preview

How To Import Ap Yahtzee Case Study Answers

Decent Essays
Open Document

mport java.awt.Color; import acm.io.*; import acm.program.*; import acm.util.*; public class Yahtzee extends GraphicsProgram implements YahtzeeConstants { /** * Constants for the lowest and highest values that the dice can be. * In a typical game of Yahtzee, the lowest value is 1 and the highest * is 6 as this range is normal for dice. However, this allows * for the values to be changed in desired. */ public static final int MINDICEVALUE = 1; public static final int MAXDICEVALUE = 6; public static final int MAXEXTRAROLLS = 2; public static void main(String[] args) { new Yahtzee().start(args); } /* * Runs the game Yahztee. */ public void run() { IODialog dialog = getDialog(); nPlayers = dialog.readInt("Enter …show more content…

} } playerScores[UPPER_SCORE][p] += score; } break; case 6: if (checkCategory(dice, SIXES)) { for(int d = 0; d < N_DICE; d++) { if (dice[d] == 6) { score += 6; } } playerScores[UPPER_SCORE][p] += score; } break; //End of upper score categories case 9: //Beginning of lower score categories if (checkCategory(dice, THREE_OF_A_KIND)) { for(int d = 0; d < N_DICE; d++) { score += dice[d]; } playerScores[LOWER_SCORE][p] += score; } break; case 10: if (checkCategory(dice, FOUR_OF_A_KIND)) { for(int d = 0; d < N_DICE; d++) { score += dice[d]; } playerScores[LOWER_SCORE][p] += score; } break; case 11: if (checkCategory(dice, FULL_HOUSE)) { score = 25; playerScores[LOWER_SCORE][p] += score; } break; case 12: if (checkCategory(dice, SMALL_STRAIGHT)) { score = 30; playerScores[LOWER_SCORE][p] += score; } break; case 13: if (checkCategory(dice, LARGE_STRAIGHT)) { score = 40; playerScores[LOWER_SCORE][p] += score; } break; case 14: if (checkCategory(dice, YAHTZEE)) { score = 50; playerScores[LOWER_SCORE][p] += score; } break; case 15: if (checkCategory(dice, CHANCE))

Get Access