A player wins one point for each target number rolled during a turn. For example, if a player rolls 2, 1, and 1 in round one, that player scores 2 points for that roll. A Bunco occurs when a player rolls three of the target (round) number, i.e., three 1s in round one, three 2s in round two, and so on. A Bunco is worth 21 points. A Baby Bunco occurs when a player rolls three of any number except the target number, i.e., three 1s in round two, or three 3s in round 2, and so on. A Baby Bunco is worth 5 points. A round ends when one of the players reaches a score of at least 21 and wins that round. The game is over once all six rounds are played. The player with the most number of rounds won wins the game.
A player continues to roll for as long as points are won in a roll. If no points are won in a roll, the dice are passed to the opponent. The game is played in sequence from round 1 to round 6.
First of all, I write a die class which will represent for 3 dice. Here the code:
public class Die {
/** maximum face value */
private static final int MAX = 6;
/** current value showing on the die */
private int faceValue;
/**
* Constructor: Sets the initial face value of this die.
*/
public Die () {
faceValue = 1;
}
/**
* Computes a new face value for this die and returns the
* result.
* @return an int
*/
public int roll () {
faceValue = (int) (Math.random () * MAX) + 1;
return faceValue;
}
/**
* Face value mutator. The face value is not modified if the
* specified value is not valid.
* @param value an int indicating the face value of the die
*/
public void setFaceValue (int value) {
if (value > 0 && value <= MAX)
faceValue = value;
}
/**
* Face value accessor.
* @return an int
*/
public int getFaceValue () {
return faceValue;
}
/**
* Returns a string representation of this die.
* @return String object
*/
@Override
public String toString () {
String result = Integer.toString (faceValue);
return result;
}
public static void main(String[] args) {
// TODO code application logic here
}
}Then, I create Diceset class which contain 3 dice and how it roll, here the code:public class Diceset {
private Die d1,d2,d3;
public DiceSet(){} // instantiate d1, d2, d3
public int getValue(int dieNumber) throws IllegalArgumentException {
// returns the face value of die with dieNumber
// throws IllegalArgumentException if dieNumber is
// not valid (< 1 or > 3)
}
public void roll() {
// roll d1, d2, and d3
}
public static void main(String[] args) {
}
}
Finally, I create Bunco class, show how the game is played. Here the code:
public class Bunco {
private DiceSet myDice;
private Scanner myScanner;
/* add other private variables as needed */
public Bunco() {
myDice = new DiceSet();
myScanner = new Scanner(System.in);
}
public void play() {
// the main logic of the game goes here. This method
// invokes the userTurn() and computerTurn() methods as required
}
private void userTurn() {
// This method handles a single turn for the user player
}
private void computerTurn() {
// This method handles a single turn for the computer player
}
public static void main (String[] args) {
Bunco game = new Bunco();
game.play();
}
}For some reason, this game doesn't work, I would be appreciate if anyone can help me find the problem and fix it.
Edited by ZekeDragon, 06 September 2010 - 09:36 PM.
Please use [code] tags when posting code.


Sign In
Create Account

Back to top









