public Object[] GetScoreOptions() { if (pointOptions.Count == points.Length) { PointOption[] toReturn = new PointOption[points.Length]; for (int i = 0; i < toReturn.Length; i++) { if (points[i] == 0 || pointOptions[i].CanBeUsedAgain()) { toReturn[i] = pointOptions[i]; } } return(toReturn); } else { throw new Exception(exceptionArrayLengthsNotSameSize); } }
private void SetupPointOptions() { if (pointOptions == null) { pointOptions = new List <PointOption>(); if (sameNumberExtraPointBonusIndexes == null) { sameNumberExtraPointBonusIndexes = new List <int>(); } else { sameNumberExtraPointBonusIndexes.Clear(); } for (int i = 1; i < numberOfDiceSides + 1; i++) { string name = "all " + i + "s"; string textBeforePoints = "all " + i + " together get to a total of "; int targetNumber = i; Func <int[], int> calculatePoints = (int[] diceResults) => { int total = 0; foreach (int result in diceResults) { if (result == targetNumber) { total += result; } } return(total); }; PointOption option = new PointOption(name, calculatePoints, textBeforePoints, false); pointOptions.Add(option); for (int o = 0; o < pointOptions.Count; o++) { if (pointOptions[o] == option) { sameNumberExtraPointBonusIndexes.Add(o); break; } } } string threeOfAKindName = "Three Of A Kind"; string threeOfAKindTextBeforePoints = threeOfAKindName + " where " + threeOfAKindAmountOfDiceWithSameNumberThreshold + " dice must be the same and all numbers are put together for a score of "; Func <int[], int> threeOfAKindCalculatePoints = (int[] diceResults) => { for (int i = 1; i < numberOfDiceSides + 1; i++) { int amountOfDiceWithNumber = 0; for (int o = 0; o < diceResults.Length; o++) { if (diceResults[o] == i) { amountOfDiceWithNumber++; } } if (amountOfDiceWithNumber >= threeOfAKindAmountOfDiceWithSameNumberThreshold) { int result = 0; foreach (int diceResult in diceResults) { result += diceResult; } return(result); } } return(0); }; pointOptions.Add(new PointOption(threeOfAKindName, threeOfAKindCalculatePoints, threeOfAKindTextBeforePoints, false)); string carréName = "Carré"; string carréTextBeforePoints = carréName + " where " + carréAmountOfDiceWithSameNumberThreshold + " dice must be the same and all numbers are put together for a score of "; Func <int[], int> carréCalculatePoints = (int[] diceResults) => { for (int i = 1; i < numberOfDiceSides + 1; i++) { int amountOfDiceWithNumber = 0; for (int o = 0; o < diceResults.Length; o++) { if (diceResults[o] == i) { amountOfDiceWithNumber++; } } if (amountOfDiceWithNumber >= carréAmountOfDiceWithSameNumberThreshold) { int result = 0; foreach (int diceResult in diceResults) { result += diceResult; } return(result); } } return(0); }; pointOptions.Add(new PointOption(carréName, carréCalculatePoints, carréTextBeforePoints, false)); string fullHouseName = "Full House"; string fullHouseTextBeforePoints = fullHouseName + " where " + fullHouseAmountOfDiceWithSameNumberThresholdOne + " dice must be the same and " + fullHouseAmountOfDiceWithSameNumberThresholdTwo + " other dice must be the same for a total of "; Func <int[], int> fullHouseCalculatePoints = (int[] diceResults) => { for (int diceSideToTestForOne = 1; diceSideToTestForOne < numberOfDiceSides + 1; diceSideToTestForOne++) { int amountOfDiceWithNumberOne = 0; for (int i = 0; i < diceResults.Length; i++) { if (diceResults[i] == diceSideToTestForOne) { amountOfDiceWithNumberOne++; } } if (amountOfDiceWithNumberOne >= fullHouseAmountOfDiceWithSameNumberThresholdOne) { for (int diceSideToTestForTwo = 1; diceSideToTestForTwo < numberOfDiceSides + 1; diceSideToTestForTwo++) { int amountOfDiceWithNumberTwo = 0; for (int i = 0; i < diceResults.Length; i++) { if (diceResults[i] == diceSideToTestForTwo && diceSideToTestForOne != diceSideToTestForTwo) { amountOfDiceWithNumberTwo++; } } if (amountOfDiceWithNumberTwo >= fullHouseAmountOfDiceWithSameNumberThresholdTwo) { return(fullHousePoints); } } } } return(0); }; pointOptions.Add(new PointOption(fullHouseName, fullHouseCalculatePoints, fullHouseTextBeforePoints, false)); string kleineStraatName = "Kleine Straat"; string kleineStraatTextBeforePoints = kleineStraatName + " where " + kleineStraatAmountOfDiceThatHaveToIncrementallyIncreaseTheshold + " dice have to successively increase for a total of "; Func <int[], int> kleineStraatCalculatePoints = (int[] diceResults) => { for (int startOfStreetNumber = 1; startOfStreetNumber <= numberOfDiceSides - kleineStraatAmountOfDiceThatHaveToIncrementallyIncreaseTheshold + 1; startOfStreetNumber++) { bool isStreet = true; for (int increment = 0; increment < kleineStraatAmountOfDiceThatHaveToIncrementallyIncreaseTheshold; increment++) { bool incrementFound = false; for (int i = 0; i < diceResults.Length; i++) { if (diceResults[i] == startOfStreetNumber + increment) { incrementFound = true; break; } } if (incrementFound == false) { isStreet = false; break; } } if (isStreet == true) { return(kleineStraatPoints); } } return(0); }; pointOptions.Add(new PointOption(kleineStraatName, kleineStraatCalculatePoints, kleineStraatTextBeforePoints, false)); string grooteStraatName = "Grote Straat"; string grooteStraatTextBeforePoints = kleineStraatName + " where " + grooteStraatAmountOfDiceThatHaveToIncrementallyIncreaseTheshold + " dice have to successively increase for a total of "; Func <int[], int> grooteStraatCalculatePoints = (int[] diceResults) => { for (int startOfStreetNumber = 1; startOfStreetNumber <= numberOfDiceSides - grooteStraatAmountOfDiceThatHaveToIncrementallyIncreaseTheshold + 1; startOfStreetNumber++) { bool isStreet = true; for (int increment = 0; increment < grooteStraatAmountOfDiceThatHaveToIncrementallyIncreaseTheshold; increment++) { bool incrementFound = false; for (int i = 0; i < diceResults.Length; i++) { if (diceResults[i] == startOfStreetNumber + increment) { incrementFound = true; break; } } if (incrementFound == false) { isStreet = false; break; } } if (isStreet == true) { return(grooteStraatPoints); } } return(0); }; pointOptions.Add(new PointOption(grooteStraatName, grooteStraatCalculatePoints, grooteStraatTextBeforePoints, false)); string yahtzeeName = "Yahtzee"; string yahtzeeTextBeforePoints = yahtzeeName + " where " + yahtzeeAmountOfDiceWithSameNumberThreshold + " dice must be the same for a total yahtzee score of "; int amountOfTimesYahtzeeHasBeenTrown = 0; Func <int[], int> yahtzeeCalculatePoints = (int[] diceResults) => { for (int i = 1; i < numberOfDiceSides + 1; i++) { int amountOfDiceWithNumber = 0; for (int o = 0; o < diceResults.Length; o++) { if (diceResults[o] == i) { amountOfDiceWithNumber++; } } if (amountOfDiceWithNumber >= yahtzeeAmountOfDiceWithSameNumberThreshold) { int result = yahtzeePointsInitial + yahtzeePointsSuccessive * amountOfTimesYahtzeeHasBeenTrown; amountOfTimesYahtzeeHasBeenTrown++; return(result); } } return(0); }; pointOptions.Add(new PointOption(yahtzeeName, yahtzeeCalculatePoints, yahtzeeTextBeforePoints, true)); } }