public void resetShips(ShipMenu shipMenu) { control.initArray(); this.shipmenu = shipMenu; for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { cells[i, j].rectangle.Fill = Brushes.LightBlue; } } }
private void HandleChildEvent(object sender, RoutedEventArgs e) { Button b = e.OriginalSource as Button; m = this.DataContext as MainWindowViewModel; if (b.Name.Equals("new")) { shipmenu = new ShipMenu(); bv = new BoardView(shipmenu); bvm = bv.DataContext as BoardViewModel; m.Menu = shipmenu; m.Content = bv; builder = new BattleshipBuilder(bvm, new Player(), new Player(), State.PLACE_BOAT_STATE); } else if (b.Name.Equals("load")) { loadGameView = new LoadGameView(); m.Content = loadGameView; m.Menu = new LoadGameMenuView(); } else if (b.Name.Equals("next")) { builder.progressGame(); if (builder.CurrentState == State.PLACE_BOAT_STATE) { shipmenu = new ShipMenu(); bv.resetShips(shipmenu); m.Menu = shipmenu; } else if (builder.CurrentState == State.GAME_STATE) { bv.resetBoard(); m.Menu = new GameMenu(); } this.Title = builder.getPlayer(); } else if (b.Name.Equals("nextPlayer")) { builder.progressGame(); this.Title = builder.getPlayer(); } else if (b.Name.Equals("saveGame")) { SavedGame save = new SavedGame("title", builder.Player1, builder.Player2); save.Save(); } else if (b.Name.Equals("startLoadedGame")) { LoadGameViewModel loadViewModel = loadGameView.DataContext as LoadGameViewModel; SavedGame game = loadViewModel.getSelectedGame(); if (shipmenu == null) { shipmenu = new ShipMenu(); bv = new BoardView(shipmenu); } bvm = bv.DataContext as BoardViewModel; m.Menu = new GameMenu(); m.Content = bv; // bvm.modelChanged(game.Player1.TargetBoard); builder = new BattleshipBuilder(bvm, game.Player1, game.Player2, State.GAME_STATE); } else if (b.Name.Equals("exitGame")) { m.Content = null; m.Menu = new MainMenu(); } else if (b.Name.Equals("goBack")) { m.Content = null; m.Menu = new MainMenu(); } e.Handled = true; }
public BoardView(ShipMenu shipmenu) { this.shipmenu = shipmenu; InitializeComponent(); }