我正在制作一款棋盘游戏,当一个人获胜时,我希望棋盘自行重置。如果有帮助,我正在为 iPhone 使用 cocos2d。我有一个重置方法,可以重置所有变量和数组。它会重置一次,然后在一个人获胜后的下一次它不会重置董事会。有想法该怎么解决这个吗?这是 .m 文件中的方法。//方法
-(void) resetGame {
self.isTouchEnabled = YES;
if( (self=[super init]) ) {
self.isTouchEnabled = YES;
turn = 2;
pieces = [[NSMutableArray alloc] initWithObjects:
[[Piece alloc] pieceWithType:1 player:1 row:1 col:3], // bSphere1
[[Piece alloc] pieceWithType:1 player:1 row:2 col:3], // bSphere2
[[Piece alloc] pieceWithType:2 player:1 row:1 col:2], // bSquare1
[[Piece alloc] pieceWithType:2 player:1 row:3 col:3], // bSquare2
[[Piece alloc] pieceWithType:2 player:1 row:0 col:3], // bSquare3
[[Piece alloc] pieceWithType:1 player:2 row:0 col:4], // wSphere1
[[Piece alloc] pieceWithType:1 player:2 row:2 col:4], // wSphere2
[[Piece alloc] pieceWithType:2 player:2 row:1 col:4], // wSquare1
[[Piece alloc] pieceWithType:2 player:2 row:3 col:4], // wSquare2
[[Piece alloc] pieceWithType:2 player:2 row:2 col:5], // wSquare3
nil];
// add background before pieces
CCSprite *bg = [CCSprite spriteWithFile:@"grid.png"];
[bg setPosition:ccp(240, 160)];
[self addChild:bg z:0];
// add all the pieces
for(Piece *piece in pieces) {
[self addChild:piece];
}
}
}