public class Tile : Image
{
public TileType Type { get;}
public static int Size { get; set; }=32;
public double X {
get { return Canvas.GetLeft(this) / Width; }
set { Canvas.SetLeft(this, value * Width); }
}
public double Y
{
get { return Canvas.GetTop(this) / Height; }
set { Canvas.SetTop(this, value * Height); }
}
public Tile() {
Height = Size;
Width = Size;
Type=TileType.GrassA;
}
public Tile(double x, double y,TileType type) : this()
{
X = x;
Y = y;
Type=type;
ImageBrush brush = new ImageBrush();
brush.ImageSource = new BitmapImage(new Uri(GetImagePath(Type),UriKind.RelativeOrAbsolute));
Source = brush.ImageSource;
MouseLeftButtonDown += TileClicked;
}
public static string GetImagePath(TileType type)
{
switch(type)
{
case TileType.GrassA:
return "tile_0000.png";
case TileType.GrassB:
return "tile_0001.png";
case TileType.GrassC:
return "tile_0002.png";
default:
throw new ArgumentOutOfRangeException(nameof(type), type, null);
}
}
private void TileClicked(object sender, EventArgs e)
{
switch (Type)
{
case TileType.GrassA:
return;
case TileType.GrassB:
return;
case TileType.GrassC:
return;
}
}
}