我正在为 iPhone 开发我的第一个游戏应用程序,但在 Objective-c 中我还是有点小白。
游戏进展顺利,但我遇到了一个小问题......
我想让它每 20 次击杀,你就获得 +1 生命,我知道如何做到这一点,但是代码写得不好,比如这样......:
switch (kills) {
case 20:
lives++;
livescount.text = [NSString stringWithFormat:@"%i", lives];
break;
case 40:
lives++;
livescount.text = [NSString stringWithFormat:@"%i", lives];
break;
case 60:
lives++;
livescount.text = [NSString stringWithFormat:@"%i", lives];
break;
case 80:
lives++;
livescount.text = [NSString stringWithFormat:@"%i", lives];
break;
case 100:
lives++;
livescount.text = [NSString stringWithFormat:@"%i", lives];
break;
case 120:
lives++;
livescount.text = [NSString stringWithFormat:@"%i", lives];
break;
case 140:
lives++;
livescount.text = [NSString stringWithFormat:@"%i", lives];
break;
case 160:
lives++;
livescount.text = [NSString stringWithFormat:@"%i", lives];
break;
case 180:
lives++;
livescount.text = [NSString stringWithFormat:@"%i", lives];
break;
case 200:
lives++;
livescount.text = [NSString stringWithFormat:@"%i", lives];
等等....我不想一直写到无穷大哈哈
我知道这是编写代码的不正确方式。谁能给我每 20 次击杀 = +1 生命的正确代码。我可能也会发现并理解代码是如何工作的。