public void UseScore(ScoreSlot slot, DiceSet set) { if (slot == SLOT_YAHTZEE) { } //Add bonus here if (!slot.Score.HasValue) { if (slot.Qualifier(set)) { slot.Score = slot.ScorePotential(set); } else { slot.Score = 0; } } }
public void UseScore(ScoreSlot slot, DiceSet set) { ScoreCard.UseScore(slot, set); Reset(); }
public ScoreCard() { SLOT_ONES = createUpperSlot(1, 1); SLOT_TWOS = createUpperSlot(2, 2); SLOT_THREES = createUpperSlot(3, 3); SLOT_FOURS = createUpperSlot(4, 4); SLOT_FIVES = createUpperSlot(5, 5); SLOT_SIXES = createUpperSlot(6, 6); SLOT_THREE_OF_KIND = new ScoreSlot(11) { Qualifier = (diceset) => { int[] count = new int[DiceSet.DICE_FACE + 1]; foreach (GameDie die in diceset) { if (die.Number >= 1 && die.Number <= DiceSet.DICE_FACE) { count[die.Number] += 1; } } for (int index = 1; index < DiceSet.DICE_FACE + 1; index += 1) { if (count[index] >= 3) { return(true); } } return(false); }, ScorePotential = (diceset) => calcDiceSum(diceset) }; SLOT_FOUR_OF_KIND = new ScoreSlot(12) { Qualifier = (diceset) => { int[] count = new int[DiceSet.DICE_FACE + 1]; foreach (GameDie die in diceset) { if (die.Number >= 1 && die.Number <= DiceSet.DICE_FACE) { count[die.Number] += 1; } } for (int index = 1; index < DiceSet.DICE_FACE + 1; index += 1) { if (count[index] >= 4) { return(true); } } return(false); }, ScorePotential = (diceset) => calcDiceSum(diceset) }; SLOT_FULL_HOUSE = new ScoreSlot(13) { Qualifier = (diceset) => { int[] count = new int[DiceSet.DICE_FACE + 1]; foreach (GameDie die in diceset) { if (die.Number >= 1 && die.Number <= DiceSet.DICE_FACE) { count[die.Number] += 1; } } bool two = false; bool three = false; for (int index = 1; index < DiceSet.DICE_FACE + 1; index += 1) { if (count[index] == 2) { two = true; } else if (count[index] == 3) { three = true; } } return(two && three); }, ScorePotential = (diceset) => 25 }; SLOT_SMALL_STRAIGHT = new ScoreSlot(14) { Qualifier = (diceset) => { int[] count = new int[DiceSet.DICE_FACE + 1]; foreach (GameDie die in diceset) { if (die.Number >= 1 && die.Number <= DiceSet.DICE_FACE) { count[die.Number] += 1; } } int inSeq = 0; for (int index = 1; index < DiceSet.DICE_FACE + 1; index += 1) { if (count[index] == 0) { inSeq = 0; } else { inSeq += 1; if (inSeq >= 4) { return(true); } } } return(inSeq >= 3); }, ScorePotential = (diceset) => 30 }; SLOT_LARGE_STRAIGHT = new ScoreSlot(15) { Qualifier = (diceset) => { int[] count = new int[DiceSet.DICE_FACE + 1]; foreach (GameDie die in diceset) { if (die.Number >= 1 && die.Number <= DiceSet.DICE_FACE) { count[die.Number] += 1; } } int inSeq = 0; for (int index = 1; index < DiceSet.DICE_FACE + 1; index += 1) { if (count[index] == 0) { inSeq = 0; } else { inSeq += 1; if (inSeq >= 5) { return(true); } } } return(inSeq >= 3); }, ScorePotential = (diceset) => 40 }; SLOT_CHANCE = new ScoreSlot(16) { Qualifier = (diceset) => true, ScorePotential = (diceset) => calcDiceSum(diceset) }; SLOT_YAHTZEE = new ScoreSlot(17) { Qualifier = (diceset) => { int[] count = new int[DiceSet.DICE_FACE + 1]; foreach (GameDie die in diceset) { if (die.Number >= 1 && die.Number <= DiceSet.DICE_FACE) { count[die.Number] += 1; } } for (int index = 1; index < DiceSet.DICE_FACE + 1; index += 1) { if (count[index] == 5) { return(true); } } return(false); }, ScorePotential = (diceset) => 50 }; }