2 Attachment(s)
HELP? Rock paper scissors lizard spock game. Just need 1 last piece, can you help me?
So here's my code. It's alllllll done except I need the errorCount to be round specific.
You need to run the 2 classes together.
So when you run it. The error count should increment for each round. With an allotment of 2 errors per round.
Right now it's just 2 errors total for the entire project. So if you make an error in round 1 and round 2 it exits.
I'm trying to make it so if you make 2 errors in 1 round if exits.
So if you did:
Round 1: "q"
invalid input (error count =1)
it reprompts
Round 1: "1"
Paper beats rock. You win a point (error count = 0)
Round 2: "q"
invald input (error count = 1)
reprompts
Round 2: "q"
invalid input (error count = 2)
you have entered too many invalid inputs
system.exit(0)
Does that make sense?
Re: HELP? Rock paper scissors lizard spock game. Just need 1 last piece, can you help me?
Quote:
I need the errorCount to be round specific.
Would saving the errorCount in an array (or arraylist) with the index being the round do the job?
Re: HELP? Rock paper scissors lizard spock game. Just need 1 last piece, can you help me?
Thanks for the reply man!
I'm not sure actually. I'm a super noob at programming ,but I'll give it a shot and let you know if it works!
--- Update ---
Ok so I have no idea how I would use an array for this.
I'm using a giant switch statement for the game itself & right now I'm just trying to make my default case track the errors.
So I'm trying to do something like
default:
System.out.println("The input you entered is invalid.");
if (roundCount == 1)
errorCount++;
else errorCount = 0;
if (roundCount == 2){
errorCount++;
else errorCount = 0;
it works if for round 1 if I only have the first if else ,but when I try to use the same if else for the other rounds it just keeps reseting the error count to 0.
outside the switch I have
if(errorCount == 2 ){
System.out.println("You entered too many invalid inputs.");
System.out.print("Goodbye!");
System.exit(0);
Re: HELP? Rock paper scissors lizard spock game. Just need 1 last piece, can you help me?
Make errorCount an array and use the round number as the index.
For the first round add to errorCount[0]
for the second round add to errorCount[1]
etc
When posting code please wrap your code with
[code=java]
<YOUR CODE HERE>
[/code]
to get highlighting and preserve formatting.
Re: HELP? Rock paper scissors lizard spock game. Just need 1 last piece, can you help me?
Ok! I fixed it!
I guess I'm just dumb. I couldn't figure out the array ,but here's my fix if you're interested.
Code java:
<switch (playerChoice){
case "1":
//call to computer
errorCount = 0;
roundCount++;
computerChoice = RockPaperScissorsLizardSpockComputerPlayer.getChoice();
System.out.println("The computer player chooses " + computerChoice);
switch (computerChoice){
case "rock":
System.out.println("Its a tie!");
System.out.println("No points are awarded.");
break;
case "paper":
System.out.println("Paper covers rock.");
System.out.println("The computer player wins a point.");
computerPoints++;
break;
case "scissors":
System.out.println("Rock crushes scissors.");
System.out.println("Congratulations! You win a point.");
playerPoints++;
break;
case "lizard":
System.out.println("Rock crushes lizard");
System.out.println("Congratulations! You win a point.");
playerPoints++;
break;
case "spock":
System.out.println("Spock vaporizes rock.");
System.out.println("The computer player wins a point.");
computerPoints++;
break;
}
break;>