• Post Reply Bookmark Topic Watch Topic
  • New Topic

Can someone please be bothered to try this, thanks Rock paper scissors  RSS feed

 
Ross Born
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
'paper, scissors, rock' with a user. A game consists of a user-defined number of rounds.
A single round of the game works as follows:
The user and the program each choose a number: 0 (for 'paper'), 1 (for 'scissors') or 2 (for 'rock'). The program uses a random number generator to make its choice. The result of the round is as follows:
Enter 0, 1 or 2 for paper, scissors, rock
1
My choice was 2
Rock blunts scissors: I win
Your Game class should contain:
a public integer instance variable called numRounds, that records how many
rounds of the game have been played.
a public integer instance variable called roundsWon, that records how many
rounds of the game have been won by the human player.
a public void method called playGame(), which plays the game
Method playGame() should ask the user how many rounds to play, and then play that many rounds of the game. Variables numRounds and roundsWon should be correctly updated by the method.

 
Knute Snortum
Sheriff
Posts: 4276
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch, Ross.

It looks like you've posted your homework assignment. We're happy to help you but you have to ShowSomeEffort (← click me). Show us either what you have already coded or post an outline of what you think the program should do.
 
Junilu Lacar
Sheriff
Posts: 11477
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had to complete a similar project in an online Python class I took at Coursera.com except we had to do the more geeky RPSLS (Rock, Paper, Scissors, Lizard, Spock). What do you have so far?
 
Liutauras Vilda
Sheriff
Posts: 4917
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ross Born,

If I understand, you have to write two programs, server and a client, and they have to communicate through a TCP protocol. Correct?
 
Liutauras Vilda
Sheriff
Posts: 4917
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, some hints if my guess is correct in a top post.

On a program (server) side, you'll have to use likely these classes:
BufferedReader, BufferedWriter, InputStreamReader, OutputStreamWriter, ServerSocket, Socket
1. Very first step likely will be on your program to create a server socket object and wait for connection on specific port (if it is not provided, then pick some you like).

On a user (client) side:
BufferedReader, BufferedWriter, InputStreamReader, OutputStreamWriter, Socket
1. On client - create a socket by specifying your local machine host address and port you want to connect (on server and client they have to match).

The rest of flow are pretty clear described in english, what has to be done.
Ross, do you have any specific questions about your assignment, which you cannot understand?

Probably mostly of the guys would suggest you still to start with a pencil and the paper, it would save some your time later, if you'd get lost.


 
Dave Tolls
Ranch Foreman
Posts: 3056
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see anything in the OP that implies a client/server architecture.
Looks like a simple console based game.
 
Liutauras Vilda
Sheriff
Posts: 4917
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dave Tolls wrote:I don't see anything in the OP that implies a client/server architecture.
Looks like a simple console based game.

I might overcomplicated, not sure, you might right.
Well, then everything is easier.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!