MedGameController라는 전역 (정적) 클래스가있는 게임을 만들고 있습니다. 내 클래스에는 각 플레이어 유닛에 대한 논리를 보유하는 15 개의 객체로 이루어진 두 개의 배열이 있습니다. 게임에서 플레이어는 이미 만든 유닛을보고 더 많은 유닛을 만드는 버튼이있는 양식으로 이동합니다. 현재 단위가 존재하는지 확인하는 방법을 모르겠으므로 단일 단위를 작성할 수도 없습니다. 유닛 클래스의 인스턴스가 배열에 존재하는지 어떻게 확인합니까? 단위 배열은 2 개의 어쩌면 3 개의 형식을 포함하는 스코프를 가져야 만합니다. 그래서 전역 클래스에서 생성했습니다. 여기에 글로벌 클래스입니다 :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 스쿼드를 만들어 배열에 추가하십시오. 또는 무엇을? –
play1squads 및 ply2squads는 정적 메서드에서 액세스하려는 경우 정적이어야합니다. –
네 가지 형태 중 하나에서 플레이어는 제한된 자원으로 자신의 팀을 커스터마이징 할 수 있습니다. 15 분의 숫자입니다 – Mobianhero