/**
* Craps赌博游戏
*
*@刘顺
*/
public class Test07 {
/**
* 摇一颗色子
* @return 摇出的点数
*/
public static int roll() {
//Math数学类
return (int) (Math.random() * 6 + 1);
}
//上面是写的一个方法,下面直接导入应用
public static void main(String[] args) {
int firstPoint, currentPoint;
//roll()方法直接导入应用
firstPoint = currentPoint = roll() + roll();
System.out.println("玩家摇出了" + currentPoint + "点");
//定义一个布尔值
boolean goon = false;
//switch语句是用来检测变量与多个值相等性比较的。
switch(currentPoint) {
//每一个case值都与switch变量比较
case 7: case 11:
System.out.println("玩家胜!!!");
break;
case 2: case 3: case 12:
System.out.println("庄家胜!!!");
break;
default:
goon = true;
}
while(goon) {
currentPoint = roll() + roll();
System.out.println("玩家摇出了" + currentPoint + "点");
if(currentPoint == 7) {
System.out.println("庄家胜!!!");
goon = false;
}
else if(currentPoint == firstPoint) {
System.out.println("玩家胜!!!");
goon = false;
}
}
}
}
switch case 语句的初步运用。。
最新推荐文章于 2022-11-16 15:30:16 发布