保龄球计分程序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;

}

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值