//small and large straight static void CalculateStraight(SingleLine sl, int numsInRow) { //numsinrow= how many dices needs to be in a row for a straight //small = 4 digits in row //large = 5 digits in row List <int> numsList = new List <int>(); //make nums into list so Sort() can be used //not adding duplicate values to numslist, they are not needed for checking straight foreach (int i in nums) { bool exists = numsList.Exists(digit => digit == i); if (!exists) { numsList.Add(i); } } numsList.Sort(); //there has to be enough different values for a straight to be possible (longer the list more different numbers) if (numsList.Count < numsInRow) { sl.SetOtherPoints(false); return; } //if enough different values, proceed int count = 1; //how many values are in row (cant be zero there is always the first dice) for (int i = 1; i < numsList.Count; i++) { //the previuous value plus 1 should be same as current value if (numsList[i] == (numsList[i - 1] + 1)) { count++; } else if (count < numsInRow) {//if not, start from one count = 1; } } //if enough numbers in row, give points if (count >= numsInRow) { sl.SetOtherPoints(true); } else { sl.SetOtherPoints(false); } }
//Yatzy static void CalculateYatzy(SingleLine sl) { int digit = nums[0]; foreach (int i in nums) { if (i != digit) { sl.SetOtherPoints(false); return; } } sl.SetOtherPoints(true); }
//check the points in upper section and if bonus can be given void CheckUpperLine() { //upperPoints += line.points; if (upperPoints >= 63 && upperBonusLine.hasBeenPlayed == false) //so that the bonus points are not given mopre than once { upperBonusLine.SetOtherPoints(true); upperBonusLine.PlayThis(); GameManager.instance.playerInTurn.AddToPoints(upperBonusLine.points); } }
//full house static void CalculateFullHouse(SingleLine sl) { Dictionary <int, int> tempDict = new Dictionary <int, int>(); foreach (int i in nums) { if (tempDict.ContainsKey(i)) { tempDict[i] += 1; } else { tempDict.Add(i, 1); } } //checking if there is a 3x AND a pair, if yes, full house, else 0 points bool threeSame = false; bool pair = false; foreach (KeyValuePair <int, int> kvp in tempDict) { if (kvp.Value == 3) { threeSame = true; } if (kvp.Value == 2) { pair = true; } } if (threeSame && pair) { sl.SetOtherPoints(true); } else { sl.SetOtherPoints(false); } }