每个玩家掷两个骰子,然后比较每个骰子上的最高数字。人数多的选手得2分。他们比较每卷的最低数字。人数多的选手得1分。如果数字是平局,则不得分。第一个得到20分的玩家获胜。我怎么做比较部分?这是我目前掌握的密码
import java.util.Scanner;
import java.util.Random;
public class DiceGame
{
public static void main(String[] args) // method 1
{
String again = "y"; // To control the loop
int die1; // To hold the value of die #1
int die2; // to hold the value of die #2
int die3;
int die4;
// Create a Scanner object to read keyboard input.
Scanner keyboard = new Scanner(System.in);
// Create a Random object to generate random numbers.
Random rand = new Random();
// Simulate rolling the dice.
while (again.equalsIgnoreCase("y"))
{
System.out.println("Rolling the dice...");
die1 = rand.nextInt(6) + 1;
die2 = rand.nextInt(6) + 1;
System.out.println("Player 1's values are:");
System.out.println(die1 + " " + die2);
die3 = rand.nextInt(6) + 1;
die4 = rand.nextInt(6) + 1;
System.out.println("Player 2's values are:");
System.out.println(die3 + " " + die4);
//method 2 = comparing the numbers
public static void compareRoll(int die1, die2, die3, die4)
{
{
if(die1 > die2 && die3 > die4)
else if(die1 < die2 && die3 < die4)
else
}
}
//method 3 = getting total number of scores
System.out.print("Roll them again (y = yes)? ");
again = keyboard.nextLine();
}
}
}
1条答案
按热度按时间hwazgwia1#
我看到这样的东西: