今天给大家分享一下我的赌博游戏:
package com.itheima;
import java.util.Random;
import java.util.Scanner;
public class RandomDemo {
public static void main(String[] args) {
int monery=100;
Random r=new Random();
Scanner s=new Scanner(System.in);
while(true){
System.out.println("请输入你要压的金额");
int x=s.nextInt();
if (x>monery||x<0) {
System.out.println("你输入的金额超出你的账户金额请重新输入:");
continue;
}
monery-=x;
System.out.println("请输入你是压大-1,还是小-0");
int y=s.nextInt();
if (y!=0&&y!=1) {
System.out.println("你压的数字只能是0或者1,请重新输入:");
monery+=x;
continue;
}
int r1=r.nextInt(2);
if (r1==1) {
System.out.println("大");
}else{
System.out.println("小");
}
if (y==r1) {
System.out.println("恭喜你压中了");
monery=monery+x*2;
System.out.println("你的当前金额为:"+monery);
} else {
if(monery<=0){
System.out.println("充钱去");
break;
}
System.out.println("你的当前金额为:"+monery);
System.out.println("继续猜下去");
}
}
|
|