• Post Reply Bookmark Topic Watch Topic
  • New Topic

Pig Game  RSS feed

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure you can even compile that code you posted?
 
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i got 11 compiler errors.
 
Author
Ranch Hand
Posts: 3417
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Break down your code into smaller sub functions. It will be easier to read, debug, and some functions can be reused as well.
 
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!