Problem with a rock, paper, scissors game

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lollollol1234
    New Member
    • Jan 2019
    • 1

    Problem with a rock, paper, scissors game

    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);
    }
    }
  • chaarmann
    Recognized Expert Contributor
    • Nov 2007
    • 785

    #2
    Please use code tags to make it easier for us free helpers to read your code.

    You have two variables "pointsHuma n" and "pointsBot" , but you have not listed the code where they are defined and where they are printed out. Maybe you count up, but at the end you reset them to 0 by accident?

    So the first thing you should do is to add two methods
    Code:
    increaseHumanPoints() {
       pointsHuman++;
       System.out.println("Human points after increase:" + pointsHuman);
    }
    resetHumanPoints() {
       pointsHuman= 0;
       System.out.println("Human points were resetted!");
    }
    Then replace every occurence of "pointsHuma n" with these methods everywhere. You should not have a single occurrence of humanPoints anywhere in your code except in these two methods.
    Then let your program run and post the result here.
    If everything is OK, then do it similar with "pointsBot" and post the results here.

    Comment

    Working...