【发布时间】:2014-02-12 11:05:03
【问题描述】:
我对 Objective-c 编程很陌生,但构建自己的掷骰子游戏帮助我理解了它的基础知识。我知道这里有很多关于掷骰子游戏的主题,但没有找到我想要的。 我用 8 个不同的骰子(都在单独的图像视图中)创建了一个游戏,这些骰子使用从 1 到 6 的随机生成的数字。玩家可以一键掷出所有骰子,并且标签会随总点数更新在每一卷。但是,为了提高分数,我想让玩家在掷骰后保留某个骰子(通过点击单个骰子)并继续使用其他骰子。 我已经实现了一个日志,显示是否点击了某个骰子,如下所示:
- (void)viewDidLoad {
UITapGestureRecognizer *recogDice = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapRecognized:)];
[self.firstDieView addGestureRecognizer:recogDice];
}
-(void)tapRecognized:(UITapGestureRecognizer *)sender {
NSLog(@"Nr 1 touched");
}
当然,这确实向我展示了骰子已被点击,但我不知道如何从这里编写代码,以便在其他骰子再次滚动时实际上不会滚动。 我的滚动代码如下:
-(void)throw {
DiceThrowController *diceController = [[DiceThrowController alloc] init];
int firstNumber = [diceController getDieNumber]; //for this example i've cut out the other dice, which are the same as this one, only called 'second' etc.
[self.firstDieView showDieNumber:firstNumber];
self.sumLabel.text = [NSString stringWithFormat:@"%d", firstNumber];
}
任何人都可以在这里指出正确的方向吗?我的游戏运行良好,但我想为其添加一些实际的交互/目标。谢谢
【问题讨论】:
-
每个 dice-view 都有自己的 diceThrowController 实例吗?
标签: objective-c cocoa-touch dice