我正在製作一個名爲MedGameController的全局(靜態)類的遊戲。在我的班級中,我有兩個包含15個對象的數組,每個對象都包含每個玩家單位的邏輯。在遊戲中,玩家會轉到一個表單,在表單中他們看到他們已經創建的單位,並有按鈕來創建更多單位。我不知道如何檢查當前的單位是否存在,所以我甚至不能創建單個單位。如何檢查我的單元類的實例是否存在於數組中?單位陣列必須有一個範圍,它可以包含兩種或三種形式,這就是爲什麼我在全球課程中創建它們的原因。下面是全局類:如何檢查一個對象是否存在於C#中的全局類中發現的數組中
static class MedGameController
{
static int ply1pts;
static int ply2pts;
Squad[] ply1squads = new Squad[15];
Squad[] ply2squads = new Squad[15];
public static int SetPly1Pts
{
get { return ply1pts; }
set { ply1pts = value; }
}
public static int SetPly2Pts
{
get { return ply2pts; }
set { ply2pts = value; }
}
public static int SquadSetUp
{
get { return squadcreation; }
set { squadcreation = value; }
}
public static void Player1Squads
{
This is where I think i'm supposed to check if they exist then if it doesn't then I create the instance of the squad class
}
}
}
目前還不清楚你想要做什麼。 Player1Squads應該做什麼?它會在ply1squads數組中創建15個新的小隊嗎?或者創建1 Squad並將其添加到數組?或者是什麼? –
如果你想從靜態方法訪問它們,play1squads和ply2squads必須是靜態的。 –
在四種形式之一中,玩家可以用有限的資源定製自己的小隊。 15是球隊的最大數量 – Mobianhero