Page 1 of 2 12 LastLast
Results 1 to 20 of 30

Thread: Pig Game Lab

  1. #1
    fire is offline Member
    Join Date
    Feb 2012
    Location
    Texas
    Posts
    20
    Rep Power
    0

    Default Pig Game Lab

    Can someone help me with a Pig Game Lab? I have to do the Human Player Part. So far I have this, and I need help on where to begin:

    import static java.lang.System.*;
    import java.util.*;
    import java.awt.*;
    import javax.swing.*;
    import java.io.*;
    import java.util.Scanner.*;


    public class HumanPlayer {

    private int scoreOfPlayer;
    private int totalOfRolls;

    int scoreOfPlayer = 0;
    int totalOfRolls = 0;

    Scanner kb = new Scanner(System.in);
    System.out.println("It's your turn to roll the dice.");


    }



    Need help on it. Thank you for your time!

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: Pig Game Lab

    Not a lot to go on. What is supposed to happen next? Is the program supposed to get some input from the user?

  3. #3
    fire is offline Member
    Join Date
    Feb 2012
    Location
    Texas
    Posts
    20
    Rep Power
    0

    Default Re: Pig Game Lab

    Well, I need to construct a method. It's supposed to calculate scores and have a roll button for dice which is made by my other group partner. But I'm stuck, and it's due tomorrow. Can you/others help me on this lab?

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

    Default Re: Pig Game Lab

    Still not a lot to go on. You need to tell us exactly what you're trying to do, you need to tell us exactly where you're stuck and you need to show your code attempt to solve this. Also you need to understand that no one here will do this for you of course, but we will try to nudge you in the right direction and give you links to tutorials so hopefully you can learn to solve this yourself.

  5. #5
    santa's Avatar
    santa is offline Senior Member
    Join Date
    Nov 2009
    Location
    Sweden
    Posts
    208
    Rep Power
    5

    Default Re: Pig Game Lab

    What exactly are you stuck on ? I't seems that you only recently started with your project ?

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: Pig Game Lab

    Before you can write the code you need to describe what it is supposed to do.
    When you have that,
    for a method you need to know what it will return and what parameters it needs.
    Then you'd write the code, compile it and test it.

    What do you have so far? Post the code, your description of what its to do and your questions.

    have a roll button for dice
    That sounds like you'll need some GUI to put the button on.

  7. #7
    fire is offline Member
    Join Date
    Feb 2012
    Location
    Texas
    Posts
    20
    Rep Power
    0

    Default Re: Pig Game Lab

    Okay so I have to determine first player which is a HumanPlayer. Then I have to roll a die. (which my partner will do) After that, I have to display current turn score with the new die roll. Then prompt if they want to end the turn or continue to roll. Finally, I have to display a total game score.

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: Pig Game Lab

    have to determine first player which is a HumanPlayer
    How do you do that? Do you ask the user a question?

  9. #9
    fire is offline Member
    Join Date
    Feb 2012
    Location
    Texas
    Posts
    20
    Rep Power
    0

    Default Re: Pig Game Lab

    Sorry if I'm not clear enough because this lab could be hard for me, I just make a String variable stating the HumanPlayer. You don't have to ask the user a question.

  10. #10
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: Pig Game Lab

    You don't have to ask the user a question
    What do you plan to use the Scanner class for? It's often used to ask users questions.

    Can you explain the next thing the program is supposed to do after it prints out the message: It's your turn to roll the dice.

  11. #11
    fire is offline Member
    Join Date
    Feb 2012
    Location
    Texas
    Posts
    20
    Rep Power
    0

    Default Re: Pig Game Lab

    They have to press a button that rolls the dice. And it calculates the outcome score after the user rolls the dice. At the end, there is a question asking whether or not the user wants to end the turn or keep on rolling. Then the user enters their input which will update the score board and switches to the computer player.

  12. #12
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: Pig Game Lab

    They have to press a button that rolls the dice
    Do you want a window with a button on it? That will be a lot more code than you are ready to write tonight. There is a lot to setting up a GUI with a button that you can press and have some method called.

    You don't use the Scanner class with a GUI program.
    I suggest that you leave the GUI for the next project and stick with simple console input.

  13. #13
    fire is offline Member
    Join Date
    Feb 2012
    Location
    Texas
    Posts
    20
    Rep Power
    0

    Default Re: Pig Game Lab

    Okay, I don't have to use scanner. I guess window is okay, but I make it simple using the general output window. Problem is I have two errors with the statement line System.out.println("It's your turn to roll the dice."); I have an error on that.

  14. #14
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: Pig Game Lab

    Also with a GUI application you do not use System.out.println to tell the user anything.
    System.out.println would be used for debug output to find program problems.

    If you get errors, you need to post the full text here.

  15. #15
    fire is offline Member
    Join Date
    Feb 2012
    Location
    Texas
    Posts
    20
    Rep Power
    0

    Default Re: Pig Game Lab

    As in the error line like this?: System.out.println("It's your turn to roll the dice.");

    My full text is the first post if you need it.

  16. #16
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: Pig Game Lab

    Please copy full text of error message and paste it here. Here is a sample:
    Java Code:
    TestSorts.java:138: cannot find symbol
    symbol  : variable var
    location: class TestSorts
             var = 2;
             ^

  17. #17
    fire is offline Member
    Join Date
    Feb 2012
    Location
    Texas
    Posts
    20
    Rep Power
    0

    Default Re: Pig Game Lab

    Sorry I couldn't do it like that because I tried to build on file but failed to do so. So I improvised my own. <identifier> expected and illegal start of type System.out.println("It's your turn to roll the dice.");

  18. #18
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: Pig Game Lab

    The code with the error needs to be inside of a method.

  19. #19
    fire is offline Member
    Join Date
    Feb 2012
    Location
    Texas
    Posts
    20
    Rep Power
    0

    Default Re: Pig Game Lab

    Can you show me an example of it? Sorry, I'm still new to Java and I have troubles with methods alot of times.

  20. #20
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 1
    Last Post: 06-02-2011, 09:29 AM
  2. Replies: 2
    Last Post: 08-05-2010, 04:49 AM
  3. game code for any game
    By deathnote202 in forum Java Gaming
    Replies: 4
    Last Post: 06-10-2010, 08:06 AM
  4. can someone help me with this game??
    By amalina in forum New To Java
    Replies: 1
    Last Post: 08-24-2009, 05:59 AM
  5. 2D strategy game or 2D war game
    By led1433 in forum Java 2D
    Replies: 5
    Last Post: 02-10-2009, 06:00 AM

Posting Permissions

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