Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Slice & dice game  RSS feed

 
Princess Shalini
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is my first Java beginner course and I am having trouble with creating the code for my game.

The game is between two players goes as follows:

The goal is to be the first one to reach 100 points.... The players will alternate turns. However, during a turn, a player may roll as many times as she pleases, and each sum of the pair of dice will be added to her total.

However, if the player rolls doubles then the player loses all the points and begins all over and loses their turn and must pass the dice.

If the player chooses to pass the dice to her opponent before doubles are rolled, the points will be permanently added to her total.

So far i have done the following - any guidance would be appreciated... what i am really confused on is how do I alternative between the 2 players.... thanks

 
fred rosenberger
lowercase baba
Bartender
Posts: 12542
48
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the biggest problem you have is that all your code is in the main method. That means none of it is re-usable.

You need to think about re-doing this code in a OO-way. You need to think up what classes you want to create, and what methods they should have.

At the VERY least, you want to break down your code into methods so you can call them as needed.

And really, before you do any of that, you should turn off your computer and use your brain. Coding is really 90% thinking, and 10% typing. You should really know (or at least have a good idea about) how to do it before you type a single line of java.
 
Princess Shalini
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks fred rosenberger - i am only in grade 10 and i was looking for some guidance and patience. This is a beginner course assignment and i was looking for some help! Not nasty comments
 
Stephan van Hulst
Saloon Keeper
Posts: 7806
142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please don't interpret Fred's advice as being nasty! He gave you valuable advice that applies to all programmers. He's not saying you're not using your brain, he's just highlighting the fact that programming starts by breaking up the problem in your mind.

From your story, it looks like you need a way to roll a pair of dice, and determine the sum, and whether doubles were rolled.

You also need a way to save the total of each player, and you need to be able to pass the turn.

All of this means you can probably have a DiceRoll class represents one roll of two dice, and you can have a Player class that makes DiceRolls until they roll doubles, or they win.

Finally a DiceGame class keeps track of which player's turn it is, and whether the game is finished.

You can print the output of these classes to the console. Don't even think of starting with a graphical user interface before you've implemented these classes.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!