From 89b786207e37e77aa76a771e669a1bb07d909d78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20Wullum?= Date: Wed, 8 Jan 2025 14:23:03 +0100 Subject: [PATCH] Finished Core and Extensions excercises. --- csharp-scrabble-challenge.Main/Scrabble.cs | 49 +++++++++++++++++++++- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/csharp-scrabble-challenge.Main/Scrabble.cs b/csharp-scrabble-challenge.Main/Scrabble.cs index c1ea013..2986bcb 100644 --- a/csharp-scrabble-challenge.Main/Scrabble.cs +++ b/csharp-scrabble-challenge.Main/Scrabble.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Reflection.Metadata.Ecma335; using System.Text; @@ -9,15 +10,59 @@ namespace csharp_scrabble_challenge.Main { public class Scrabble { + private int sum { get; set; } + + private static Dictionary letterScore = new Dictionary() + { + {'A', 1}, {'E', 1}, {'I', 1}, {'O', 1}, {'U', 1}, {'L', 1}, {'N', 1}, {'R', 1}, {'S', 1}, {'T', 1}, + {'D', 2}, {'G', 2}, + {'B', 3}, {'C', 3}, {'M', 3}, {'P', 3}, + {'F', 4}, {'H', 4}, {'V', 4}, {'W', 4}, {'Y', 4}, + {'K', 5}, + {'J', 8}, {'X', 8}, + {'Q', 10}, {'Z', 10} + }; + + public Scrabble(string word) - { + { //TODO: do something with the word variable + + int multiplier = 1; + + if (word == null) throw new ArgumentNullException(); + + foreach (char ch in word.ToUpper()) + { + switch (ch) + { + case '{': + multiplier = 2; + break; + case '}': + multiplier = 1; + break; + case '[': + multiplier = 3; + break; + case ']': + multiplier = 1; + break; + default: + if (letterScore.ContainsKey(ch)) { this.sum += letterScore[ch] * multiplier; } + break; + } + }; } + + public int score() { //TODO: score calculation code goes here - throw new NotImplementedException(); //TODO: Remove this line when the code has been written + //throw new NotImplementedException(); //TODO: Remove this line when the code has been written + return this.sum; } + } }