public void NewGame() { p1.Reset(); p2.Reset(); grid.ColumnDefinitions.Clear(); grid.Children.Clear(); grid.RowDefinitions.Clear(); //Simple Game this.game = new Game(p1, p2); this.buttonGrid = new GridButton[3, 3]; //Create rows, columns for (int i = 0; i < 3; i++) { grid.ColumnDefinitions.Add(new ColumnDefinition()); } for (int i = 0; i < 3; i++) { grid.RowDefinitions.Add(new RowDefinition()); } //Create buttons for (int r = 0; r < 3; r++) { for (int c = 0; c < 3; c++) { var info = new ButtonInfo(r, c); GridButton button = new GridButton(); button.SetValue(Grid.RowProperty, r); button.SetValue(Grid.ColumnProperty, c); button.InitializeButton(info); grid.Children.Add(button); buttonGrid[r, c] = button; } } //Set Handlers GridButton.SetHandlers( OnClick, () => game.CurrentPlayerToken); UpdateGameState(game.GetState()); }