Results 1 to 8 of 8
  1. #1
    kaanax is offline Member
    Join Date
    Aug 2010
    Posts
    2
    Rep Power
    0

    Default Paper rock Scissors Game inheritance problem

    Hello everyone,

    I wrote a game which name is in title. But i must write code without using if(comprasion). Can you give me some advice?

    there are 4 class. Item, paper, rock, scissors. P, R, S are Item. Item is abstract class.
    Thank you.

  2. #2
    kaanax is offline Member
    Join Date
    Aug 2010
    Posts
    2
    Rep Power
    0

    Default

    this program main method:

    import java.util.ArrayList;
    import java.util.List;

    public class GameMain extends Item {

    public static void main(String[] args) {

    List <Item> itemList = new ArrayList<Item>();
    itemList.add(new Paper("Paper"));
    itemList.add(new Scissors("Scissors"));
    itemList.add(new Stone("Stone"));

    for(Item item1: itemList){
    for(Item item2:itemList){
    System.out.print(item1 + "<--->" + item2 + " ");
    item1.match(item2);
    }


    }

    }
    }

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,559
    Rep Power
    25

    Default

    How are you representing the players? And their choices?

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,651
    Blog Entries
    7
    Rep Power
    21

    Default

    If you have to do it completely without if statements you have to assign a rank to rock, scissors, paper, e.g. 0, 1, 2. You also have to define a 'decistion matrix' that tells the user who has won, e.g.

    Java Code:
    String[][] win= {
       { "tie", "computer wins", "human wins" },
       { "human wins", "tie", "computer wins" },
       { "computer wins", "human wins", "tie }
    };
    The row index is the computer's guess, the column index is the human's guess.

    kind regards,

    Jos

  5. #5
    imorio is offline Senior Member
    Join Date
    Aug 2010
    Posts
    127
    Rep Power
    0

    Default

    I'd say use a switch statement.

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,651
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by imorio View Post
    I'd say use a switch statement.
    A switch statement is an if statement in disguise ...

    kind regards,

    Jos

  7. #7
    imorio is offline Senior Member
    Join Date
    Aug 2010
    Posts
    127
    Rep Power
    0

    Default

    Quote Originally Posted by JosAH View Post
    A switch statement is an if statement in disguise ...

    kind regards,

    Jos
    A problem is a solution in disguise :D

  8. #8
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,651
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by imorio View Post
    A problem is a solution in disguise :D
    True, and sometimes their disguise is so develish that they look like an entirely other problem ;-)

    kind regards,

    Jos

Similar Threads

  1. Stone, Paper, Scissors game help
    By Harris68 in forum Networking
    Replies: 1
    Last Post: 12-19-2009, 04:33 PM
  2. Rock, Paper, Scissor Game Help
    By CYANiDE in forum New To Java
    Replies: 6
    Last Post: 10-28-2009, 04:20 PM
  3. Rock Paper Scissors
    By 54byler in forum Advanced Java
    Replies: 2
    Last Post: 04-23-2009, 06:23 AM
  4. Need Help with Rock paper and Scissors Java Game
    By kingsun in forum New To Java
    Replies: 3
    Last Post: 11-17-2008, 03:35 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
  •