Witam serdecznie,
Chcę wykonać planszę do gry w statki.
Mam klasę komórka:
class komórka
{
public int X { get; set; }
public int Y { get; set; }
public Rectangle Rect { get; private set; }
public bool active;
public komórka(int x, int y)
{
X = x;
Y = y;
Rect = new Rectangle();
Rect.Width = Rect.Height = 20;
if(active == true)
{
Rect.Fill = Brushes.Red;
} else if(active == false)
{
Rect.Fill = Brushes.Yellow;
}
}
}
oraz siatka:
class siatka
{
public komórka [,] mesh { get; private set; }
public Cell(int x, int y)
{
SetShip(x, y);
}
public void RedrawCells()
{
foreach(StructuralElement tmp in mesh)
{
Grid.SetColumn(tmp.Rect, tmp.X);
Grid.SetRow(tmp.Rect, tmp.Y);
if(tmp.active == true)
tmp.Rect.Fill = System.Windows.Media.Brushes.Red;
if (tmp.active == false)
tmp.Rect.Fill = System.Windows.Media.Brushes.Yellow;
}
}
public void SetShip(int x, int y)
{
mesh[x, y].active = true;
}
}
W konstruktorze klasy komórka brakuje utworzenia obiektu z "new"..
Jeżeli mesh był tworzony jako lista:
public List<komórka> mesh { get; private set; }
to odwoływałem się do niego poprzez:
mesh = new List<komórka>();
Ktoś mi podsunie w jaki sposób mogę zainicjować swoją tablicę obiektów?