Rock-Paper-Scissors

This was a fun programing assignment (if only because I heard so much whining and head-scratching from my fellow classmates).

The task: Create a game of rock-paper-scissors to play against the computer.

For this, we need a random number generator so that it’s like playing the game against a dice. You don’t know what it’s outcome will be and the computer isn’t able to “cheat”. Luckily enough, java comes with a random number generator, so it’s just a matter of handling the outcomes.

I assembled my program in two halves. The first half, it’s own method, checked the user input and returns a number to correspond with the choice (1 for rock, 2 for paper, 3 for scissors, and 4 if the user doesn’t enter the right value). Then the computer generates a random number and compares it against the user input using a switch/catch tree with an if/else tree inside. So, it catches the computer input and tests it against the user input.

Thankfully, it worked on the first try and is rather clean and concise. The code.
~Locke

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: