private async void ValueOfAKind(YatzyScoreType type, int value, string name) { int score = GetItemScoreByType(type); if (_rollCount > 0 && score == 0) { int total = _calculate.GetOfAKind(ref _dice, value - 1); if (total != 0) { bool result = await _confirm($"Total is {total}. {accept}"); if (result) { SetItemScoreByType(type, total); _calculate.UpdateTotals(total, false); Reset(); } } else { bool result = await _confirm($"No {name} of a Kind. {accept}"); if (result) { SetItemScoreByType(type, 0); _calculate.UpdateTotals(total, false); Reset(); } } } }
private void SetItemScoreByType(YatzyScoreType type, int score) { YatzyItem item = GetItemByType(type); if (item != null) { item.Score = score; } }
private int GetItemScoreByType(YatzyScoreType type) { YatzyItem item = GetItemByType(type); if (item != null) { return(item.Score); } return(0); }
private async void AddUpDice(YatzyScoreType type, int value) { int score = GetItemScoreByType(type); if (_rollCount > 0 && score == 0) { int total = _calculate.GetAddUp(ref _dice, value); bool result = await _confirm($"Total is {total}. {accept}"); if (result) { SetItemScoreByType(type, total); _calculate.UpdateTotals(total, true); Reset(); } } }
private async void ItemScore(YatzyScoreType type, int value, string name) { int score = GetItemScoreByType(type); if ((_rollCount > 0) && (score == 0)) { int total = 0; if (type == YatzyScoreType.FullHouseScore) { total = _calculate.GetFullHouse(ref _dice); } else if (type == YatzyScoreType.SmallStraightScore) { total = _calculate.GetSmallStraight(ref _dice); } else if (type == YatzyScoreType.LargeStraightScore) { total = _calculate.GetLargeStraight(ref _dice); } if (total == value) { SetItemScoreByType(type, total); _calculate.UpdateTotals(total, false); Reset(); } else { bool result = await _confirm($"No {name}. {accept}"); if (result) { SetItemScoreByType(type, 0); _calculate.UpdateTotals(total, false); Reset(); } } } }
private YatzyItem GetItemByType(YatzyScoreType type) { return(_items.FirstOrDefault(t => t.Type == type)); }