I am trying to create a Rock, Paper, Scissors game (where you play against a bot) using four different classes (SSPViewer, SSPController, SSPPlayer and SSPUserInput) + one main class. The game is supposed to use two different windows/JPanels. One with buttons that the user can click on and one showing the score etc.
The current problem that I have is that I cannot get the game to count score at all. Everything else about the design within the program is working as it should. I think that it has to do with some logic in the code, but I cannot seem to find the problem.
Here is some code from the Viewer and Controller-classes:
Controller:
public void game(int Humanchoice){
if (pointsBot < 3 && pointsHuman < 3){
int computer = bot.newChoice() ;
// rock = 1, paper = 2, scissors = 3;
//reglerna - poƤng utdelning
if (Humanchoice == 1 && computer == 3){
pointsHuman++;
viewer.setScore Human(pointsHum an);
}
else if (Humanchoice == 2 && computer == 3){
pointsBot++;
viewer.setScore Bot(pointsBot);
}
else if (Humanchoice == 1 && computer == 2){
pointsBot++;
viewer.setScore Bot(pointsBot);
}
else if (Humanchoice == 3 && computer == 2){
pointsHuman++;
viewer.setScore Human(pointsHum an);
}
else if (Humanchoice == 2 && computer == 1){
pointsHuman++;
viewer.setScore Human(pointsHum an);
}
else if (Humanchoice == 3 && computer == 1){
pointsBot++;
viewer.setScore Bot(pointsBot);
}
}
}
Viewer:
public void setHumanChoice( String ChoiceHuman) {
Choice.setText( ChoiceHuman);
}
public void setBotChoice(St ring ChoiceBot) {
Choice2.setText (ChoiceBot);
}
public void setScoreHuman(i nt pointsHuman) {
HumanNbr.setTex t("" + pointsHuman);
}
public void setScoreBot(int pointsBot) {
ComputerNbr.set Text("" + pointsBot);
}
}
The current problem that I have is that I cannot get the game to count score at all. Everything else about the design within the program is working as it should. I think that it has to do with some logic in the code, but I cannot seem to find the problem.
Here is some code from the Viewer and Controller-classes:
Controller:
public void game(int Humanchoice){
if (pointsBot < 3 && pointsHuman < 3){
int computer = bot.newChoice() ;
// rock = 1, paper = 2, scissors = 3;
//reglerna - poƤng utdelning
if (Humanchoice == 1 && computer == 3){
pointsHuman++;
viewer.setScore Human(pointsHum an);
}
else if (Humanchoice == 2 && computer == 3){
pointsBot++;
viewer.setScore Bot(pointsBot);
}
else if (Humanchoice == 1 && computer == 2){
pointsBot++;
viewer.setScore Bot(pointsBot);
}
else if (Humanchoice == 3 && computer == 2){
pointsHuman++;
viewer.setScore Human(pointsHum an);
}
else if (Humanchoice == 2 && computer == 1){
pointsHuman++;
viewer.setScore Human(pointsHum an);
}
else if (Humanchoice == 3 && computer == 1){
pointsBot++;
viewer.setScore Bot(pointsBot);
}
}
}
Viewer:
public void setHumanChoice( String ChoiceHuman) {
Choice.setText( ChoiceHuman);
}
public void setBotChoice(St ring ChoiceBot) {
Choice2.setText (ChoiceBot);
}
public void setScoreHuman(i nt pointsHuman) {
HumanNbr.setTex t("" + pointsHuman);
}
public void setScoreBot(int pointsBot) {
ComputerNbr.set Text("" + pointsBot);
}
}
Comment