package com.lovo;
import java.util.Scanner;
public class Test03 {
/**
* 摇一个骰子
* @return
*/
public static int roll(){
return (int) (Math.random()*6+1);
}
public static void main(String[] args) {
int firstPoint,currentPoint;
Scanner sc = new Scanner(System.in);
int total=10000;
for(;total>0;){
firstPoint = currentPoint = roll()+roll();
System.out.printf("玩家总资金:%d\n",total);
System.out.println("<---请下注--->");
int m = sc.nextInt();
if(m<=total){
boolean goon = false;
switch(currentPoint){
case 7:
case 11:
System.out.printf("玩家%d点,玩家胜!!\n",currentPoint);
System.out.printf("余额:%d\n",total+=m);
break;
case 2:
case 3:
case 12:
System.out.printf("玩家%d点,庄家胜!!\n",currentPoint);
System.out.printf("余额:%d\n",total-=m);
break;
default:
System.out.printf("玩家掷出%d点\n",currentPoint);
goon = true;
}
while(goon){
currentPoint = roll()+roll();
System.out.printf("玩家掷出%d点\n",currentPoint);
if(currentPoint == 7){
System.out.print("庄家胜!");
System.out.printf("余额:%d\n",total-=m);
goon = false;
}else if(currentPoint==firstPoint){
System.out.print("玩家胜!");
System.out.printf("余额:%d\n",total+=m);
goon = false;
}
}
if(total <=0){
System.out.printf("余额不足!!\nGAME OVER!");
break;
}
}else{
System.out.println("余额不足!!");
continue;
}
}
sc.close();
}
}
java 10.18.2
最新推荐文章于 2024-07-01 07:45:00 发布