import java.util.Scanner;
public class labSection14
{
public static void main(String[] args)
{
String userInput;
int userChoice = -1, cpuChoice, timesWon = 0, timesLost = 0, timesTied = 0;
boolean debug = false;
// debug = true;
Scanner kb = new Scanner(System.in);
while( userChoice >= -1)
{
cpuChoice = (int)(Math.random() * 3);
System.out.print("Enter your choice (Rock, Paper, or Scissors): ");
userInput = kb.next();
// Start Choice Assignments
if( userInput.equalsIgnoreCase("rock") || userInput.equalsIgnoreCase("r") )
userChoice = 0;
else if( userInput.equalsIgnoreCase("paper") || userInput.equalsIgnoreCase("p") )
userChoice = 1;
else if( userInput.equalsIgnoreCase("scissors") || userInput.equalsIgnoreCase("s") )
userChoice = 2;
else if( userInput.equalsIgnoreCase("debug") && debug == true)
userChoice = 3;
else
{
System.out.println("Invalid choice");
break;
}
// Start Choice Winner Determination
if( userChoice == 3) // Backdoor :)/>
System.out.println("You won! You are: "+ ++timesWon +":"+ timesLost +":"+ timesTied);
else if( userChoice == 0 && cpuChoice == 0) // Rock v Rock
System.out.println("You tied! You are: "+ ++timesWon +":"+ timesLost +":"+ ++timesTied);
else if( userChoice == 0 && cpuChoice == 1) // Rock v Paper
System.out.println("You lost! You are: "+ ++timesWon +":"+ ++timesLost +":"+ timesTied);
else if( userChoice == 0 && cpuChoice == 2) // Rock v Scissors
System.out.println("You won! You are: "+ ++timesWon +":"+ timesLost +":"+ timesTied);
else if( userChoice == 1 && cpuChoice == 0) // Paper v Rock
System.out.println("You won! You are: "+ ++timesWon +":"+ timesLost +":"+ timesTied);
else if( userChoice == 1 && cpuChoice == 1) // Paper v Paper
System.out.println("You tied! You are: "+ timesWon +":"+ timesLost +":"+ ++timesTied);
else if( userChoice == 1 && cpuChoice == 2) // Paper v Scissors
System.out.println("You lost! You are: "+ timesWon +":"+ ++timesLost +":"+ timesTied);
else if( userChoice == 2 && cpuChoice == 0) // Scissors v Rock
System.out.println("You lost! You are: "+ timesWon +":"+ ++timesLost +":"+ timesTied);
else if( userChoice == 2 && cpuChoice == 1) // Scissors v Paper
System.out.println("You won! You are: "+ ++timesWon +":"+ timesLost +":"+ timesTied);
else if( userChoice == 2 && cpuChoice == 2) // Scissors v Scissors
System.out.println("You tied! You are: "+ timesWon +":"+ timesLost +":"+ ++timesTied);
else // Internal Error
{
System.err.println("Internal Error");
break;
}
if(debug == true)
{
System.out.println("RAW INFO::userChoice=="+ userChoice +"::cpuChoice==="+ cpuChoice);
}
System.out.print("Play again(y/n)? ");
userInput = kb.next();
if( userInput.equalsIgnoreCase("y") || userInput.equalsIgnoreCase("yes") )
{
continue;
}
else
{
break;
}
}
kb.close();
}
}
Java Rock Paper Scissors GameWant to see if there are any improvements I should make
Page 1 of 1
4 Replies - 7674 Views - Last Post: 10 March 2010 - 08:53 PM
#1
Java Rock Paper Scissors Game
Posted 10 March 2010 - 02:53 PM
For my AP Computer science class we have to make a rock paper scissors game. I was wondering if there were any improvements anybody thinks I should make. Thanks in advance.
Replies To: Java Rock Paper Scissors Game
#2
Re: Java Rock Paper Scissors Game
Posted 10 March 2010 - 03:07 PM
Well, does it work? As far as cleaning it up, with what I've seen so far, I don't think you can do much at that level to clean it up. No offense, I'm just saying. Most professors don't like when the student codes GUIs while the rest of the class is only on Hello, world! (that was a metaphor). They think you're cheating. So, does it have any problems or what?
#3
Re: Java Rock Paper Scissors Game
Posted 10 March 2010 - 03:14 PM
No it doesn't have any problems lol. I guess you are right was just trying to see if there was something new I could learn, but you are right.
#4
Re: Java Rock Paper Scissors Game
Posted 10 March 2010 - 03:23 PM
Alrighty, looks fine to me for now ^___^
#5
Re: Java Rock Paper Scissors Game
Posted 10 March 2010 - 08:53 PM
NeoTifa, on 10 March 2010 - 01:07 PM, said:
Well, does it work? As far as cleaning it up, with what I've seen so far, I don't think you can do much at that level to clean it up. No offense, I'm just saying. Most professors don't like when the student codes GUIs while the rest of the class is only on Hello, world! (that was a metaphor). They think you're cheating. So, does it have any problems or what?
I guess it's good that my teacher knows that I'm ahead. His mentality: as long as it does what I want it to do, you can add stuff to it. Though it's true, most teachers generally don't like it when you start doing tons of stuff that's out of class in class.
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote








|