Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: HELP? Rock paper scissors lizard spock game. Just need 1 last piece, can you help me?

  1. #1
    Junior Member
    Join Date
    Feb 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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?
    Attached Files Attached Files


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: HELP? Rock paper scissors lizard spock game. Just need 1 last piece, can you help me?

    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?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Feb 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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);

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default 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.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Feb 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.

    <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;>

Similar Threads

  1. I REALLY NEED HELP IN SOLVING THIS ROCK PAPER SCISSOR
    By John93 in forum Java Theory & Questions
    Replies: 12
    Last Post: April 8th, 2012, 08:55 PM
  2. Help Improve My Rock,Paper,Scissors
    By Emperor_Xyn in forum Java Theory & Questions
    Replies: 3
    Last Post: December 16th, 2011, 10:34 PM
  3. Rock paper scissors project
    By katie_gsu in forum Loops & Control Statements
    Replies: 1
    Last Post: November 28th, 2011, 02:34 PM
  4. rock paper si
    By robingeldolf in forum What's Wrong With My Code?
    Replies: 4
    Last Post: November 4th, 2011, 06:41 AM
  5. Rock Paper Scissors Spock Lizard Player Problem
    By flyingcurry in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 3rd, 2011, 10:53 AM