public void HitShipReturnsResultOfShooting() { fleet Fleet = new fleet(); Fleet.addShip(new List <Square> { new Square(1, 4), new Square(1, 5), new Square(1, 6) }); Fleet.addShip(new List <Square> { new Square(4, 5), new Square(5, 5) }); var hit = Fleet.Hit(new Square(1, 4)); Assert.AreEqual(HitResult.Hit, hit); hit = Fleet.Hit(new Square(1, 5)); Assert.AreEqual(HitResult.Hit, hit); hit = Fleet.Hit(new Square(1, 6)); Assert.AreEqual(HitResult.Sunken, hit); hit = Fleet.Hit(new Square(1, 9)); Assert.AreEqual(HitResult.Missed, hit); hit = Fleet.Hit(new Square(4, 5)); Assert.AreEqual(HitResult.Hit, hit); hit = Fleet.Hit(new Square(5, 5)); Assert.AreEqual(HitResult.Sunken, hit); }
private void computerButtonGridClickHandler(Button clickedButton) { int x = 0, y = 0; foreach (var list in computerButtons) { if (list.IndexOf(clickedButton) != -1) { x = computerButtons.IndexOf(list); y = list.IndexOf(clickedButton); } } if (modelNmspc.HitResult.Hit == computerFleet.Hit(new modelNmspc.Square(x, y))) { clickedButton.BackColor = shipHitColor; clickedButton.Enabled = false; label3.Text = "Hit !"; return; } if (modelNmspc.HitResult.Sunken == computerFleet.Hit(new modelNmspc.Square(x, y))) { clickedButton.BackColor = shipSunkColor; clickedButton.Enabled = false; label3.Text = "You have sunk a ship!"; if (checkIfPlayerWon() == 1) { return; } ; disableComputerGridButtons(); displayMessageAndWaitForXSeconds(1); return; } clickedButton.BackColor = shipMissedColor; clickedButton.Enabled = false; label3.Text = "You missed :("; disableComputerGridButtons(); displayMessageAndWaitForXSeconds(0); }