Monday, June 2, 2014

Wow! This program ROCKS! Writes your PAPERS! And Functions as SCISSORS! (The Last Two Statements are False)

The next class I created is to actually play rock paper scissors. It uses the "Q" "W" and "E" keys in order to get an input from the user. Heres the code here:
First off it reads the LastLogin file and sets the User string to the information in that text file. That information is used before the computer input is decided and is printed to the console with a ":" after it so that when the user roll is chosen it reads "[User]: [Rock/Paper/Scissors]." The program uses a KeyListener which checks for if the "Q" "W" or "E" keys are pressed. Once it determines which key is pressed it sets Rock Paper or Scissors accordingly. Then a random number generator is started and picks a number between 1 and 3, and sets that to the roll variable. Then based on what the roll variable is either rock paper or scissors is chosen for the computer and based on what the conclusion of the game is it prints "Win!", "Loss!" or "Tie!" to the console. Overall the actual rock paper scissors program was fairly simple to make, the only difficult parts were the launcher and attempting to get the leaderboard to work. The Launcher was detailed in the last post, and the Leaderboard never actually came to be. The reason for this was that I couldn't get variables to be pulled out of if loops, which seems like it should be very easy but actually isn't. Because I couldn't get those pulled out of the loops I couldn't get the wins and losses to accumulate so I could never get that part to work. Overall this program was a good experience in java, and got me to learn a lot. It exercised all the aspects of Java I had learned in the past, and got me to learn many more. I had some difficult moments, and some aspects of the program that were done in seconds, but overall it was a sufficient challenge and I hope to make more programs like it in the future.

No comments:

Post a Comment