保龄球计分程序java_保龄球计分——java代码实现

/**

* 计算一局得分、当前轮次

*

* @author Administrator

*

*/

public class Bowling {

int index = 0;

static int[] score = new int[24];

static {

for (int i = 0; i < score.length; i++) {

score[i] = -2;

}

}

// 保存分数

public int[] saveScore(int goalScore) {

score[index] = goalScore;

++index;

if (10 == goalScore) {

score[index] = -1;

++index;

}

return score;

}

// 计算当前轮次

public int roundTime() {

int round = 0;

for (int i = 0; i < score.length; i++) {

if (0 == i % 2 && -2 == score[i]) {

round = i / 2;

break;

} else if (0 != i % 2 && -2 == score[i]) {

round = i / 2 + 1;

break;

}

}

round = round <= 10 ? round : 10;

System.out.println("当前一共进行" + round + "轮");

return round;

}

// 计算当前的总分

public int getRoundScore() {

int roundScore = 0;

int rounds = roundTime();

for (int i = 1; i <= rounds; i++) {

roundScore += getEachRoundScore(i);

}

System.out.println("总分是" + roundScore);

return roundScore;

}

// 计算每轮得分

public int getEachRoundScore(int round) {

int eachRoundScore = 0;

int roundIndex = 2 * (round - 1);

if (10 == score[roundIndex]) {

eachRoundScore = score[roundIndex]

+ (-2 != score[roundIndex += 2] ? score[roundIndex] : 0);

if (10 == score[roundIndex]) {

eachRoundScore += (-2 != score[roundIndex += 2] ? score[roundIndex]

: 0);

} else {

eachRoundScore += (-2 != score[++roundIndex] ? score[roundIndex]

: 0);

}

} else {

eachRoundScore = score[roundIndex]

+ (-2 != score[++roundIndex] ? score[roundIndex] : 0);

if (10 == eachRoundScore) {

eachRoundScore += (-2 != score[++roundIndex] ? score[roundIndex]

: 0);

}

}

System.out.println("第" + round + "轮得分是" + eachRoundScore);

return eachRoundScore;

}

} 最近在捯饬保龄球计分代码,实现好复杂的说,光是规则就理解了半天。

  • 1
    点赞
  • 0
    收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
©️2022 CSDN 皮肤主题:数字20 设计师:CSDN官方博客 返回首页
评论

打赏作者

crazyboy92

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值