public void ConvertInputToCoordinates(string input, ref PlayerShot playerShot) { int x = input[0] % 32; int y = (int)char.GetNumericValue(input[1]); playerShot.coordinateX = x; playerShot.CoordinateY = y; }
public void ShipIsHitted(PlayerShot playerShot, Ship ship, char[,] gameOnGrid, char shipSymbol) { if (ship.health > 0 && ship.health < this.health) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("You hit the ship\r\n"); gameOnGrid[playerShot.CoordinateX, playerShot.CoordinateY] = shipSymbol; ship.Health -= 20; Console.ForegroundColor = ConsoleColor.White; } }
public void UpdateGrid(PlayerShot playerShot) { IList <Ship> createShips = Ship.InstanceOfShip.CreateShips(); var shotX = playerShot.CoordinateX; var shotY = playerShot.CoordinateY; if (shotX == 0) { shotX = shipGrid.GetLength(0) - 1; } if (shotY == 0) { shotY = shipGrid.GetLength(1) - 1; } if (shipGrid[shotX, shotY] == this.shipSymbol && gameOnGrid[shotX, shotY] != this.shipSymbol) { gameOnGrid = playerShot.SuccessfullyShot(shotX, shotY, gameOnGrid, this.shipSymbol); int battleshipRow, battleshipCol, destroyer1Row, destroyer1Col, destroyer2Row, destroyer2Col; battleshipRow = createShips[0].CoordinateX; battleshipCol = createShips[0].CoordinateY; destroyer1Row = createShips[1].CoordinateX; destroyer1Col = createShips[1].CoordinateY; destroyer2Row = createShips[2].CoordinateX; destroyer2Col = createShips[2].CoordinateY; bool isBattleship = gameOnGrid[battleshipRow, battleshipCol] == this.shipSymbol; bool isDestroyer1 = gameOnGrid[destroyer1Row, destroyer1Col] == this.shipSymbol; bool isDestroyer2 = gameOnGrid[destroyer2Row, destroyer2Col] == this.shipSymbol; bool isBattleshipSunk = Validation.InstanceOfValidation.IsBattleshipSunk(gameOnGrid, battleshipRow, battleshipCol); bool isDestroyer1HullHorizontal = Validation.InstanceOfValidation.IsDestroyerHullHorizontal(gameOnGrid, destroyer1Row, destroyer1Col); bool isDestroyer2HullHorizontal = Validation.InstanceOfValidation.IsDestroyerHullHorizontal(gameOnGrid, destroyer2Row, destroyer2Col); bool isDestroyer1HullVertical = Validation.InstanceOfValidation.IsDestroyerHullVertical(gameOnGrid, destroyer1Row, destroyer1Col); bool isDestroyer2HullVertical = Validation.InstanceOfValidation.IsDestroyerHullVertical(gameOnGrid, destroyer2Row, destroyer2Col); bool isDestroyer1Sunk = isDestroyer1 == true && (isDestroyer1HullHorizontal == true || isDestroyer1HullVertical == true); bool isDestroyer2Sunk = isDestroyer2 == true && (isDestroyer2HullHorizontal == true || isDestroyer2HullVertical == true); bool isPlayerWin = isBattleshipSunk == true && isDestroyer1Sunk == true && isDestroyer2Sunk == true; if (isBattleship == true && isBattleshipSunk == true) { Console.WriteLine(this.battleshipSunkMessage); } if (isDestroyer1Sunk == true) { Console.WriteLine(this.destroyer1Sunk); } if (isDestroyer2Sunk == true) { Console.WriteLine(this.destroyer2Sunk); } if (isPlayerWin == true) { int shots = Engine.InstanceEngine.Shots; InstanceOfEngineMethod.PlayerWin(shots); } } else { playerShot.OnShotMiss(shotX, shotY, gameOnGrid, this.missSymbol); } this.countShots++; this.PrintGrid(gameOnGrid); }