public void TestShootInPlaceBoatsState() { Player player1 = new TestPlayer(); Player player2 = new TestPlayer(); BattleshipBuilder game = new BattleshipBuilder(new ModelHolderImpl(), player1, player2); game.progressGame(); int didTakeShoot = game.Shoot(0, 0); Assert.AreEqual(-1, didTakeShoot); }
public void TestMiss() { Player player1 = new TestPlayer(); Player player2 = new TestPlayer(); BattleshipBuilder game = new BattleshipBuilder(new ModelHolderImpl(), player1, player2); game.progressGame(); game.progressGame(); int didTakeShoot = game.Shoot(0, 1); Assert.AreEqual(BoardConstants.miss, didTakeShoot); }
public void TestTwoShotsDuringOneTurn() { Player player1 = new TestPlayer(); Player player2 = new TestPlayer(); BattleshipBuilder game = new BattleshipBuilder(new ModelHolderImpl(), player1, player2); game.progressGame(); game.progressGame(); int didTakeShoot = game.Shoot(0, 0); Assert.AreEqual(BoardConstants.hit, didTakeShoot); didTakeShoot = game.Shoot(1, 0); Assert.AreEqual(-1, didTakeShoot); }
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; }