So for my class we have to create a GUI for this class that just displays 3 buttons to choose from (rock, paper, or scissors) and then it has to display who wins ( Player win: Player's choice (ROCK) beats Computer's choice (SCISSORS)) and also displays PLAYER: 1; COMPUTER: 0; (Which is the score of the games)
Please help!
Thanks
package homework08;
import java.util.Random;
public class RockPaperScissors
{
// The enumerated type with the gestures a person can use -- either rock,
// paper, or scissors.
public enum Gesture { ROCK, PAPER, SCISSORS }
// Instance variables we'll use to track the score of the game.
private int computerScore, playerScore;
public String playGame( Gesture playerChoice )
{
// Randomly select a gesture. Rock, paper, or scissors is selected
// uniformly at (pseudo-)random.
Gesture computerChoice =
Gesture.values( )[(new Random( )).nextInt( 3 ) ];
// The string we'll use to represent the result and new score.
String result;
// Find out the result -- was it a tie?
if( playerChoice == computerChoice )
{
result = "Draw: Player and Computer select " + playerChoice;
}
// If it wasn't a tie, one of the players must have won. Instead of
// analyzing each case, we can note the "circular" way the winner is
// determined -- position i+1 % 3 beats position i.
else if( (playerChoice.ordinal() + 1) % 3 == computerChoice.ordinal() )
{
computerScore++;
result = "Computer Win: Computer's choice (" + computerChoice
+ ") beats " + "Player's choice (" + playerChoice + ")";
}
// If neither case above is true, it must be that the player won.
else
{
playerScore++;
result = "Player Win: Player's choice (" + playerChoice + ") "
+ "beats Computer's " + "choice (" + computerChoice + ")";
}
// Add the score to the String and return it. Note we tell Java that
// our answer is in HTML by using <HTML>. The <BR> is an HTML command
// asking it to break the line, moving on to the next line.
// HINT: a JLabel will make a new line for this ...
result = "<HTML><CENTER>" + result + "<BR>PLAYER: " + playerScore
+ "; COMPUTER: " + computerScore + "</CENTER></HTML>";
return result;
}
}