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
18 changes: 16 additions & 2 deletions csharp-scrabble-challenge.Main/Program.cs
Original file line number Diff line number Diff line change
@@ -1,2 +1,16 @@
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");
using csharp_scrabble_challenge.Main;

class Program
{
static void Main(string[] args)
{
Console.WriteLine("Welcome to Scrabble!\n");
Console.WriteLine("Try putting in a word:\n");

string? input = Console.ReadLine();

Scrabble scrabble = new Scrabble(input);

Check warning on line 12 in csharp-scrabble-challenge.Main/Program.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'word' in 'Scrabble.Scrabble(string word)'.

Check warning on line 12 in csharp-scrabble-challenge.Main/Program.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'word' in 'Scrabble.Scrabble(string word)'.

Check warning on line 12 in csharp-scrabble-challenge.Main/Program.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'word' in 'Scrabble.Scrabble(string word)'.

Check warning on line 12 in csharp-scrabble-challenge.Main/Program.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'word' in 'Scrabble.Scrabble(string word)'.
scrabble.score();
}
}

54 changes: 50 additions & 4 deletions csharp-scrabble-challenge.Main/Scrabble.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,67 @@
using System.Linq;
using System.Reflection.Metadata.Ecma335;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace csharp_scrabble_challenge.Main
{
public class Scrabble
{

private string _word;
private int modifier = 1;

Dictionary<char, int> scores = new Dictionary<char, int>()
{
{'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
{
_word = word.Trim().ToLower();

if (_word.StartsWith("[") && _word.EndsWith("]"))
{
_word = _word.Remove(0, 1);
_word = _word.Remove(_word.Length - 1);
modifier = 3;
}
else if (_word.StartsWith("{") && _word.EndsWith("}"))
{
_word =_word.Remove(0, 1);
_word = _word.Remove(_word.Length - 1);
modifier = 2;
}
}

public int score()
{
//TODO: score calculation code goes here
throw new NotImplementedException(); //TODO: Remove this line when the code has been written

int totalScore = 0;
Dictionary<char, int> counts = new Dictionary<char, int>();

foreach (char c in _word)
{
if (scores.ContainsKey(c))
{
totalScore += scores[c];
}
}

foreach (KeyValuePair<char, int> kvp in counts)
{
Console.WriteLine($"{kvp.Key}: {kvp.Value}");
}

Console.WriteLine($"\nYour total score for this word is: {totalScore}");
return totalScore * modifier;
}
}
}
Loading