I must set up a Player vs Computer Dice Game, consisting of 3 dice to each, which upon roll will determine which "player" has won the round. There are several determination factors (rules) with which I'm struggling to efficiently input.
- A Triple is when all the dice have the same number, the value of the Triple is their common value. (This I know is ((d1 == d2) && (d1 == d3))
- A Pair is when two of the dice have the same number, the value of the pair is the common value. (Similar to triple but with || I believe)
- Junk is anything that is not a Triple or Pair.
- Any Triple beats any Pair.
- Any Triple beats any Junk.
- Two Triples are compared by their respective values.
- Any Pair beats and Junk.
- Two Pairs are first compared by their respective pair values, and then by their respective non-common die values.
If it was a couple determinations I wouldn't have a problem with it but I'm kinda lost due to the fact that we need all these conditions to check each roll-loop and I was told to only use the main class.
I believe I've correctly set up the entire program ASIDE FROM DETERMINATION and can get values each roll, counters working and such. The issue lies in inputing the determination rules into the game. Everything else I feel confident in working through.
This is my DO-WHILE loop for the roll and determination area. As you can see I'm struggling with how to manage and input the determinations. I get the basic idea that it is a 3! situation resulting in 6 combinations but I don't understand how to compare Player and Computer values properly. In class I was given a tip... - math library - int d1, d2, d3;
- int big = Math.max(Math.max(d1,d2),d3)
- int small = Math.min(Math.min(d1,d2),d3)
- int medium = (d1 + d2 + d3) - (b + s)
This is to check values on the dice. I understand how this works but I've lost the plot as to how this will work with a Player and Computer both having 3 dice and using these integer variables with Determination rules.
do
{
System.out.println();
System.out.println("Do you wish to play again? [y, n]");
answer = stdIn.next();
if (answer.equalsIgnoreCase("y"))
{
turnCounter++;
System.out.println("Player");
System.out.println("------");
int d1 = (int)(Math.random() * 6) + 1;
int d2 = (int)(Math.random() * 6) + 1;
int d3 = (int)(Math.random() * 6) + 1;
System.out.println("Roll: " + "\t" + d1 + "\t" + d2 + "\t" + d3 + "\n");
System.out.println("Computer");
System.out.println("--------");
int d4 = (int)(Math.random() * 6) + 1;
int d5 = (int)(Math.random() * 6) + 1;
int d6 = (int)(Math.random() * 6) + 1;
System.out.println("Roll: " + "\t" + d4 + "\t" + d5 + "\t" + d6);
if ((d1 == d2) && (d1 == d3) &&
(d4 == d5) && (d4 == d6)) //Triple (Player & Computer) Tie
roundTied++;
System.out.println("You tied the round with the Computer!");
if ((d1 == d2) || (d2 == d3) || (d1 == d3) &&
(d4 == d5) || (d4 == d6) || d5 == d6) //Pair (Player & Computer) Tie
roundTied++;
System.out.println("You tied the round with the Computer!");
if ()
if (userWin > compWin) winner = Player;}
if (compWin > userWin) winner = Computer;
}while(answer.equalsIgnoreCase("y"));
System.out.println("\n" + "Game Results");
System.out.println("------------");
System.out.println("Rounds Played: " + turnCounter);
System.out.println("User Wins: " + userWin + "\t" + " User Losses: " + userLoss);
System.out.println("Computer Wins: " + compWin + "\t" + "Computer Losses: " + compLoss);
System.out.println("Rounds Tied: " + roundTied);
System.out.println("------------");
System.out.println("The " + winner + " has won the game!");
stdIn.close();
Aucun commentaire:
Enregistrer un commentaire