I working on a program to simulate (roughly) a Meier dice game (linked game information. I am struggling adding a second player to be rolled and have different numbers than my first player, I would think this would be done with a loop, but in this course, we haven't learned about loops yet. I am anxious on how this can be done then, since we were instructed to only use if-statements.
I'd appreciate any help on this,
Thank you!
My code:
public class Meier {
public static void main(String[] args) {
int die1=(int)(Math.random()*6+1);
int die2=(int)(Math.random()*6+1);
int rank1 = 0; // For player 1
int rank2 = 0; // For player 2
int temp = 0; // Allows for variable switching
if (die1 > die2) {
rank1 = Integer.valueOf(String.valueOf(die1) + String.valueOf(die2));
System.out.println("Player one's two die values are: " + die1 + " and " + die2);
System.out.println("Player one's rank is: " + rank1); }
else if (die1 < die2) {
temp = die1;
die1 = die2;
die2 = temp;
rank1 = Integer.valueOf(String.valueOf(die1) + String.valueOf(die2));
System.out.println("Player one's two die values are: " + die1 + " and " + die2);
System.out.println("Player one's rank is: " + rank1); }
else if (die1 == die2) {
rank1 = Integer.valueOf(String.valueOf(die1) + String.valueOf(die2));
System.out.println("Player one's two die values are: " + die1 + " and " + die2);
System.out.println("Player one's rank is: " + rank1); }
return;
}
}
My output:
Player one's two die values are: 6 and 1
Player one's rank is: 61
Aucun commentaire:
Enregistrer un commentaire