wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Pig Game Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Pig Game" Watch "Pig Game" New topic
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: 825
    
    5

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: 11172
    
  16

i got 11 compiler errors.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
arulk pillai
Author
Ranch Hand

Joined: May 31, 2007
Posts: 3219
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: 38087
    
  22
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 can&#s2019;t be object‑oriented without objects to create.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Pig Game
 
Similar Threads
Help with Class
Dice game issue
Methods
Having problem compiling this answer
Please help, java program terminating unexpectedly without reason