public static Grid CreateGameGrid(GameController controller, Cell[,] game) { Grid grid = new Grid(); int createdColumns = 0; for (int row = 0; row < game.GetLength(0); row++) { grid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(25, GridUnitType.Pixel) }); for (int column = 0; column < game.GetLength(1); column++) { // Create columns only once if (createdColumns < game.GetLength(1)) { grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(25, GridUnitType.Pixel) }); createdColumns++; } // Create cell controls CellControl cell = new CellControl(controller, game[row, column]); Grid.SetRow(cell, row); Grid.SetColumn(cell, column); grid.Children.Add(cell); } } return grid; }
public MainViewModel() { StartCommand = new DelegateCommand((obj) => StartGame()); OpenSettingsCommand = new DelegateCommand((obj) => OpenSettings(), (obj) => settingsWindow == null); OpenStatisticsCommand = new DelegateCommand((obj) => OpenStatistics(), (obj) => statisticsWindow == null); LoadStatistics(); Settings = new GameSettings(); TimerService = new TimerService(); Controller = new GameController(); Controller.FirstStep += HandleFirstStep; Controller.GameOver += HandleGameOver; Controller.GameWon += HandleGameWon; CreateNewGame(); }