473,386 Members | 1,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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.setScoreHuman(pointsHuman);
}
else if (Humanchoice == 2 && computer == 3){
pointsBot++;
viewer.setScoreBot(pointsBot);
}
else if (Humanchoice == 1 && computer == 2){
pointsBot++;
viewer.setScoreBot(pointsBot);
}
else if (Humanchoice == 3 && computer == 2){
pointsHuman++;
viewer.setScoreHuman(pointsHuman);
}
else if (Humanchoice == 2 && computer == 1){
pointsHuman++;
viewer.setScoreHuman(pointsHuman);
}
else if (Humanchoice == 3 && computer == 1){
pointsBot++;
viewer.setScoreBot(pointsBot);
}
}
}


Viewer:

public void setHumanChoice(String ChoiceHuman) {
Choice.setText(ChoiceHuman);
}

public void setBotChoice(String ChoiceBot) {
Choice2.setText(ChoiceBot);
}

public void setScoreHuman(int pointsHuman) {
HumanNbr.setText("" + pointsHuman);
}

public void setScoreBot(int pointsBot) {
ComputerNbr.setText("" + pointsBot);
}
}
Jan 6 '19 #1
1 1842
chaarmann
785 Expert 512MB
Please use code tags to make it easier for us free helpers to read your code.

You have two variables "pointsHuman" 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
Expand|Select|Wrap|Line Numbers
  1. increaseHumanPoints() {
  2.    pointsHuman++;
  3.    System.out.println("Human points after increase:" + pointsHuman);
  4. }
  5. resetHumanPoints() {
  6.    pointsHuman= 0;
  7.    System.out.println("Human points were resetted!");
  8. }
  9.  
Then replace every occurence of "pointsHuman" 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.
Apr 5 '19 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: TooNaive | last post by:
Hello all, I'm taking a C class and am having to write a program to play a game of rock, paper scissors, and with the output of: You chose paper and I chose rock. You Win where paper is the...
7
by: Sharon Tal | last post by:
Hi to all. I'm developing a web multi player game. The game will run on the server, and the clients will just show it. All the clients will have few events, by which they can change the game...
9
by: Sukh | last post by:
Hello anyone, I am printing a pre-printed continue paper on dot-matrix printer using vb.net winform. For printing I am creating custom size paper and selecting the same for printing. Everything...
3
by: continium | last post by:
I am learning how to program and I only started about a month ago so the answer to this is probably quite obvious. I'm running accross a problem when writing a rock, paper, scissor program....
1
by: flg22 | last post by:
Hi I am working on this Rock, paper, scissors java game and the program works, but I can not figure out how to get the images to load onto the program. So my question is how do I get the images to...
8
by: jmf777 | last post by:
Hi here is my problem I want to have the outcome of my rock paper scissors game to print outcomes like: You chose paper and I chose rock. You win. The value for player_choice and machine_choice is...
2
by: Izkimar | last post by:
I'm supposed to redesign this paper scissors rock game that first happened between 2 players, and for only one round. Yet, now I'm supposed to take for loops and ask them if they want to play...
5
by: ramosariel | last post by:
this is for our project, and i'm still a beginner in programming, so guys I need some help. I want to create a random rock paper scissors game(player vs computer)... I tried many times to...
10
by: as1000 | last post by:
Hi, the prompt doesn't work. Any suggestions? If you could spell it out for me it would be helpful. I have only been doing this for less than a week Thanks! <!DOCTYPE html> <html> <head> ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.