我很新的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];
}
任何人都可以點我在這裏向正確的方向?我的遊戲完美運行,但我想添加一些實際的交互/目標。謝謝
每個骰子視圖是否都有自己的diceThrowController實例? –