| Author |
Pig Game
|
Andy Hammersmith
Greenhorn
Joined: Sep 30, 2012
Posts: 13
|
|
For my beginning java class we are suppose to make a pig game following these guidelines:
- You are going to make a computer player vs human player game using two dice
- On each turn, the player rolls a pair of dice and adds up his or her points.
- Whoever reaches 100 points first, wins. You are allowed to go over.
- If a player rolls a 1, he or she loses all points for that round and the dice go to the other player
- If a player rolls two 1's in one turn, the player loses all points earned so far in the game and loses control of the dice
- The player may voluntarily turn over the dice after each roll. So the player must decide to either roll again (be a pig) and risk losing points, or give up the dice, possibly letting the other player win.
- Setup the computer player so that it always gives up the dice after getting 20 or more point in a round.
I have the code all written but for some reason I am not able to get it to continue on past the first two turns. I would very much appreciate help. Any suggestions on how to condense it would also be appreciated.
My code is as follows:
|
 |
Kemal Sokolovic
Bartender
Joined: Jun 19, 2010
Posts: 792
|
|
|
Are you sure you can even compile that code you posted?
|
The quieter you are, the more you are able to hear.
|
 |
fred rosenberger
lowercase baba
Bartender
Joined: Oct 02, 2003
Posts: 9952
|
|
|
i got 11 compiler errors.
|
Never ascribe to malice that which can be adequately explained by stupidity.
|
 |
arulk pillai
Author
Ranch Hand
Joined: May 31, 2007
Posts: 3190
|
|
|
Break down your code into smaller sub functions. It will be easier to read, debug, and some functions can be reused as well.
|
Java Interview Questions and Answers Blog | Amazon.com profile | Java Interview Books
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32708
|
|
Welcome to the Ranch
I always worry when I see a main method that long. I worry when I see a main method longer than 1 statement, in fact.
Not only should you create lots of small methods, but I think you should also create Player and Die classes, because you are supposed to be learning object‑oriented programming and you cans2019;t be object‑oriented without objects to create.
|
 |
 |
|
|
subject: Pig Game
|
|
|