Java Reference
In-Depth Information
int gameWinner;
char response;
//to get the user's response
//to play the game
char selection1;
char selection2;
RockPaperScissors play1;
//player1's selection
RockPaperScissors play2;
//player2's selection
//Initialize the variables; Step 2
gameCount = 0;
winCount1 = 0;
winCount2 = 0;
displayRules();
//Step 3
System.out.print("Enter Y/y to play "
+ "the game: ");
//Step 4
response = console.nextLine().charAt(0);
//Step 5
System.out.println();
while (response == 'Y' || response == 'y')
//Step 6
{
System.out.print("Player 1 enter "
+ "your choice: ");
//Step 6a
selection1 =
console.nextLine().charAt(0);
//Step 6b
System.out.println();
System.out.print("Player 2 enter "
+ "your choice: ");
//Step 6c
selection2 =
console.nextLine().charAt(0);
//Step 6d
System.out.println();
//Step 6e
if (validSelection(selection1) &&
validSelection(selection2))
{
play1 = retrievePlay(selection1);
play2 = retrievePlay(selection2);
gameCount++;
gameWinner = gameResult(play1, play2);
if (gameWinner == 1)
winCount1++;
else if (gameWinner == 2)
winCount2++;
} //end if
 
Search WWH ::




Custom Search