import java.util.Random;
import java.util.Scanner;
class FunGame
{
/*@param this is the main method
*
*/
public static void main(String [] args)
{
Random ran = new Random();
Scanner s = new Scanner(System.in);
/*@ return this is returning a string to be used later on in the game.
*
*/
String a = "Computer chose Rock";
String b = "Computer chose Paper";
String c = "Computer chose Scissors";
String e = "Computer chose Lizard";
String f = "Computer chose Spock";
// Initialize variables
int hs = 0;
int cs = 0;
int d = 0;
// Created string to use for the game
String choice, rock, paper, scissors, lizard, spock;
int comp;
/* Created a while loop that prints out the appropriate current score and
* basic score for each game played.
*/
while(hs < 5 && cs < 5)
{
comp = ran.nextInt(5);
/* For this assignment, I am using shorthand p to venture new ways
* into learning how to implement different things into Java.
*/
p("\nRock, Paper, Scissors, Lizard, Spock . . . Go!\n");
p("Current score: \nYou = " + hs + "\nComputer = " + cs + "\nDraws = " + d + "\n\n");
choice = s.nextLine();
/* In my example, rock is 0, paper 1, scissors 2 , lizard 3, and spock 4
* The if statements are self explanatory so I will include the logic in one piece.
* For the first if statement, if the user inputs rock, the computer will randomly
* select an option, and based on that option, the output is printed notifying
* the user if they won or not. For example, if the user selects rock and the random
* selection is = 0, which is rock, there is a tie. This follows through all parts of the game
* and is consistent in each section. IF the random selection is = 1 which is paper, the user loses.
*/
if(choice.equals ("rock"))
{
if(comp == 0)
{
p(a);
p("Rock and rock? Looks like we have a tie!");
d = d+1;
}
if(comp == 1)
{
p(b);
p("Paper covers rock, Want to try again?!");
cs = cs + 1;
}
if(comp == 2)
{
p(c);
p("Rock crushes scissors like Cartmen crushes Cheesy Poofs, You win!");
hs = hs+1;
}
if(comp == 3)
{
p(e);
p("Rock crushes the lizard! You win!");
hs = hs+1;
}
if(comp == 4)
{
p(f);
p("Spock vaporizes rocks. Womp Womp, try again!");
cs = cs+1;
}
}
// If statement consistent with my previous statement comments
if(choice.equals ("paper"))
{
if(comp == 0)
{
p(a);
p("Paper closes on rock and no longer lets it see, you win!");
hs = hs + 1;
}
if(comp == 1)
{
p(b);
p("Paper and paper? Try again!");
d = d+1;
}
if(comp == 2)
{
p(c);
p("Paper gets cut by scissors. You Lose!");
cs = cs + 1;
}
if(comp == 3)
{
p(e);
p("Lizard eats paper. You lose!");
cs = cs+1;
}
if(comp == 4)
{
p(f);
p("Paper beats spock! You win");
hs = hs + 1;
}
}
// If statements consistent with previous comments
if(choice.equals ("scissors"))
{
if(comp == 0)
{
p(a);
p("Scissors get smashed by rocks. Try again!");
cs = cs + 1;
}
if(comp == 1)
{
p(b);
p("Two scissors? This isn't a sword fight! Tie!");
d = d+1;
}
if(comp == 2)
{
p(c);
p("Scissors demolish paper. You Win!");
hs = hs+1;
}
if(comp == 3)
{
p(e);
p("Scissors and lizards? Things don't end well for the lizard. You win! ");
hs = hs+1;
}
if(comp == 4)
{
p(f);
p("Spock crushes scissors! You Lose!");
cs = cs+1;
}
}
if(choice.equals ("lizard"))
{
if(comp == 0)
{
p(a);
p("Rock crushes your poor lizard. You lose!");
cs = cs + 1;
}
if(comp == 1)
{
p(b);
p("Lizard eats paper! You win!");
hs = hs + 1;
}
if(comp == 2)
{
p(c);
p("Scissors and lizards?! You lose, just think about that one!");
cs = cs+1;
}
if(comp == 3)
{
p(e);
p("Lizard and lizard = friendship. Draw.");
d = d + 1;
}
if(comp == 4)
{
p(f);
p("Lizard beats spock! You win!");
hs = hs + 1;
}
}
if(choice.equals ("spock"))
{
if(comp == 0)
{
p(a);
p("Spock vaporizes rock. You win!");
hs = hs + 1;
}
if(comp == 1)
{
p(b);
p("Spock loses to paper. You lose!");
cs = cs+1;
}
if(comp == 2)
{
p(c);
p("Spock > scissors. You win!");
hs = hs+1;
}
if(comp == 3)
{
p(e);
p("Spock is killed by a lizard. You lose!");
cs = cs+1;
}
if(comp == 4)
{
p(f);
p("Two spocks? Tie!");
d = d+1;
}
}
}
// If statement saying if the computer score is 5, if you'd like do try again.
if(cs == 5)
{
p("\nThe compter has beat you.");
p("Try again? yes or no?");
}
if(hs == 5)
{
p("You win! You managed to beat the computer!");
}
}
/* @param this describes a method parameter that I used for the string
*
*/
public static void p(String a)
{
System.out.println(a);
}
}