From 9c8807cb849ba5efe669e1708bca30f1af1e0590 Mon Sep 17 00:00:00 2001 From: Chris Sivert Sylte Date: Mon, 18 Aug 2025 15:58:11 +0200 Subject: [PATCH] multiplier should be working? --- csharp-scrabble-challenge.Main/Program.cs | 6 ++- csharp-scrabble-challenge.Main/Scrabble.cs | 61 +++++++++++++++++++--- 2 files changed, 58 insertions(+), 9 deletions(-) diff --git a/csharp-scrabble-challenge.Main/Program.cs b/csharp-scrabble-challenge.Main/Program.cs index 3751555..f0e1b84 100644 --- a/csharp-scrabble-challenge.Main/Program.cs +++ b/csharp-scrabble-challenge.Main/Program.cs @@ -1,2 +1,4 @@ -// See https://aka.ms/new-console-template for more information -Console.WriteLine("Hello, World!"); +using csharp_scrabble_challenge.Main; + +Scrabble scrabble = new Scrabble("OXyPHEnBUTaZoNE"); + diff --git a/csharp-scrabble-challenge.Main/Scrabble.cs b/csharp-scrabble-challenge.Main/Scrabble.cs index c1ea013..9b83760 100644 --- a/csharp-scrabble-challenge.Main/Scrabble.cs +++ b/csharp-scrabble-challenge.Main/Scrabble.cs @@ -8,16 +8,63 @@ namespace csharp_scrabble_challenge.Main { public class Scrabble +{ + static readonly Dictionary LetterValues = new Dictionary { - public Scrabble(string word) - { - //TODO: do something with the word variable - } + { 'A', 1 }, { 'B', 3 }, { 'C', 3 }, { 'D', 2 }, + { 'E', 1 }, { 'F', 4 }, { 'G', 2 }, { 'H', 4 }, + { 'I', 1 }, { 'J', 8 }, { 'K', 5 }, { 'L', 1 }, + { 'M', 3 }, { 'N', 1 }, { 'O', 1 }, { 'P', 3 }, + { 'Q', 10}, { 'R', 1 }, { 'S', 1 }, { 'T', 1 }, + { 'U', 1 }, { 'V', 4 }, { 'W', 4 }, { 'X', 8 }, + { 'Y', 4 }, { 'Z', 10} + }; + + private string word; + + public Scrabble(string word) + { + this.word = word; + score(); + } - public int score() + public int score() + { + int multiplyFactor; + int total = 0; + // Forces the letters to be uppercase + foreach (char c in word.ToUpper()) { - //TODO: score calculation code goes here - throw new NotImplementedException(); //TODO: Remove this line when the code has been written + // TryGetValue takes two parameters. (1) The key, or in this case the letter. + // (2) Out tries to store the value if that key or letter exists in the directory + if (LetterValues.TryGetValue(c, out int value)) + { + + // Janky way to add multiplier + multiplyFactor = 1; + + if (c == '{') { + multiplyFactor = 2; + } + + if (c == '}') { + multiplyFactor = 1; + } + + if (c == '[') { + multiplyFactor = 3; + } + + if (c == ']') { + multiplyFactor = 1; + } + + + total = total + value * multiplyFactor; + } } + Console.WriteLine(total); + return total; } } +}