I have to do some sort of game with WPF App that contain some matrix of color boxes (ex. 10x10). On-click at some it must eliminate itself and surrounding boxes with the same color if there are more than 3, and after elimination these boxes grant some random color.
I'm fairly new in WPF apps, but I have some knowledge of C# Programming and I can't figure out from where I should start. Most difficult part for me is "spawning" this boxes and use it like a matrix.
So far I found some project that I thought it will help me, but not really.
Can someone navigate from where I can start and which is most relevant way to do this.
Thank you.
ItemsControl + UniformGrid as a Panel is a good choice to display a matrix
view
code-behind
public partial class MainWindow : Window { List _board; public MainWindow() { InitializeComponent(); int rows = 10; int columns = 10; _board = new List(); for(int r = 0; r
you can create and use more complex type instead of Point and improve ItemTemplate to continue development. current ItemTemplate is nothing more that a rectangle
I used code-behind for demonstration, but in wpf MVVM in a preferred approach
EDIT extended example
in most cases you don't have to work with UI elements directly
to support different Colors I will create a custom class
public class MatrixElement { private string _color; public MatrixElement(int x, int y) { X = x; Y = y; } public int X { get; private set; } public int Y { get; private set; } public string Color { get { return _color; } set { _color = value; if (ColorChanged != null) ColorChanged(this, EventArgs.Empty); } } public event EventHandler ColorChanged; }
window code has changed accordingly
List _board; public MainWindow() { InitializeComponent(); int rows = 10; int columns = 10; _board = new List(); for (int r = 0; r
ItemTemplate was modified a bit