From 44bab193613b47b354b3a72faf2ef47bac4d8e5b Mon Sep 17 00:00:00 2001 From: OliBomby Date: Fri, 9 Dec 2022 00:14:41 +0100 Subject: [PATCH] fix illegal letters crashing the program --- SpellCastSolverLib/LetterState.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/SpellCastSolverLib/LetterState.cs b/SpellCastSolverLib/LetterState.cs index 1dffde0..492d8b3 100644 --- a/SpellCastSolverLib/LetterState.cs +++ b/SpellCastSolverLib/LetterState.cs @@ -6,8 +6,7 @@ public class LetterState public int PointsMultiplier; public int Multiplier; public bool Gem; - - public int Points => LetterPoints[char.ToLower(Letter)]; + public readonly int Points; public LetterState(char letter, int pointsMultiplier = 1, int multiplier = 1, bool gem = false) { @@ -15,6 +14,12 @@ public LetterState(char letter, int pointsMultiplier = 1, int multiplier = 1, bo PointsMultiplier = pointsMultiplier; Multiplier = multiplier; Gem = gem; + Points = GetPoints(letter); + } + + public static int GetPoints(char letter) + { + return LetterPoints.ContainsKey(char.ToLower(letter)) ? LetterPoints[char.ToLower(letter)] : 0; } public static readonly Dictionary LetterPoints = new() {