Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions csharp-scrabble-challenge.Main/Program.cs
Original file line number Diff line number Diff line change
@@ -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");

61 changes: 54 additions & 7 deletions csharp-scrabble-challenge.Main/Scrabble.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,63 @@
namespace csharp_scrabble_challenge.Main
{
public class Scrabble
{
static readonly Dictionary<char, int> LetterValues = new Dictionary<char, int>
{
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;
}
}
}
Loading