Skip to content

Commit

Permalink
String Constant Mapping unecessary
Browse files Browse the repository at this point in the history
  • Loading branch information
VolkerWollmann committed Jul 24, 2020
1 parent 7f083be commit d4ba21c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 38 deletions.
2 changes: 1 addition & 1 deletion MyMasterMind/MyMasterMind/Commands/SelectColorCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public bool CanExecute(object parameter)

public void Execute(object parameter)
{
CodeField.SetColor(MyMasterMindConstants.GetCodeColor((string)parameter));
CodeField.SetColor((MyMasterMindCodeColors)parameter);
}

public SelectColorCommand(CodeField codeField )
Expand Down
13 changes: 7 additions & 6 deletions MyMasterMind/MyMasterMind/Controls/CodeField.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:MyMasterMind.Controls"
xmlns:constants="clr-namespace:MyMasterMind.Interfaces"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<StackPanel Name="CodeFieldStackPanel">
<StackPanel.ContextMenu>
<ContextMenu>
<MenuItem Header="Red" Background="Red" CommandParameter="RED" Command="{Binding SelectColorCommand, Mode=OneWay}"/>
<MenuItem Header="Green" Background="Green" CommandParameter="GREEN" Command="{Binding SelectColorCommand, Mode=OneWay}" />
<MenuItem Header="Blue" Background="Blue" CommandParameter="BLUE" Command="{Binding SelectColorCommand, Mode=OneWay}" />
<MenuItem Header="Yellow" Background="Yellow" CommandParameter="YELLOW" Command="{Binding SelectColorCommand, Mode=OneWay}" />
<MenuItem Header="Magenta" Background="Magenta" CommandParameter="MAGENTA" Command="{Binding SelectColorCommand, Mode=OneWay}" />
<MenuItem Header="Cyan" Background="Cyan" CommandParameter="CYAN" Command="{Binding SelectColorCommand, Mode=OneWay}" />
<MenuItem Header="Red" Background="Red" CommandParameter="{Binding Source={x:Static constants:MyMasterMindCodeColors.Red}}" Command="{Binding SelectColorCommand, Mode=OneWay}"/>
<MenuItem Header="Green" Background="Green" CommandParameter="{Binding Source={x:Static constants:MyMasterMindCodeColors.Green}}" Command="{Binding SelectColorCommand, Mode=OneWay}" />
<MenuItem Header="Blue" Background="Blue" CommandParameter="{Binding Source={x:Static constants:MyMasterMindCodeColors.Blue}}" Command="{Binding SelectColorCommand, Mode=OneWay}" />
<MenuItem Header="Yellow" Background="Yellow" CommandParameter="{Binding Source={x:Static constants:MyMasterMindCodeColors.Yellow}}" Command="{Binding SelectColorCommand, Mode=OneWay}" />
<MenuItem Header="Magenta" Background="Magenta" CommandParameter="{Binding Source={x:Static constants:MyMasterMindCodeColors.Magenta}}" Command="{Binding SelectColorCommand, Mode=OneWay}" />
<MenuItem Header="Cyan" Background="Cyan" CommandParameter="{Binding Source={x:Static constants:MyMasterMindCodeColors.Cyan}}" Command="{Binding SelectColorCommand, Mode=OneWay}" />
</ContextMenu>
</StackPanel.ContextMenu>
<Rectangle Name="CodeFieldRectangle" HorizontalAlignment="Left"
Expand Down
31 changes: 0 additions & 31 deletions MyMasterMind/MyMasterMind/Interfaces/MasterMindEnums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,36 +48,5 @@ public class MyMasterMindConstants
{
public const int CLOUMNS = 4;
public const int ROWS = 10;

public const string RED = "RED";
public const string GREEN = "GREEN";
public const string BLUE = "BLUE";
public const string YELLOW = "YELLOW";
public const string MAGENTA = "MAGENTA";
public const string CYAN = "CYAN";

private static readonly string[] COLORNAMES = { RED, GREEN, BLUE, YELLOW, MAGENTA, CYAN};

public static MyMasterMindCodeColors GetCodeColor(string color)
{
List<Tuple<string, MyMasterMindCodeColors>> mapping =
new List<Tuple<string, MyMasterMindCodeColors>>()
{
new Tuple<string, MyMasterMindCodeColors>( RED, MyMasterMindCodeColors.Red ),
new Tuple<string, MyMasterMindCodeColors>( GREEN, MyMasterMindCodeColors.Green ),
new Tuple<string, MyMasterMindCodeColors>( BLUE, MyMasterMindCodeColors.Blue ),
new Tuple<string, MyMasterMindCodeColors>( YELLOW, MyMasterMindCodeColors.Yellow ),
new Tuple<string, MyMasterMindCodeColors>( MAGENTA, MyMasterMindCodeColors.Magenta ),
new Tuple<string, MyMasterMindCodeColors>( CYAN, MyMasterMindCodeColors.Cyan ),

};

if (mapping.Any(m => (m.Item1 == color)))
{
return mapping.First(m => (m.Item1 == color)).Item2;
}

return MyMasterMindCodeColors.None;
}
}
}

0 comments on commit d4ba21c

Please sign in to comment.