所以,我在我的编程项目上有点挣扎。
我有一个存储玩家信息、姓名、胜利、失败的对象。
我继续在另一个对象(括号)中使用该对象,该对象设置播放器信息的值,在每个循环之后,它将播放器对象复制到括号类中的 NSMutable。
在括号类中,我有一个打印信息的方法,这很容易弄清楚。
现在,为了生成下一个括号会发生什么,我设置了一个方法,当它完成复制谁输赢时将返回一个括号。
我已经在同一个括号方法中完成了所有这些操作,因此我可以尽可能轻松地访问数据。我如何简单地复制播放器对象并将其添加到新括号中?
当我尝试打印刚刚生成的括号时,我发现我只是得到垃圾值或什么都没有。这是我遇到问题的功能。
-(Bracket *) NextRound//Configures the next round
{
int i, y, *selection; //counter and selection
int comp;
y = 1;
i = 0;//so the counter won't get messed up
Bracket *roundx = [Bracket new]; //creates the bracket that will be sent back with the winners.
NSLog(@"Did %@(1) or %@(2) win (1 or 2)?: ",[[playerarray objectAtIndex:i] name], [[playerarray objectAtIndex:y] name]);
scanf("%d",&selection);
comp = selection++;
if (comp == 1)
{
NSLog(@"Player %d %@ selected to win", i, [[playerarray objectAtIndex:i] name]);
[[self.playerarray objectAtIndex:i] setNext];//bool value for win or not
[roundx.playerarray addObject: [self.playerarray objectAtIndex:i]];
[roundx Print];//Too see if it has anything, usually it does not.
}
else
{
i++;
NSLog(@"Player %d %@ selected to win", i, [[playerarray objectAtIndex:i] name]);
[[self.playerarray objectAtIndex:i] setNext];
[roundx.playerarray addObject: [self.playerarray objectAtIndex:i]];
[roundx Print];
}
return(roundx);
}
所以,我认为这会奏效。它编译得很好(我收到了一些警告,但它是关于整数的,所以我主要用于逻辑)。
谢谢你!