This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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:
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.