摇骰子游戏

package com.day05;

import java.util.Scanner;

public class Zuoye1 {
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
System.out.println("********澳门赌场欢迎您********");//
System.out.println("********欢迎进入摇骰子猜大小游戏********");
System.out.println("请输入你兑换的本金");
int money = sc.nextInt();//定义本金

//开始循环
while(true) {
//摇骰子(控制随机数在1-6,和为3-18)
int a = (int)(Math.random()*6+1);
int b = (int)(Math.random()*6+1);
int c = (int)(Math.random()*6+1);
//求和
int sum = a+b+c;
//判断骰子大小
String result = sum<10?"小":"大";


System.out.println("请猜骰子的大小:");
String guess = sc.next();

System.out.println("请输入本轮所押金额:");
int pay = sc.nextInt();
System.out.println(a+"\t"+b+"\t"+c);
System.out.println("本轮游戏结果为"+result);
//计算剩余金额
switch (result) {
case "小":
money = guess.equals(result) ?(money + pay) : (money - pay);

break;
case"大":
money = guess.equals(result) ?(money + pay) : (money - pay);

break;

}
System.out.println("你当前余额为:"+money);

//判断循环结果
if(money<=0) {
System.out.println("余额不足,游戏结束");
break;
}else{
System.out.println("是否继续游戏?(是/否)");
String again = sc.next();
if("否".equals(again)) {
System.out.println("您拒绝了继续游戏");
break;
}
}
}

System.out.println("游戏结束!");
}

猜你喜欢

转载自www.cnblogs.com/hxtzzz/p/11099851.html