게임을 만들고 있는데, 메뉴 VC에서 버튼을 누르면 게임 VC가 열리 며 viewDidLoad
에는 게임을 설정하는 방법이 있습니다 (에고, Game
수업); 카드 덱을 만들고, 플레이어를 만들고, 플레이어에게 카드를 추가하는 등의 작업을 할 수 있습니다. 이제는 게임을 취소/종료 할 수 있기를 바랄뿐입니다. 분명히 버튼이 있습니다. 해당 버튼을 누르면 메뉴 VC가 다시 표시되지만 Game
클래스는 여전히 존재합니다. 내 기록에서 볼 수 있듯이 Ai 선수는 여전히 놀고 있습니다.뷰 컨트롤러 나가기, 게임 종료
내 질문은 내가 게임을 취소하고 Game
클래스를 "할당 해제"하고 플레이어 배열을 지우고 카드 덱 등을 지울 수있는 방법입니다. 내가 아는 한 내가 오브젝트를 "할당 해제"할 수 없습니다. ARC에서는 허용되지 않습니다.
나는보기를 변경하는 방법을 알고 있지만 게임을 종료하는 방법 만 필요합니다.
Game
클래스에 대한 추가 정보입니다.
@implementation Game
{
int _activePlayerPosition;
NSArray *activePlayersArray;
//Player *activePlayer;
}
+(Game *) game {
static Game *game = nil;
if(game == nil) {
game = [[super allocWithZone:nil] init];
}
return game;
}
-(id) init {
if((self = [super init])){
}
return self;
}
-(void) setupGame {
NSLog(@"setup game");
_deckCard = [[DeckCard alloc]init];
_tableCard = [[TableCard alloc]init];
_players = [NSMutableDictionary dictionaryWithCapacity:4];
_deckCards = _deckCard.cardsInDeck;
_tableCards = _tableCard.cardsOnTable;
//If game is single player, start single player game.
if([Game game].isSinglePlayerGame) {
[self startSinglePlayerGame];
}
_activePlayerId = 0;
//Check playabality of all playercards in Game.
NSArray *playersArray = [[[Game game] players] allKeys];
for(int x = 0; x <[playersArray count];x++){
id key = [playersArray objectAtIndex:x];
id player = [[[Game game] players] objectForKey:key];
[player isPlayerAllowedToPlay];
}
}
그래서 Game
클래스의 인스턴스가 생성 된 모든 다른 객체 (배열, 플레이어 등)과 함께 gameViewController에 사용됩니다.
그래서 게임을 어떻게 끝내나요?
감사합니다.
Game 클래스를 nil로 설정하려고 시도 했습니까? – matsoftware
Game 객체를 어떻게 저장하는지 알 필요가 있습니다. 귀하의 질문에 중요한 정보가 누락되었습니다. – CrimsonChris
@CrimsonChris 공정한만큼, 나는 나의 질문을 편집했다. 당신의 도움을 주셔서 감사합니다! – Niels