Since you have a Type - which presumably is an enum - use that instead of "magic numbers" in your case statements:
tile.Type = (TileType)selectedTool;
switch (tile.Type)
{
case Empty:
tile.Image = null;
tile.Tag = 0;
break;
case Character:
tile.Image = Properties.Resources.Char;
tile.Tag = 1;
break;
case Wall:
tile.Image = Properties.Resources.Wall;
tile.Tag = 2;
break;
}
That makes your code both more reliable, and easier to read.
And when you pass a value to a method, it's a good idea to use it:
public static Image GetTypeImage(Type imageType)
{
switch (imageType)
{
case Empty:
tile.Image = null;
tile.Tag = 0;
break;
case Character:
tile.Image = Properties.Resources.Char;
tile.Tag = 1;
break;
case Wall:
tile.Image = Properties.Resources.Wall;
tile.Tag = 2;
break;
}
selectedTool = (int)tile.Tag;
return tile.Image;
}
You should probably also pass the Tile through to the method instead of teh Type, and use the Type value that contains.
It's also a very good idea to add a
default
to every switch:
default: throw new ArgumentException($"Unknown Type: {tile.Type}");
That way, if you forget an option in the
case
list, you get told about it - and if you add a Door type, it reminds you if you forget to add it to a
switch
.
On an unrelated basis: Doing a whole map with individual buttons is not a good idea - it may be easy for you, but the number of buttons you need to create gets silly, very quickly - a 10x10 map has 100, but a 50x50 has 2500 ... and most "interesting games" have pretty big maps. More Buttons equals more windows, equals worse performance / app or even system crashes because you start to run out of window handles. A much, much better idea is to draw your map manually onto a Panel in it's Paint event and do the click detection for yourself using the Panel.MouseClick event and the coordinates it gets passed.