Results 1 to 8 of 8
Like Tree2Likes
  • 1 Post By JosAH
  • 1 Post By Junky

Thread: Rock paper scissors.

  1. #1
    katie_gsu is offline Member
    Join Date
    Nov 2011
    Location
    Statesboro, GA
    Posts
    3
    Rep Power
    0

    Question Rock paper scissors.

    Hi everyone,

    I'm writing a Rock, Paper, Scissors program in Java. I am in my first Java class and I am still new at this :(
    So far I have it so that the user enters a number that corresponds with their choice. I am supposed to error check the user input to make
    sure it is either Rock, Paper or Scissors, and if not, they will be prompted to enter it again. I'm supposed to use a do/while loop to allow the
    user to continue playing games until ready to quit, and what's scaring me the most, is I have to use a multi-dimensional array to store the user's choices and the computer's choices for each round, and output the game details for each round.

    Can anyone PLEASE help me? I feel like this is overwhelming and I'm so lost.

    Thanks,
    Katie

    PS
    I attached the structure part of the program that I am using to try and figure out these problems I'm having.


    Attached Files Attached Files

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is online now Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,971
    Rep Power
    8

    Default Re: Rock paper scissors.

    If you want help, you'll have to provide an SSCCE that demonstrates where you're stuck. What have you tried? What works, what doesn't work? How doesn't it work?

    Break your problem up into tiny pieces, and focus on one small step at a time. What is the very next, smallest thing you know you have to do?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    KevinWorkman's Avatar
    KevinWorkman is online now Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,971
    Rep Power
    8

    Default Re: Rock paper scissors.

    But I guess you didn't like that suggestion?

    Crossposted: Rock paper scissors project
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  4. #4
    katie_gsu is offline Member
    Join Date
    Nov 2011
    Location
    Statesboro, GA
    Posts
    3
    Rep Power
    0

    Default Re: Rock paper scissors.

    Thank you for your reply, I am trying to break it down now. I will post back later.

    As for your pointing out crossposts, I'm just trying to get as much insight from as many people as I can.

  5. #5
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,574
    Blog Entries
    7
    Rep Power
    21

    Default Re: Rock paper scissors.

    As Kevin wrote: solve the problem in tiny pieces; maybe one tiny piece that might help is this: you think of Rock, Paper, Scissors, but your computer might prefer the numbers 0, 1 and 2. 0 wins from 1, 1 wins from 2 and 2 wins from 0. Mathematically speaking x wins from (x+1)%3 where x is 0, 1 or 2 (check it). b.t.w. the % operator is Java's modulo operator. Keeping track of pairs of numbers and comparing them is easier than having to deal with Strings. Of course us humans prefer to think of Rocks, Paper and Scissors, but that's just because humans are strange creatures ;-)

    kind regards,

    Jos
    katie_gsu likes this.
    cenosillicaphobia: the fear for an empty beer glass

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Rock paper scissors.

    An alternative solution that you'll probably not want to use, but may give you some ideas was one that I posted here: stackoverflow: no-desired-output-probable-cause-is-an-overload. It uses enums and a payout matrix which is a bit of overkill perhaps.

  7. #7
    katie_gsu is offline Member
    Join Date
    Nov 2011
    Location
    Statesboro, GA
    Posts
    3
    Rep Power
    0

    Default Re: Rock paper scissors.

    Quote Originally Posted by JosAH View Post
    As Kevin wrote: solve the problem in tiny pieces; maybe one tiny piece that might help is this: you think of Rock, Paper, Scissors, but your computer might prefer the numbers 0, 1 and 2. 0 wins from 1, 1 wins from 2 and 2 wins from 0. Mathematically speaking x wins from (x+1)%3 where x is 0, 1 or 2 (check it). b.t.w. the % operator is Java's modulo operator. Keeping track of pairs of numbers and comparing them is easier than having to deal with Strings. Of course us humans prefer to think of Rocks, Paper and Scissors, but that's just because humans are strange creatures ;-)

    kind regards,

    Jos
    I currently have a user input dialog that asks the user to input a number (0,1,2) for either rock, paper or scissors, and the game works fine. Unfortunately, the new project calls for the user to input
    the word instead of a number :/. I am trying to figure out how to use a string for both the user's input and the computers random input. So far I get errors of incompatible operand types String and int.
    Is there a way that I can convert the user's input of the word Rock, Paper, or Scissors back to a number, so that I can leave the if statement as is? This seems like it would be the easiest thing to do?

    I am thinking of using a switch statement for the computer's choice that maybe could solve this. Something like:
    case 0:
    computerChoice = "Rock";
    break;
    etc.

    Thank you for your kind reply!
    Last edited by katie_gsu; 11-29-2011 at 02:05 AM.

  8. #8
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default Re: Rock paper scissors.

    Using a switch sounds good. Or you could place the Strings into an array and use the choice as the index into the array. Or you could use an enum which has already been suggested.
    katie_gsu likes this.

Similar Threads

  1. Help! (Java GUI - Rock, Paper, Scissors)
    By Snowball in forum New To Java
    Replies: 5
    Last Post: 06-16-2011, 06:37 AM
  2. Replies: 3
    Last Post: 02-17-2011, 02:42 AM
  3. Rock, paper, scissors
    By StevenF in forum New To Java
    Replies: 3
    Last Post: 01-30-2011, 11:38 PM
  4. Rock Paper Scissors
    By 54byler in forum Advanced Java
    Replies: 2
    Last Post: 04-23-2009, 06:23 AM
  5. Need help with Rock Paper Scissors Game
    By GettinGwap in forum New To Java
    Replies: 12
    Last Post: 10-19-2008, 06:15 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •