private ShotStatus TorpedoHit(BoardCoordinates torpedo) { ShotStatus shotStatus = ShotStatus.Miss; for (int i = 0; i < GameBoard.Ships.Count; i++) { var ship = GameBoard.Ships[i]; var boardCellStatus = (ShotTypes)Enum.Parse(typeof(ShotTypes), GameBoard.DisplayBoard[torpedo.Row, torpedo.Column]); if (CheckShipHit(ship, torpedo) && (boardCellStatus != ShotTypes.Hit && boardCellStatus != ShotTypes.Sink)) { if (ship.HitCount < ship.Size) { ship.HitCount++; } if (ship.HitCount == ship.Size) { ship.Sunk = true; shotStatus = ShotStatus.Sink; } else { shotStatus = ShotStatus.Hit; } } } return(shotStatus); }
public void shotResult(Position position, ShotStatus status) { Shots.Add(position, status); ConsoleGraphics.showShootedField(Shots, 90); string str = null; switch (status) { case ShotStatus.HIT: str = "Попадание"; break; case ShotStatus.MISS: str = "Промах"; break; case ShotStatus.SUNK: str = "Потопил"; break; } Console.WriteLine($"{position.getX()},{position.getY()} {str}"); Console.ReadLine(); }
public void DisplayShotStatus(ShotStatus shot) { switch (shot) { case ShotStatus.Victory: break; case ShotStatus.HitAndSunk: //HitAndSunkMessage(ShipType); Console.ReadKey(); break; case ShotStatus.Duplicate: //DuplicateMessage(); Console.ReadKey(); break; case ShotStatus.Hit: HitMessage(); Console.ReadKey(); break; case ShotStatus.Miss: MissMessage(); Console.ReadKey(); break; default: break; } }
/// <summary> /// Check if a ship is hit /// </summary> /// <param name="coordinate"></param> /// /// <param name="response"></param> private void CheckShipsForHit(Coordinate coordinate, FireShotResponse response) { response.ShotStatus = ShotStatus.Miss; ShotStatus status = Ships[0].FireAtShip(coordinate); switch (status) { case ShotStatus.HitAndSunk: response.ShotStatus = ShotStatus.HitAndSunk; response.ShipImpacted = Ships[0].ShipName; ShotHistory.Add(coordinate, Responses.ShotHistory.Hit); break; case ShotStatus.Hit: response.ShotStatus = ShotStatus.Hit; response.ShipImpacted = Ships[0].ShipName; ShotHistory.Add(coordinate, Responses.ShotHistory.Hit); break; } if (response.ShotStatus == ShotStatus.Miss) { ShotHistory.Add(coordinate, Responses.ShotHistory.Miss); } }
// What do I want the gameflow to do? // 1) Manages players turns (bool isp1Turn) // 2) Alternate FireShot () at enemy board // 3) Shot history and track board // 4) Check Coordinate() public void PlayGame(GameState state) { ShotStatus lastShot = ShotStatus.Invalid; /* * if (!state.IsPlayer1Turn) * { * ConsoleInput.WhoseTurn(state.P2); * } * else * { * ConsoleInput.WhoseTurn(state.P1); * } */ while (lastShot != ShotStatus.Victory) { ConsoleInput.DrawBoard(state); // prompt user for coordinate lastShot = FireShot(state); if (lastShot == ShotStatus.Duplicate || lastShot == ShotStatus.Invalid) { continue; } //ConsoleOutput.DrawBoard(state); state.IsPlayer1Turn = !state.IsPlayer1Turn; ConsoleOutput.ToNextTurn(); } }
public void ReceveStatus(ShotStatus shotStatus) { if (gameState == GameState.WaitOtherPlayerStatus && programState == ProgramState.game) { // View shot on field fieldEnemy.Shot(lastShotPos, shotStatus); // handle shot status here MessageBox.Show(shotStatus.ToString()); if (shotStatus == ShotStatus.miss) { setGameState(GameState.WaitOtherPlayerPos); } else if (shotStatus == ShotStatus.killEverybody) { MessageBox.Show("You win!"); setProgramState(ProgramState.end); } else { setGameState(GameState.WaitPlayerChoise); } } }
public static ShotStatus FireShotAtEnemey(Player player) { Coordinate coordToShoot = ConsoleInput.GetCoordinateFromUser(); ShotStatus returnvValue = player.board.FireShot(coordToShoot).ShotStatus; //use return returnValue istead of if else if (returnvValue == ShotStatus.Hit) { Console.WriteLine(ShotStatus.Hit); return(ShotStatus.Hit); } else if (returnvValue == ShotStatus.HitAndSunk) { Console.WriteLine(ShotStatus.HitAndSunk); return(ShotStatus.HitAndSunk); } else if (returnvValue == ShotStatus.Duplicate) { Console.WriteLine(ShotStatus.Duplicate); return(ShotStatus.Duplicate); } else if (returnvValue == ShotStatus.Miss) { Console.WriteLine(ShotStatus.Miss); return(ShotStatus.Miss); } else { return(ShotStatus.Victory); } }
private void CheckShipsForHit(Coordinates coordinate, FireShotResponse response) { response.ShotStatus = ShotStatus.Miss; foreach (var ship in Ships) { if (ship.IsSunk) { continue; } ShotStatus status = ship.FireAtShip(coordinate); switch (status) { case ShotStatus.Hit: response.ShotStatus = ShotStatus.Hit; response.ShipImpacted = ship.ShipName; ShotHistorys.Add(coordinate, ShotHistory.Hit); break; } if (status != ShotStatus.Miss) { break; } } if (response.ShotStatus == ShotStatus.Miss) { response.ShotStatus = ShotStatus.Miss; ShotHistorys.Add(coordinate, ShotHistory.Miss); } }
public TurnResult handleShot() { if (shotStatus != ShotStatus.none) { return(TurnResult.fail); } if (ship != null) { var result = ship.HandleShot(); shotStatus = ShotStatus.damagedShip; if (result == Ship.ShotResult.killed) { return(TurnResult.kill); } else { return(TurnResult.hit); } } else { shotStatus = ShotStatus.miss; return(TurnResult.miss); } }
// Visualize shot on enemy field public void Shot(Point pos, ShotStatus shotStatus) { if (player == Player.ally) { throw new ConstraintException("Can't view a shot on the ally field"); } FieldButtonState state; var buttonsPos = new List <Point>(); buttonsPos.Add(pos); if (shotStatus == ShotStatus.miss) { state = FieldButtonState.miss; } else if (shotStatus == ShotStatus.hurt) { state = FieldButtonState.hit; } else if (shotStatus == ShotStatus.kill || shotStatus == ShotStatus.killEverybody) { state = FieldButtonState.kill; FindComleteShip(buttonsPos); } else { state = FieldButtonState.blocked; } foreach (var p in buttonsPos) { getFB(p).setState(state); } }
public void GameStart() { string again = "y"; bool playAgain = true; while (playAgain == true) { ConsoleIO.DisplayTitle(); Players player1 = new Players(); setUpPlayer(player1); Players player2 = new Players(); setUpPlayer(player2); Random number = new Random(); ShotStatus shot = new ShotStatus(); int whoseTurn = number.Next(1, 2); while (shot != ShotStatus.Victory) { if (whoseTurn == 1) { ConsoleIO.PlayerBoard(player1, player2); shot = ConsoleIO.DisplayShot(player1); whoseTurn = 2; } else if (whoseTurn == 2) { ConsoleIO.PlayerBoard(player2, player1); shot = ConsoleIO.DisplayShot(player2); whoseTurn = 1; } } Console.Write("Wanna to play again? (y/n): "); again = Console.ReadLine(); if (again == "y") { playAgain = true; Console.Clear(); } else if (again == "n") { Console.Write("Thank you for playing!"); playAgain = false; Console.ReadKey(); } else { Console.Write("error message"); } } }
public void ReceveStatus(ShotStatus shotStatus) { var data = status + separator + ((int)shotStatus).ToString(); var msg = Encoding.ASCII.GetBytes(data); // Send the data through the socket. int bytesSent = sender.Send(msg); }
public void WhenShotItReturnsCorrectStatus(int remainingLife, ShotStatus expectedStatus) { var ship = new Ship(remainingLife); var shotStatus = ship.Shoot(); shotStatus.ShouldBe(expectedStatus); }
public void Start(Board b1, Board b2, Player[] playerArray) { int[] shot = new int[2]; FireShotResponse response = new FireShotResponse(); ResponseDisplayer ResponseWriter = new ResponseDisplayer(); setPlayers(playerArray); do { ShotStatus responseType = new ShotStatus(); if (TurnCounter % 2 == 0) { do { showShotHistory(player2, b1); shot = getUserShot(player2); response = firePlayerShot(shot, b1); Console.Clear(); showShotHistory(player2, b1); responseType = ResponseWriter.DisplayResponse(response); } while (responseType == ShotStatus.Invalid || responseType == ShotStatus.Duplicate); TurnCounter++; } else { do { showShotHistory(player1, b2); shot = getUserShot(player1); response = firePlayerShot(shot, b2); Console.Clear(); showShotHistory(player1, b2); responseType = ResponseWriter.DisplayResponse(response); } while (responseType == ShotStatus.Invalid || responseType == ShotStatus.Duplicate); TurnCounter++; } } while (response.ShotStatus != ShotStatus.Victory); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Game Over. Would you like to play again? (y/n)"); Console.ForegroundColor = ConsoleColor.Gray; string playagain = Console.ReadLine(); if (playagain == "y") { Console.Clear(); Program p = new Program(); p.playAgain(); } else { Console.WriteLine("Thanks for playing. Bye."); Thread.Sleep(3000); } }
private void ShotFailedOnFireEffectActive(ShotStatus status) { if (status != ShotStatus.FAILED) { return; } InterruptCoroutine(ref m_DecreaseSliderOnFireEffect); InterruptOnFireEffect(); }
public void Play() { var playerTurn = _setup.Player1GoesFirst; bool playOn = true; while (playOn) { ShotStatus status = new ShotStatus(); Console.Clear(); if (playerTurn) { status = FireShotPrompt(_setup.Player2Board, _setup.Player1Name); } else { status = FireShotPrompt(_setup.Player1Board, _setup.Player2Name); } if (status == ShotStatus.Invalid || status == ShotStatus.Duplicate) { playerTurn = !playerTurn; } playerTurn = !playerTurn; if (status != ShotStatus.Victory) { playOn = true; } else { playOn = false; Console.WriteLine("Press ENTER to play again or press Q to quit."); if (Console.ReadKey().Key == ConsoleKey.Q) { return; } else { SetupWorkflow restart = new SetupWorkflow(); restart.Start(); } } } }
private void SetThrowParameters(ShotStatus stauts) { if (stauts == ShotStatus.FAILED) { m_BallThrower.RepeatShot(); return; } ShotData currentThrowData = m_ShootingSpots[m_SpotsCounter].GetShotData(m_TrDestinationPoint.position); m_BallThrower.SetNextShot(currentThrowData); m_SpotsCounter = m_SpotsCounter + 1 <= m_ShootingSpots.Length - 1 ? m_SpotsCounter + 1 : 0; }
public void Start() { string Again = "y"; bool playagain = true; while (playagain) { ConsoleIO.Welcome(); Player player1 = new Player(); Player.setUpPlayer(player1); Player player2 = new Player(); Player.setUpPlayer(player2); ShotStatus shooting = new ShotStatus(); Random PlayerRandom = new Random(); int random = PlayerRandom.Next(1, 2); while (shooting != ShotStatus.Victory) { if (random == 1) { Player.PlayerBoard(player1, player2); shooting = Player.ShootShip(player2); random = 2; } else { Player.PlayerBoard(player2, player1); shooting = Player.ShootShip(player1); random = 1; } } Console.WriteLine("Want to play again? y or n"); Again = Console.ReadLine(); if (Again == "y") { playagain = true; } else { Console.WriteLine("Good Game!!!!"); } playagain = false; } }
private void CheckShipsForHit(Coordinate coordinate, FireShotResponse response) { response.ShotStatus = ShotStatus.Miss; foreach (var ship in _ships) { // no need to check sunk ships // *** next2 del if (ship == null) { continue; } if (ship.IsSunk) { continue; } ShotStatus status = ship.FireAtShip(coordinate); switch (status) { case ShotStatus.HitAndSunk: response.ShotStatus = ShotStatus.HitAndSunk; response.ShipImpacted = ship.ShipName; ShotHistory.Add(coordinate, Responses.ShotHistory.Hit); break; case ShotStatus.Hit: response.ShotStatus = ShotStatus.Hit; response.ShipImpacted = ship.ShipName; ShotHistory.Add(coordinate, Responses.ShotHistory.Hit); break; } // if they hit something, no need to continue looping if (status != ShotStatus.Miss) { break; } } if (response.ShotStatus == ShotStatus.Miss) { ShotHistory.Add(coordinate, Responses.ShotHistory.Miss); } }
public static void DisplayShot() { ShotStatus result = new ShotStatus(); FireShotResponse response = new FireShotResponse(); while (true) { Console.WriteLine("Place your fireshot. "); ConsoleIO.GetCoord(); switch (result) { case ShotStatus.Invalid: DisplayInvalid(); break; case ShotStatus.Duplicate: DisplayDuplicate(); break; case ShotStatus.Miss: DisplayMiss(); break; case ShotStatus.Hit: DisplayHit(); break; case ShotStatus.HitAndSunk: DisplayHitAndSunk(); break; case ShotStatus.Victory: DisplayVictory(); break; default: break; } Console.ReadKey(); } }
public void Update(ShotStatus status) { switch (status) { case ShotStatus.Victory: IsVictorious = true; ShotsHit++; break; case ShotStatus.Hit: case ShotStatus.HitAndSunk: ShotsHit++; break; case ShotStatus.Miss: ShotsMissed++; break; } }
private int GetScoreFromStatus(ShotStatus shotStauts) { if (shotStauts == ShotStatus.FAILED) { return(0); } if (shotStauts == ShotStatus.PERFECT) { return((int)Constant.ShotScores.PERFECT); } if (shotStauts == ((ShotStatus.BONUS | ShotStatus.NORMAL))) { return((int)BackBoardEntity.GetCurrentScoreBonus); } return((int)Constant.ShotScores.NORMAL); }
public GameFlow(Player Attacker, Player Receiver) { FireShotResponse ShotResponse; while (true) { ConsoleOutput.PromptPlayerTurn(Attacker); var shot = ConsoleInput.GetCoordinateFromUser(); ShotResponse = Receiver.PlayerBoard.FireShot(shot); ShotStatus result = ShotResponse.ShotStatus; string ShipHit = ShotResponse.ShipImpacted; if (result == ShotStatus.Miss) { ConsoleOutput.Miss(Attacker.Name); break; } else if (result == ShotStatus.Hit) { ConsoleOutput.Hit(Attacker.Name); break; } else if (result == ShotStatus.HitAndSunk) { ConsoleOutput.HitAndSunk(Attacker.Name, Receiver.Name, ShipHit); break; } else if (result == ShotStatus.Victory) { ConsoleOutput.DeclareVictory(Attacker.Name, Receiver.Name); GameOver = true; break; } else if (result == ShotStatus.Duplicate) { ConsoleOutput.Duplicate(Attacker.Name); } else { ConsoleOutput.InvalidShot(Attacker.Name); } } }
private ShotStatus FireShot(GameState state) { // ShipType ship = ShipType.Battleship; Board toFire = state.IsPlayer1Turn ? state.P2.PlayerBoard : state.P1.PlayerBoard; ShotStatus isVictory = ShotStatus.Miss; Coordinate FireAt = ConsoleInput.GetCoordinate(); FireShotResponse response = toFire.FireShot(FireAt); switch (response.ShotStatus) { case ShotStatus.Invalid: ConsoleOutput.IvalidResponse(); isVictory = ShotStatus.Invalid; return(isVictory); case ShotStatus.Duplicate: ConsoleOutput.DuplicateResponse(); isVictory = ShotStatus.Duplicate; return(isVictory); case ShotStatus.Hit: ConsoleOutput.HitResponse(); isVictory = ShotStatus.Hit; return(isVictory); case ShotStatus.HitAndSunk: ConsoleOutput.HitAndSunkResponse(response.ShipImpacted); isVictory = ShotStatus.HitAndSunk; return(isVictory); case ShotStatus.Miss: ConsoleOutput.MissResponse(); isVictory = ShotStatus.Miss; return(isVictory); case ShotStatus.Victory: ConsoleOutput.VictoryResponse(); isVictory = ShotStatus.Victory; return(isVictory); } return(isVictory); }
public bool DisplayFireShotResponse(ShotStatus currentShot, FireShotResponse shotResponse) { if (currentShot == ShotStatus.Invalid) { Console.WriteLine("Your coordinate is invalid"); return(false); } else if (currentShot == ShotStatus.Duplicate) { Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("You have already fired at that coordinate {0} \nplease enter another coordinate:", WorkFlow.OtherPlayer.PlayerName); Console.ResetColor(); return(false); } else if (currentShot == ShotStatus.Miss) { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("You have missed!"); Console.ResetColor(); return(true); } else if (currentShot == ShotStatus.Hit) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("You have landed at hit!!"); Console.ResetColor(); return(true); } else if (currentShot == ShotStatus.HitAndSunk) { Console.WriteLine("You have hit and sunk the {0}!", shotResponse.ShipImpacted); return(true); } else if (currentShot == ShotStatus.Victory) { Console.WriteLine("VICTORY!!!"); Console.ReadKey(); StartGame(); } return(true); }
public void DisplayShotResult(ShotStatus shotResult) { switch (shotResult) { case ShotStatus.Hit: _output.WriteLine("HIT!"); break; case ShotStatus.Miss: _output.WriteLine("Miss :("); break; case ShotStatus.Repeated: _output.WriteLine("This square was already shot"); break; case ShotStatus.Sink: _output.WriteLine("Ship sinked!"); break; } }
public void HandlePlayerTurn() { ShotStatus status = ShotStatus.Invalid; while (status != ShotStatus.Victory) { for (int i = 0; i < 2; i++) { if (i == 0) { status = TakeTurn(p1, p2); } else { status = TakeTurn(p2, p1); } if (status == ShotStatus.Victory) { break; } } } }
public void shotResult(Position position, ShotStatus status) { }
public void Run() { Output output = new Output(); Input input = new Input(); Board board1 = new Board(); Board board2 = new Board(); PlaceShipRequest shipRequest = new PlaceShipRequest(); PlaceShipRequest shipRequest2 = new PlaceShipRequest(); char Winner = 'n'; output.StartScreen(); if (input.Play()) { output.AskName1(); string P1 = input.GetName1(); output.AskName2(); string P2 = input.GetName2(); // player 1 place ships output.CreateBoard1(); output.ShowBoard1(); while (true) { output.PlaceBattleship(P1); var valuesB = input.GetCoordinate(); int x = valuesB.Item1; int y = valuesB.Item2; output.ShipDirection(); ShipDirection direction = input.ShipPlacement(); Coordinate coordinate = new Coordinate(x, y); shipRequest.Coordinate = coordinate; shipRequest.Direction = direction; shipRequest.ShipType = ShipType.Battleship; if (board1.PlaceShip(shipRequest) != ShipPlacement.Ok) { output.InvalidEntry(); } else { break; } } while (true) { output.PlaceCarrier(P1); var valuesC = input.GetCoordinate(); int x = valuesC.Item1; int y = valuesC.Item2; output.ShipDirection(); ShipDirection direction = input.ShipPlacement(); Coordinate coordinate = new Coordinate(x, y); shipRequest.Coordinate = coordinate; shipRequest.Direction = direction; shipRequest.ShipType = ShipType.Carrier; if (board1.PlaceShip(shipRequest) != ShipPlacement.Ok) { output.InvalidEntry(); } else { break; } } while (true) { output.PlaceCruiser(P1); var valuesCr = input.GetCoordinate(); int x = valuesCr.Item1; int y = valuesCr.Item2; output.ShipDirection(); ShipDirection direction = input.ShipPlacement(); Coordinate coordinate = new Coordinate(x, y); shipRequest.Coordinate = coordinate; shipRequest.Direction = direction; shipRequest.ShipType = ShipType.Cruiser; if (board1.PlaceShip(shipRequest) != ShipPlacement.Ok) { output.InvalidEntry(); } else { break; } } while (true) { output.PlaceDestroyer(P1); var valuesD = input.GetCoordinate(); int x = valuesD.Item1; int y = valuesD.Item2; output.ShipDirection(); ShipDirection direction = input.ShipPlacement(); Coordinate coordinate = new Coordinate(x, y); shipRequest.Coordinate = coordinate; shipRequest.Direction = direction; shipRequest.ShipType = ShipType.Destroyer; if (board1.PlaceShip(shipRequest) != ShipPlacement.Ok) { output.InvalidEntry(); } else { break; } } while (true) { output.PlaceSubmarine(P1); var valuesS = input.GetCoordinate(); int x = valuesS.Item1; int y = valuesS.Item2; output.ShipDirection(); ShipDirection direction = input.ShipPlacement(); Coordinate coordinate = new Coordinate(x, y); shipRequest.Coordinate = coordinate; shipRequest.Direction = direction; shipRequest.ShipType = ShipType.Submarine; if (board1.PlaceShip(shipRequest) != ShipPlacement.Ok) { output.InvalidEntry(); } else { break; } } output.ChangeTurns(P1, P2); //player 2 place ships output.CreateBoard2(); output.ShowBoard2(); while (true) { output.PlaceBattleship(P2); var valuesB = input.GetCoordinate(); int x = valuesB.Item1; int y = valuesB.Item2; output.ShipDirection(); ShipDirection direction = input.ShipPlacement(); Coordinate coordinate = new Coordinate(x, y); shipRequest2.Coordinate = coordinate; shipRequest2.Direction = direction; shipRequest2.ShipType = ShipType.Battleship; if (board2.PlaceShip(shipRequest2) != ShipPlacement.Ok) { output.InvalidEntry(); } else { break; } } while (true) { output.PlaceCarrier(P2); var valuesC = input.GetCoordinate(); int x = valuesC.Item1; int y = valuesC.Item2; output.ShipDirection(); ShipDirection direction = input.ShipPlacement(); Coordinate coordinate = new Coordinate(x, y); shipRequest2.Coordinate = coordinate; shipRequest2.Direction = direction; shipRequest2.ShipType = ShipType.Carrier; if (board2.PlaceShip(shipRequest2) != ShipPlacement.Ok) { output.InvalidEntry(); } else { break; } } while (true) { output.PlaceCruiser(P2); var valuesCr = input.GetCoordinate(); int x = valuesCr.Item1; int y = valuesCr.Item2; output.ShipDirection(); ShipDirection direction = input.ShipPlacement(); Coordinate coordinate = new Coordinate(x, y); shipRequest2.Coordinate = coordinate; shipRequest2.Direction = direction; shipRequest2.ShipType = ShipType.Cruiser; if (board2.PlaceShip(shipRequest2) != ShipPlacement.Ok) { output.InvalidEntry(); } else { break; } } while (true) { output.PlaceDestroyer(P2); var valuesD = input.GetCoordinate(); int x = valuesD.Item1; int y = valuesD.Item2; output.ShipDirection(); ShipDirection direction = input.ShipPlacement(); Coordinate coordinate = new Coordinate(x, y); shipRequest2.Coordinate = coordinate; shipRequest2.Direction = direction; shipRequest2.ShipType = ShipType.Destroyer; if (board2.PlaceShip(shipRequest2) != ShipPlacement.Ok) { output.InvalidEntry(); } else { break; } } while (true) { output.PlaceSubmarine(P2); var valuesS = input.GetCoordinate(); int x = valuesS.Item1; int y = valuesS.Item2; output.ShipDirection(); ShipDirection direction = input.ShipPlacement(); Coordinate coordinate = new Coordinate(x, y); shipRequest2.Coordinate = coordinate; shipRequest2.Direction = direction; shipRequest2.ShipType = ShipType.Submarine; if (board2.PlaceShip(shipRequest2) != ShipPlacement.Ok) { output.InvalidEntry(); } else { break; } } output.ChangeTurns(P2, P1); Random random = new Random(); int order = random.Next(1, 10); if (order % 2 == 0) //PLAYER 1 GOES FIRST { output.InitiateGame(P1); while (Winner != 'y') { while (true) { output.ShowBoard1(); output.AskCoordinates(P1); var values = input.GetCoordinate(); int x = values.Item1; int y = values.Item2; Coordinate coordinate = new Coordinate(x, y); var shot = board2.FireShot(coordinate); ShotStatus shotStatus = shot.ShotStatus; string ship = shot.ShipImpacted; if (shotStatus == ShotStatus.Hit) { output.Hit(); output.gameBoard1[y - 1, x - 1] = 'H'; break; } else if (shotStatus == ShotStatus.Miss) { output.Miss(); output.gameBoard1[y - 1, x - 1] = 'M'; break; } else if (shotStatus == ShotStatus.HitAndSunk) { output.HitAndSink(ship); output.gameBoard1[y - 1, x - 1] = 'H'; break; } else if (shotStatus == ShotStatus.Victory) { output.Victory(P1); output.gameBoard1[y - 1, x - 1] = 'H'; Winner = 'y'; break; } } output.ChangeTurns(P1, P2); while (true) { output.ShowBoard2(); output.AskCoordinates(P2); var values2 = input.GetCoordinate(); int x2 = values2.Item1; int y2 = values2.Item2; Coordinate coordinate2 = new Coordinate(x2, y2); var shot2 = board1.FireShot(coordinate2); ShotStatus shotStatus2 = shot2.ShotStatus; string ship2 = shot2.ShipImpacted; if (shotStatus2 == ShotStatus.Hit) { output.Hit(); output.gameBoard2[y2 - 1, x2 - 1] = 'H'; break; } else if (shotStatus2 == ShotStatus.Miss) { output.Miss(); output.gameBoard2[y2 - 1, x2 - 1] = 'M'; break; } else if (shotStatus2 == ShotStatus.HitAndSunk) { output.HitAndSink(ship2); output.gameBoard2[y2 - 1, x2 - 1] = 'H'; break; } else if (shotStatus2 == ShotStatus.Victory) { output.Victory(P2); Winner = 'y'; break; } else { output.InvalidEntry(); } output.ChangeTurns(P2, P1); } } } else // PLAYER 2 GOES FIRST { while (Winner != 'y') { while (true) { output.InitiateGame(P2); output.ShowBoard2(); output.AskCoordinates(P2); var values = input.GetCoordinate(); int x = values.Item1; int y = values.Item2; Coordinate coordinate = new Coordinate(x, y); var shot = board1.FireShot(coordinate); ShotStatus shotStatus = shot.ShotStatus; string ship = shot.ShipImpacted; if (shotStatus == ShotStatus.Hit) { output.Hit(); output.gameBoard2[y - 1, x - 1] = 'H'; break; } else if (shotStatus == ShotStatus.Miss) { output.Miss(); output.gameBoard2[y - 1, x - 1] = 'M'; break; } else if (shotStatus == ShotStatus.HitAndSunk) { output.HitAndSink(ship); output.gameBoard2[y - 1, x - 1] = 'H'; break; } else if (shotStatus == ShotStatus.Victory) { output.Victory(P2); Winner = 'y'; break; } } output.ChangeTurns(P2, P1); while (true) { output.ShowBoard1(); output.AskCoordinates(P1); var values2 = input.GetCoordinate(); int x2 = values2.Item1; int y2 = values2.Item2; Coordinate coordinate2 = new Coordinate(x2, y2); var shot2 = board2.FireShot(coordinate2); ShotStatus shotStatus2 = shot2.ShotStatus; string ship2 = shot2.ShipImpacted; if (shotStatus2 == ShotStatus.Hit) { output.Hit(); output.gameBoard1[y2 - 1, x2 - 1] = 'H'; break; } else if (shotStatus2 == ShotStatus.Miss) { output.Miss(); output.gameBoard1[y2 - 1, x2 - 1] = 'M'; break; } else if (shotStatus2 == ShotStatus.HitAndSunk) { output.HitAndSink(ship2); output.gameBoard1[y2 - 1, x2 - 1] = 'H'; break; } else if (shotStatus2 == ShotStatus.Victory) { output.Victory(P1); Winner = 'y'; break; } else { output.InvalidEntry(); } } output.ChangeTurns(P1, P2); } } } else { output.ExitGame(); } Console.ReadLine(); }
protected void CallThrowerReady(ShotStatus status) { CallEvent(OnThrowEntityReady, status); }