每个玩家掷两个骰子 他们比较每卷的最高数字。数字较大的玩家可获得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();
}
}
}
我看到这样的情况:
相关问题 更多 >
编程相关推荐