I need help with incrementing my score. I tried ++wins..., wins++..., wins += 1..., wins = wins + 1... and so far nothing works. I just keep getting 0.
My main class:
import java.util.Scanner;
public class Test
{
public static void main (String [] args)
{
Rock game = new Rock();
int totalGame = game.getTotalGames();
int wins = game.getWins();
int losses = game.getLosses();
int draws = game.getDraws();
System.out.println("Enter move 1)rock 2)paper 3)scissors");
Scanner user = new Scanner (System.in);
int userMove = user.nextInt();
game.play(userMove);
String compMove;
compMove = game.getComputerMoveAsString();
System.out.print("Computer's move: " + compMove);
System.out.println();
String gameOutcome;
gameOutcome = game.getOutcomeAsString();
System.out.println(gameOutcome);
System.out.println("total " + totalGame);
System.out.println("wins " + wins);
System.out.println("losses " + losses);
System.out.println("draws " + draws);
}
}
My rock class:
import java.util.Scanner;
public class Test
{
public static void main (String [] args)
{
Rock game = new Rock();
int totalGame = game.getTotalGames();
int wins = game.getWins();
int losses = game.getLosses();
int draws = game.getDraws();
System.out.println("Enter move 1)rock 2)paper 3)scissors");
Scanner user = new Scanner (System.in);
int userMove = user.nextInt();
game.play(userMove);
String compMove;
compMove = game.getComputerMoveAsString();
System.out.print("Computer's move: " + compMove);
System.out.println();
String gameOutcome;
gameOutcome = game.getOutcomeAsString();
System.out.println(gameOutcome);
System.out.println("total " + totalGame);
System.out.println("wins " + wins);
System.out.println("losses " + losses);
System.out.println("draws " + draws);
}
}
class Rock
{
public static final int ROCK = 1;
public static final int PAPER = 2;
public static final int SCISSORS = 3;
public static final int WIN = 1;
public static final int LOSE = 2;
public static final int DRAW = 3;
public static final int NO_MOVE = 0;
private int playerMove;
private int computerMove;
private int outcome;
private int wins;
private int losses;
private int draws;
public RockPaperScissors12()
{
playerMove = 0;
computerMove = 0;
wins = 0;
losses = 0;
draws = 0;
}
public boolean play(int playerMove)
{
double random;
double computerRandom;
int computerMove;
random = Math.random();
computerRandom = random * 3;
this.computerMove = (int)computerRandom + 1;
if (playerMove == 1)
{
this.playerMove = ROCK;
switch (this.computerMove)
{
case 1:
outcome = DRAW;
draws++;
break;
case 2:
outcome = LOSE;
losses++;
break;
case 3:
outcome = WIN;
wins++;
break;
}
return true;
}
else if (playerMove == 2)
{
this.playerMove = PAPER;
switch (this.computerMove)
{
case 1:
outcome = WIN;
++wins;
break;
case 2:
outcome = DRAW;
++draws;
break;
case 3:
outcome = LOSE;
++losses;
break;
}
return true;
}
else if (playerMove == 3)
{
this.playerMove = SCISSORS;
switch (this.computerMove)
{
case 1:
outcome = LOSE;
++losses;
break;
case 2:
outcome = WIN;
++wins;
break;
case 3:
outcome = DRAW;
++draws;
break;
}
return true;
}
else
{
return false;
}
}
public int getComputerMove()
{
if (playerMove == 1 || playerMove == 2 || playerMove == 3)
{
return this.computerMove;
}
else
{
return NO_MOVE;
}
}
public String getComputerMoveAsString()
{
if (this.computerMove == 1)
{
return("rock");
}
else if (this.computerMove == 2)
{
return("paper");
}
else
{
return("scissors");
}
}
public int getOutcome()
{
if (playerMove == 1 || playerMove == 2 || playerMove == 3)
{
return outcome;
}
else
{
return NO_MOVE;
}
}
public String getOutcomeAsString()
{
if (outcome == 1)
{
return("You Won!");
}
else if (outcome == 2)
{
return("The computer wins.");
}
else
{
return("The game was a tie.");
}
}
public int getWins()
{
return wins;
}
public int getLosses()
{
return losses;
}
public int getDraws()
{
return draws;
}
public int getTotalGames()
{
return wins + losses + draws;
}
}