I am trying to make a chessgame in c# WPF. I have miltiple classes, one for every kind of chesspiece and they all implement the same interface. All pieces objects are stored in a 2d array of type object[,] (of which have a feeling it's not the right way). I want to loop through this array to draw every corresponding image by calling Board[x, y].ImgURI but i get:
CS1061 'object' does not contain a definition for 'ImgURI' and no accessible extension method 'ImgURI' accepting a first argument of type 'object' could be found
class Rook : Igamepiece{...}
class King : Igamepiece{...}
class Queen : Igamepiece{...}
interface Igamepiece{
public string ImgURI { get; set; } //property that holds the image Uri
}
class Main{
public object[,] Board = new object[8, 8]; //array containing objects of different types
for (int y = 0; y < Board.GetLength(0); y++)
{
for (int x = 0; x < Board.GetLength(1); x++)
{
GameArea.Children.Add(new Image
{
Source = new BitmapImage(new Uri(Board[x, y].ImgURI, UriKind.Relative)),
Width = SquareSize,
Height = SquareSize,
Margin = new Thickness(nextX, nextY, 0, 0)
});
nextX += SquareSize;
}
nextX = 0;
nextY += SquareSize;
}
}