gpt4 book ai didi

java - 有没有办法返回一行代码? java

转载 作者:行者123 更新时间:2023-12-02 02:13:57 24 4
gpt4 key购买 nike

我正在创建一个赌博程序。我完成了投注过程,但是我想让赌徒在投注结束后可以继续投注,但是如何重新启动代码并允许用户替换他们的投注?

代码:

import java.util.Scanner;
import java.util.Random;
public class Casino {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int min = 1;
int max = 10;
int colmax = 2;
double balance = 2500.0;
double prize = 0;
double bet1 = 0;
double bet2 = 0;
System.out.println(" -==-==-==-==-==-==-==-==-==-==-" );
System.out.println("-==-==-=={ Welcome to the Marist Casino! }==-==-==-");
System.out.println(" -==-==-==-==-==-==-==-==-==-==-" );

System.out.println("(1) Red Fox Roullete");
System.out.println("(2) Blackjack");
System.out.println("(3) Crash");
System.out.print("Enter the number for the game you'd like to play!: ");
int game = input.nextInt();

if(game == 1) {
System.out.println("---------------------------------------------");
System.out.println("Welcome to Red Fox Roullete!");
System.out.print("Please choose Black or Red....and a number from 1-10: ");
String color = input.next();
int number = input.nextInt();

System.out.print("How much would you like to bet on "+color+ "?: ");
bet1 = input.nextInt();
System.out.print("How much would you like to bet on "+number+"?: ");
bet2 = input.nextInt();
System.out.println("------------------Results--------------------");
System.out.println("You just bet "+bet1+" on "+color+" and "+bet2+" on "+number);
System.out.println("Spinning............");
Random rouletteNum = new Random();
int rNum = min + rouletteNum.nextInt(max);
int rCol = min + rouletteNum.nextInt(colmax);
if (rCol == 1) {
System.out.println("The machine landed on Black "+rNum);
}
else {
System.out.println("The machine landed on Red "+rNum);
}
if(rNum == number) {
System.out.println("Congrats, you guessed the right number!");
balance += bet2 * 5;
}
else {
System.out.println("Sorry!You didnt guess the right number! You've lost "+bet2);
balance -= bet2;
}
if(rCol == 1 && color == "black") {
System.out.print("Congrats, you guessed the right color!");
balance += bet1 * 2;
}
else {
System.out.println("Sorry!You didnt guess the right color!You've lost "+bet1);
balance -= bet1;
}
System.out.print("New balance is :"+balance);
}
}
}

总而言之,余额打印在最后一行,我想问,“你想再下一次赌注吗?”但我不确定如何得到备份允许他们执行此操作的代码。有什么想法/建议吗?

最佳答案

您可以创建一个处理投注 Activity 的方法,并在显示余额后调用该方法。

public static void bet() { 

System.out.print("How much would you like to bet on "+color+ "?: ");
bet1 = input.nextInt();
System.out.print("How much would you like to bet on "+number+"?: ");
bet2 = input.nextInt();
System.out.println("------------------Results--------------------");
System.out.println("You just bet "+bet1+" on "+color+" and "+bet2+" on
"+number);
System.out.println("Spinning............");

}

关于java - 有没有办法返回一行代码? java ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49566216/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com