Java “增加和减少”;“金额”;基于比赛的胜负

Java “增加和减少”;“金额”;基于比赛的胜负,java,Java,我已经做了一个掷骰子游戏,我正试图增加你的“现金”,无论你赢了,输入的赌注是什么,当你输了,把它移走 import java.util.*; import javax.swing.JOptionPane; public class Joption10 { public static void main(String[] args) { Random randomNumber = new Random(); //Variables St

我已经做了一个掷骰子游戏,我正试图增加你的“现金”,无论你赢了,输入的赌注是什么,当你输了,把它移走

import java.util.*;
import javax.swing.JOptionPane;

public class Joption10 {
    public static void main(String[] args) {

        Random randomNumber = new Random();

        //Variables
        String name, bet;
        int num1, num2;
        int cash = 100;
        int convertbet;

       

        name = JOptionPane.showInputDialog(null, "Enter Your First Name");
        JOptionPane.showMessageDialog(null, "Greetings " + name + ", welcome to roll the dice!" +"\n\nYou will start with " + cash + " euros in your wallet!" + "\n\nThe game ends when you are broke, or when you have doubled your money to 200 euros." + "\n\nGood Luck!");

        while (cash > 0 && cash < 200) {
            //Generate random numbers for player and dealer
            num1 = randomNumber.nextInt(10) + 1; //player
            num2 = randomNumber.nextInt(10) + 1; //dealer

            bet = JOptionPane.showInputDialog(null, "Place your bet (1 - 100): ");
            convertbet = Integer.parseInt(bet);
            //Rolling
            JOptionPane.showMessageDialog(null, "Rolling the dice...");
            
            if (num2 > num1) {
                JOptionPane.showMessageDialog(null, "You Win!" + "\nThe Dealer rolled a " + num1 + "\n" + name + " rolled a "  + num2);
                cash + 10
            } else if (num2 < num1) {
                JOptionPane.showMessageDialog(null, "You Lose!" + "\nThe Dealer rolled a " + num1 + "\n" + name + " rolled a " + num2);
            } else {
                JOptionPane.showMessageDialog(null, "No Winner!" + "\nThe Dealer rolled a " + num1 + "\n" + name + " rolled a " + num2);
            }

            JOptionPane.showMessageDialog(null, "You have " + cash + " euros left...");
        }

        JOptionPane.showMessageDialog(null, "You have won games!");

        System.exit(0);
    }//Close Main
}//Close Class
import java.util.*;
导入javax.swing.JOptionPane;
公共课作业10{
公共静态void main(字符串[]args){
随机数=新随机数();
//变数
字符串名称,下注;
int num1,num2;
整数现金=100;
int-convertbet;
name=JOptionPane.showInputDialog(null,“输入您的名字”);
JOptionPane.showMessageDialog(空,“问候”+name+“,欢迎掷骰子!”+“\n\n您将从钱包中的“+cash+”欧元开始”+“\n\n当您破产或您的钱翻倍至200欧元时,游戏结束。”+“\n\n祝您好运!”;
而(现金>0&&现金<200){
//为玩家和庄家生成随机数
num1=randomNumber.nextInt(10)+1;//播放器
num2=randomNumber.nextInt(10)+1;//经销商
bet=JOptionPane.showInputDialog(null,“下注(1-100):”);
convertbet=Integer.parseInt(bet);
//滚动
showMessageDialog(null,“掷骰子…”);
如果(num2>num1){
JOptionPane.showMessageDialog(null,“您赢了!”+“\n经销商掷了一个“+num1+”\n“+name+”掷了一个“+num2”);
现金+10
}否则如果(num2
如果我理解的话,你应该在赢的时候加上赌注金额,在你输给现金的时候减去

if (num2 > num1) {
    JOptionPane.showMessageDialog(null, "You Win!" + "\nThe Dealer rolled a " + num1 + "\n" + name + " rolled a "  + num2);
    cash += convertbet
} else if (num2 < num1) {
    JOptionPane.showMessageDialog(null, "You Lose!" + "\nThe Dealer rolled a " + num1 + "\n" + name + " rolled a " + num2);
    cash -= convertbet
} else {
    JOptionPane.showMessageDialog(null, "No Winner!" + "\nThe Dealer rolled a " + num1 + "\n" + name + " rolled a " + num2);
}
if(num2>num1){
JOptionPane.showMessageDialog(null,“您赢了!”+“\n经销商掷了一个“+num1+”\n“+name+”掷了一个“+num2”);
现金+=押注
}否则如果(num2

请注意,在现金中添加10,但不指定返回值的地方。您可以使用
+=
运算符添加变量并将其赋值。

感谢您的快速回复!如果你赢了,它应该将输入的赌注金额添加到你预定的现金金额中,反之亦然,如果你输了。例如,如果我下注10,当我赢了,它应该输出我还有110欧元。我还收到一些语法错误与您编辑的代码,我不知道为什么。