private void DisplayBoard(Board board) { Console.WriteLine(" 1 2 3 4 5 6 7 8 9 10 "); string[] letters = new string[] { "", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J" }; for (int i = 1; i <= 10; i++) { Console.Write("{0} ", letters[i]); for (int j = 1; j <= 10; j++) { Coordinate coordinate = new Coordinate(i, j); ShotHistory history = board.CheckCoordinate(coordinate); if (history == ShotHistory.Unknown) { Console.Write(" "); } else if (history == ShotHistory.Hit) { Console.ForegroundColor = ConsoleColor.Red; Console.Write("H "); Console.ForegroundColor = ConsoleColor.White; } else if (history == ShotHistory.Miss) { Console.ForegroundColor = ConsoleColor.Yellow; Console.Write("M "); Console.ForegroundColor = ConsoleColor.White; } } Console.WriteLine(""); } }
public static void printboard(Board board) { Console.WriteLine(" 1 2 3 4 5 6 7 8 9 10"); for (int i = 1; i <= 10; i++) { Console.Write($"{LetterToWrite(i)}"); for (int y = 1; y <= 10; y++) { Coordinate coordinate = new Coordinate(i, y); ShotHistory ValShotHist = board.CheckCoordinate(coordinate); switch (ValShotHist) { case ShotHistory.Unknown: Console.Write(" ! "); break; case ShotHistory.Miss: Console.Write(" M "); break; case ShotHistory.Hit: Console.Write(" H "); break; default: Console.Write(" ! "); break; } } Console.WriteLine(""); } }
public void DisplayShotTracker(Player player) { string xLetter = "ABCDEFGHIJ"; char row = 'A'; Console.WriteLine(" 1 2 3 4 5 6 7 8 9 10"); for (int x = 1; x <= 10; x++) { row = xLetter[x - 1]; Console.Write($"\n[{row}]"); for (int y = 1; y <= 10; y++) { ShotHistory history = player.Board.CheckCoordinate(new Coordinate(x, y)); switch (history) { case ShotHistory.Hit: Console.ForegroundColor = ConsoleColor.Red; Console.Write("H"); break; case ShotHistory.Miss: Console.ForegroundColor = ConsoleColor.Yellow; Console.Write("M"); break; case ShotHistory.Unknown: Console.Write(" "); break; } Console.ForegroundColor = ConsoleColor.White; Console.Write(" |"); } Console.WriteLine(); } Console.WriteLine(" "); }
public static void PrintEnemyBoard(Player player) { string[,] BoardPrinted = new string[11, 11]; for (int x = 0; x < 11; x++) { for (int y = 0; y < 11; y++) { Coordinate currentCoord = new Coordinate(x, y); ShotHistory result = player.board.CheckCoordinate(currentCoord); if (x == 0 || y == 0) { Console.Write(""); } else if (result == ShotHistory.Miss) { Console.ForegroundColor = System.ConsoleColor.Yellow; BoardPrinted[x, y] = " M "; Console.Write(BoardPrinted[x, y]); Console.ForegroundColor = System.ConsoleColor.White; } else if (result == ShotHistory.Hit) { Console.ForegroundColor = System.ConsoleColor.Red; BoardPrinted[x, y] = " H "; Console.Write(BoardPrinted[x, y]); Console.ForegroundColor = System.ConsoleColor.White; } else { Console.Write(" U "); } } Console.WriteLine(""); } }
public static void BoardOutput(Player currentPlayer) { char letter = 'A'; Console.WriteLine(" 1 2 3 4 5 6 7 8 9 10"); for (int x = 1; x <= 10; x++) { Console.Write(letter++); for (int y = 1; y <= 10; y++) { Coordinate cord = new Coordinate(x, y); ShotHistory cordState = currentPlayer.GameBoard.CheckCoordinate(cord); if (cordState == ShotHistory.Unknown) { Console.ForegroundColor = ConsoleColor.Cyan; Console.Write(" +"); Console.ResetColor(); } else if (cordState == ShotHistory.Hit) { Console.ForegroundColor = ConsoleColor.Red; Console.Write(" H"); Console.ResetColor(); } else { Console.ForegroundColor = ConsoleColor.Yellow; Console.Write(" M"); Console.ResetColor(); } } Console.Write("\n"); } Console.Write("Enter a coordinate to attack: "); }
public static void PlayerBoard() { Board playerBoard = new Board(); string xLetter = "ABCDEFGHIJ"; char row = 'A'; ShotHistory shotDisplay = new ShotHistory(); Console.Write(" [1 2 3 4 5 6 7 8 9 10]"); for (int x = 0; x < 10; x++) { row = xLetter[x]; Console.Write($"\n[{row}]"); for (int y = 0; y < 10; y++) { Coordinate coordinate = new Coordinate(x, y); shotDisplay = playerBoard.CheckCoordinate(coordinate); Console.Write($"[{shotDisplay}]"); } } Console.ReadLine(); Console.Clear(); }
private void CheckShipsForHit(Coordinate coordinate, FireShotResponse response) { ShotHistory shotHistory = Responses.ShotHistory.Miss; response.ShotStatus = ShotStatus.Miss; // check only un-sunk ships foreach (var ship in Ships.Where(s => !s.IsSunk)) { response.ShotStatus = ship.FireAtShip(coordinate); // if a hit, set response, history type if (response.ShotStatus != ShotStatus.Miss) { // Only return ship if sunk if (response.ShotStatus == ShotStatus.HitAndSunk) { response.ShipImpacted = ship.ShipName; } shotHistory = Responses.ShotHistory.Hit; // hit can only be 1 ship, all done break; } } // Save history _shotHistory.Add(coordinate, shotHistory); }
internal static void DrawBoard(Board GameBoard) { for (int y = 1; y <= 10; y++) { for (int x = 1; x <= 10; x++) { ShotHistory currentState = GameBoard.CheckCoordinate(new Coordinate(y, x)); switch (currentState) { case ShotHistory.Unknown: Console.ForegroundColor = ConsoleColor.Green; Console.Write("?"); Console.ForegroundColor = ConsoleColor.White; break; case ShotHistory.Miss: Console.ForegroundColor = ConsoleColor.Yellow; Console.Write("M"); Console.ForegroundColor = ConsoleColor.White; break; case ShotHistory.Hit: Console.ForegroundColor = ConsoleColor.Red; Console.Write("H"); Console.ForegroundColor = ConsoleColor.White; break; } Console.Write(" | "); } Console.WriteLine(); Console.WriteLine("-------------------------------------------------"); } }
/// <summary> /// Prints a single cell using the given board and coordinates. /// </summary> /// <param name="board">The board to print a cell on.</param> /// <param name="coord">The coordinate you want to print, this will determine the cell's contents.</param> /// <param name="showPlacedShips">Will show the ship's name as the cell's content.</param> private static void PrintBoardCell(Board board, Coordinate coord, bool showPlacedShips = false) { ShotHistory shotHist = board.CheckCoordinate(coord); if (shotHist == ShotHistory.Hit) { PrintBoardCell(BOARD_INDICATORS_HIT, ConsoleColor.Red); } else if (shotHist == ShotHistory.Miss) { PrintBoardCell(BOARD_INDICATORS_MISS, ConsoleColor.Yellow); } else if (showPlacedShips) { bool isShipFound = false; foreach (Ship ship in board.Ships) { if (ship != null && ship.BoardPositions.Contains(coord)) { PrintBoardCell(GetShipShortName(ship.ShipType), ConsoleColor.White); isShipFound = true; break; } } if (!isShipFound) { PrintBoardCell(BOARD_INDICATORS_NONE, ConsoleColor.White); } } else { PrintBoardCell(BOARD_INDICATORS_NONE, ConsoleColor.White); } }
private void CheckShipsForHit(Coordinate coordinate, FireShotResponse response) { ShotHistory shotHistory = Responses.ShotHistory.Miss; response.ShotStatus = ShotStatus.Miss; foreach (Ship ship in Ships) { // check only un-sunk ships if (!ship.IsSunk) { response.ShotStatus = ship.FireAtShip(coordinate); // if a hit, set response, history type if (response.ShotStatus != ShotStatus.Miss) { response.ShipImpacted = ship.ShipName; shotHistory = Responses.ShotHistory.Hit; // hit can only be 1 ship, all done break; } } } // Save history ShotHistory.Add(coordinate, shotHistory); }
private bool WouldShotBeAWaste(Shot shot) { if (ShotHistory.Contains(shot)) { return(true); } if (shot.Coordinates.X < 0) { return(true); } if (shot.Coordinates.X > 9) { return(true); } if (shot.Coordinates.Y < 0) { return(true); } if (shot.Coordinates.Y > 9) { return(true); } return(false); }
public static void DisplayBoard(Board board) { string xStr = "ABCDEFGHIJ"; char row = 'Z'; ShotHistory displayShot = new ShotHistory(); Console.Write(" [1 2 3 4 5 6 7 8 9 10]"); for (int x = 0; x < 10; x++) { row = xStr[x]; Console.Write($"\n[{row}]"); for (int y = 0; y < 10; y++) { Coordinate coord = new Coordinate(x + 1, y + 1); displayShot = board.CheckCoordinate(coord); if (displayShot == ShotHistory.Unknown) { Console.Write($"[ ]"); } if (displayShot == ShotHistory.Hit) { Console.ForegroundColor = ConsoleColor.Red; Console.Write("[H]"); } if (displayShot == ShotHistory.Miss) { Console.ForegroundColor = ConsoleColor.Yellow; Console.Write("[M]"); } Console.ForegroundColor = ConsoleColor.White; } } Console.WriteLine(""); }
public IEnumerable <Shot> GetShots(IEnumerable <EnemyFleetInfo> enemyFleetInfo, int numberOfShots) { if (this.SearchShots == null) { CreateSearchShots(enemyFleetInfo); } if (LastHittMe != null) { // if the person who last shot at me has no ships then go back to the weakest var shooter = enemyFleetInfo.Single(s => s.Name == LastHittMe); if (shooter.NumberOfAfloatShipts == 0) { LastHittMe = null; } } var shotsToFire = new List <Shot>(); string target = LastHittMe; if (target == null) { target = enemyFleetInfo .Where(f => f.NumberOfAfloatShipts > 0) .OrderByDescending(f => f.NumberOfAfloatShipts) .FirstOrDefault() ?.Name; } // see if we've got any finds first foreach (var find in Finds) { while (shotsToFire.Count < numberOfShots && find.UpcomingShots.Any()) { var nextShot = find.UpcomingShots.Pop(); if (!WouldShotBeAWaste(nextShot)) { shotsToFire.Add(nextShot); } } } // then fill up with searches while (shotsToFire.Count < numberOfShots) { if (SearchShots.ContainsKey(target) && SearchShots[target].Any()) { var nextSearchingShot = SearchShots[target].Pop(); if (!WouldShotBeAWaste(nextSearchingShot)) { shotsToFire.Add(nextSearchingShot); } } } ShotHistory.AddRange(shotsToFire); return(shotsToFire); }
public static void DrawHistory(Player player, bool drawShips) { Console.ForegroundColor = ConsoleColor.Yellow; Console.Write(" "); for (int y = 1; y <= 10; y++) { Console.Write(y); Console.Write(" "); } Console.WriteLine(); Console.ForegroundColor = ConsoleColor.White; for (int x = 1; x <= 10; x++) { Console.ForegroundColor = ConsoleColor.Yellow; Console.Write(GetLetterFromNumber(x) + " "); Console.ForegroundColor = ConsoleColor.White; for (int y = 1; y <= 10; y++) { Console.Write(""); ShotHistory history = player.PlayerBoard.CheckCoordinate(new Coordinate(x, y)); switch (history) { case ShotHistory.Hit: Console.ForegroundColor = ConsoleColor.DarkRed; Console.Write("X"); Console.ForegroundColor = ConsoleColor.White; break; case ShotHistory.Miss: Console.Write("*"); break; case ShotHistory.Ship: if (drawShips) { Console.ForegroundColor = ConsoleColor.Cyan; Console.Write("S"); Console.ForegroundColor = ConsoleColor.White; } else { Console.Write(" "); } break; case ShotHistory.Unknown: Console.Write(" "); break; } Console.Write("."); } Console.WriteLine(""); } Console.WriteLine(); }
public Board DrawEnemyBoardFire(Board x, FireShotResponse shot, Coordinate cord) { ShotHistory History = new ShotHistory(); for (int k = 0; k < 5; k++) { x.CheckCoordinate(cord); Coordinate[] p1 = new Coordinate[10]; } int[,] arr = new int[11, 11]; for (int i = 1; i < 11; i++) { for (int j = 1; j < 11; j++) { string marking = " "; Coordinate CurrentCoordinate = new Coordinate(i, j); for (int k = 0; k < 5; k++) { History = x.CheckCoordinate(cord); } var checkCord = History; if (checkCord == ShotHistory.Miss && (j == cord.YCoordinate && i == cord.XCoordinate)) { Console.ForegroundColor = ConsoleColor.Yellow; marking = "M"; } else if (checkCord == ShotHistory.Hit && (j == cord.YCoordinate && i == cord.XCoordinate)) { Console.ForegroundColor = ConsoleColor.Red; marking = "H"; } else if (checkCord == ShotHistory.Unknown && (j == cord.YCoordinate && i == cord.XCoordinate)) { marking = "-"; } Console.Write($"|{marking}"); Console.ForegroundColor = ConsoleColor.White; } Console.WriteLine(); } return(x); }
public void DrawHistory(IPlayer player) { Console.ForegroundColor = ConsoleColor.Yellow; Console.Write(" "); for (var y = 1; y <= 10; y++) { Console.Write(y); Console.Write(" "); } Console.WriteLine(); Console.ForegroundColor = ConsoleColor.White; List <ShotHistory> list = new List <ShotHistory>(); for (var x = 1; x <= 10; x++) { Console.ForegroundColor = ConsoleColor.Yellow; Console.Write(_helper.GetLetterFromNumber(x) + " "); Console.ForegroundColor = ConsoleColor.White; for (int y = 1; y <= 10; y++) { _shotHistory = player.Board.CheckCoordinate(new Coordinate(x, y)); list.Add(_shotHistory); switch (_shotHistory) { case ShotHistory.PlayerShip: Console.ForegroundColor = ConsoleColor.Yellow; Console.Write("S"); Console.ForegroundColor = ConsoleColor.White; continue; case ShotHistory.Hit: Console.ForegroundColor = ConsoleColor.Red; Console.Write("H"); Console.ForegroundColor = ConsoleColor.White; break; case ShotHistory.Miss: Console.Write("M"); break; default: Console.Write(" "); break; } Console.Write("|"); } Console.WriteLine(); } Console.WriteLine(""); }
public void PrintBoard(Board board, string playerName) { Console.WriteLine(" | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 "); Console.WriteLine("-------------------------------------------"); char c = 'A'; while (c <= 'J') { for (int letterRow = 1; letterRow <= 10; letterRow++) { Console.Write($"\n|{c++}"); for (int numCol = 1; numCol <= 10; numCol++) { Coordinate shot = new Coordinate(letterRow, numCol); if (board.ShotHistory.ContainsKey(shot)) { ShotHistory value = board.ShotHistory[shot]; switch (value) { case ShotHistory.Miss: Console.BackgroundColor = ConsoleColor.Yellow; Console.ForegroundColor = ConsoleColor.White; Console.Write("|"); Console.Write(" M "); Console.ResetColor(); break; case ShotHistory.Hit: Console.BackgroundColor = ConsoleColor.Red; Console.ForegroundColor = ConsoleColor.White; Console.Write("|"); Console.Write(" H "); Console.ResetColor(); break; } } else { Console.Write("| "); } } } Console.WriteLine(); } }
// Board layouts private void ShowShotBoard(Board board) { Console.WriteLine(); Console.Write(" A B C D E F G H I J "); for (int y = 1; y <= 10; y++) { if (y < 10) { Console.Write($"\n{y} "); } else { Console.Write($"\n{y} "); } for (int x = 1; x <= 10; x++) { Coordinate shotCoor = new Coordinate(y, x); ShotHistory shotExist = ShotHistory.Unknown; if (board.ShotHistory.ContainsKey(shotCoor)) { shotExist = board.ShotHistory[shotCoor]; } if (shotExist == ShotHistory.Hit) { Console.ForegroundColor = ConsoleColor.Red; Console.Write("("); Console.Write("H"); Console.Write(")"); Console.ResetColor(); } else if (shotExist == ShotHistory.Miss) { Console.ForegroundColor = ConsoleColor.Yellow; Console.Write("("); Console.Write("M"); Console.Write(")"); Console.ResetColor(); } else { Console.Write("("); Console.Write("_"); Console.Write(")"); } } } Console.WriteLine(); }
internal static void BoardDisplay(Board playerBoard) { string leftSideOfMap = "ABCDEFGHIJ"; string topOfMap = "0123456789"; for (int i = 0; i < 11; i++) { Console.WriteLine(); for (int j = 0; j < 11; j++) { if (i == 0 && j == 0) { Console.Write(" "); } else if (i == 0 && j == 10) { Console.Write(topOfMap[1] + "" + topOfMap[0]); } else if (i == 0 && j != 10) { Console.Write(topOfMap[j] + " "); } else if (j == 0 && i != 0) { Console.Write(leftSideOfMap[i - 1]); } else if (i != 0) { Coordinate coordinateToDisplay = new Coordinate(j, i); ShotHistory positionHistory = playerBoard.CheckCoordinate(coordinateToDisplay); if (positionHistory == ShotHistory.Hit) { Console.Write(" x"); } else if (positionHistory == ShotHistory.Miss) { Console.Write(" o"); } else { Console.Write(" ~"); } } } } }
public void DisplayBoard(Board board) { // Displays shot history/board of opponent Console.WriteLine(" A B C D E F G H I J "); for (int cols = 1; cols <= 10; cols++) { if (cols < 10) { Console.Write(" "); Console.Write(cols); } else { Console.Write(cols); } for (int rows = 1; rows <= 10; rows++) { Console.BackgroundColor = ConsoleColor.Blue; Coordinate coord = new Coordinate(rows, cols); if (board.ShotHistory.ContainsKey(coord)) { ShotHistory spotResult = board.ShotHistory[coord]; switch (spotResult) { case ShotHistory.Hit: Console.ForegroundColor = ConsoleColor.Red; Console.Write(" H "); Console.ForegroundColor = ConsoleColor.White; break; case ShotHistory.Miss: Console.ForegroundColor = ConsoleColor.Yellow; Console.Write(" M "); Console.ForegroundColor = ConsoleColor.White; break; default: break; } } else { Console.Write(" "); } } Console.WriteLine(); Console.BackgroundColor = ConsoleColor.Black; } }
public Board DrawEnemyBoard(Board x) { ShotHistory History = new ShotHistory(); int[,] arr = new int[10, 10]; for (int i = 1; i <= 10; i++) { for (int j = 1; j <= 10; j++) { string marking = " "; Coordinate CurrentCoordinate = new Coordinate(i, j); for (int k = 0; k < 5; k++) { History = x.CheckCoordinate(CurrentCoordinate); } var checkCord = History; if (checkCord == ShotHistory.Miss) { Console.ForegroundColor = ConsoleColor.Yellow; marking = "M"; } if (checkCord == ShotHistory.Hit) { Console.ForegroundColor = ConsoleColor.Red; marking = "H"; } if (checkCord == ShotHistory.Unknown) { marking = "-"; } Console.Write($"|{marking}"); Console.ForegroundColor = ConsoleColor.White; } Console.WriteLine(); } return(x); }
static void BoardPrinter(Board board) { Console.WriteLine(" | A || B || C || D || E || F || G || H || I || J |"); for (int i = 1; i <= 10; i++) { Console.WriteLine("---|-------------------------------------------------"); if (i < 10) { Console.Write(" " + i + " "); } else { Console.Write("10 "); } for (int j = 1; j <= 10; j++) { Coordinate coordinate = new Coordinate(j, i); ShotHistory shot = board.CheckCoordinate(coordinate); Console.Write("[ "); if (shot == ShotHistory.Hit) { Console.ForegroundColor = ConsoleColor.Red; Console.Write("H"); Console.ResetColor(); } else if (shot == ShotHistory.Miss) { Console.ForegroundColor = ConsoleColor.Yellow; Console.Write("M"); Console.ResetColor(); } else if (shot == ShotHistory.Unknown) { Console.Write("X"); } Console.Write(" ]"); } Console.WriteLine(""); } }
//Displaying public void DrawBoards(Player player) { Console.ForegroundColor = ConsoleColor.Yellow; Console.Write(" "); for (int y = 1; y <= 10; y++) { Console.Write(y); Console.Write(" "); } Console.WriteLine(); Console.ForegroundColor = ConsoleColor.White; for (int x = 1; x <= 10; x++) { Console.ForegroundColor = ConsoleColor.Yellow; Console.Write(GetLetterFromNumber(x) + " "); Console.ForegroundColor = ConsoleColor.White; for (int y = 1; y <= 10; y++) { //Console.Write("O"); { ShotHistory history = player.PlayerBoard.CheckCoordinate(new Coordinates(x, y)); switch (history) { case ShotHistory.Hit: Console.ForegroundColor = ConsoleColor.Red; Console.Write("H"); Console.ForegroundColor = ConsoleColor.White; break; case ShotHistory.Miss: Console.Write("M"); break; case ShotHistory.Unknown: Console.Write(" "); break; } } Console.Write("|"); } Console.WriteLine(); } Console.WriteLine(""); }
public static Board DrawBoard(GameState state) { //Coordinate coordToCheck = new Coordinate(); Board toDraw = state.IsPlayer1Turn ? state.P2.PlayerBoard : state.P1.PlayerBoard; if (!state.IsPlayer1Turn) { ConsoleOutput.WhoseTurn(state.P2); } else { ConsoleOutput.WhoseTurn(state.P1); } for (int y = 1; y < 11; y++) { for (int x = 1; x < 11; x++) { ShotHistory currentHistory = toDraw.CheckCoordinate(new Coordinate(y, x)); switch (currentHistory) { case ShotHistory.Unknown: Console.Write(" "); break; case ShotHistory.Hit: Console.ForegroundColor = ConsoleColor.Red; Console.Write("H"); Console.ResetColor(); break; case ShotHistory.Miss: Console.ForegroundColor = ConsoleColor.DarkYellow; Console.Write("M"); Console.ResetColor(); break; } Console.Write(" | "); } Console.WriteLine(); Console.WriteLine("---------------------------------------"); } return(toDraw); }
private void DisplayMap(Board userBoard) { Console.Clear(); for (int i = 0; i <= 10; i++) { Console.Write(" "); for (int j = 0; j <= 10; j++) { if (i == 0 && j != 0) { Console.Write(j + " "); } else if (i > 0 && j == 0) { Console.Write(Players.possibleLetters[i - 1] + " "); } else { Coordinate checkCoordinate = new Coordinate(i, j); ShotHistory response = userBoard.CheckCoordinate(checkCoordinate); if (response.Equals(ShotHistory.Hit)) { Console.ForegroundColor = ConsoleColor.Red; Console.Write("H "); Console.ResetColor(); } else if (response.Equals(ShotHistory.Miss)) { Console.ForegroundColor = ConsoleColor.Yellow; Console.Write("M "); Console.ResetColor(); } else { Console.Write(" "); } } } Console.Write("\n"); } }
public static void HitBoard(Player player) { int i; int j; Console.WriteLine(" A B C D E F G H I J"); for (j = 1; j < 11; j++) { Console.Write("\n"); Console.Write($"{j} "); for (i = 1; i < 11; i++) { ShotHistory checkCoordinate = player.pBoard.CheckCoordinate(new Coordinate(i, j)); if (checkCoordinate == ShotHistory.Hit) { Console.ForegroundColor = ConsoleColor.Red; Console.Write(" H "); Console.ResetColor(); } else if (checkCoordinate == ShotHistory.Miss) { Console.ForegroundColor = ConsoleColor.Yellow; Console.Write(" M "); Console.ResetColor(); } else if (checkCoordinate == ShotHistory.Unknown) { Console.Write(" - "); } else { Console.Write(" - "); } } } Console.WriteLine("\n\n"); }
public static void PlayerBoard(Player player, Player player2) { Board Board = new Board(); string xrows = "ABCDEFGHIJ"; char xchar = 'A'; Console.Write(" 1 2 3 4 5 6 7 8 9 10"); for (int x = 0; x < 10; x++) { xchar = xrows[x]; Console.WriteLine(); Console.Write($"{xchar}"); for (int y = 0; y < 10; y++) { Coordinate coordinate = new Coordinate(x + 1, y + 1); ShotHistory displayshot = new ShotHistory(); switch (displayshot = player.Board.CheckCoordinate(coordinate)) { case ShotHistory.Hit: Console.ForegroundColor = ConsoleColor.Red; Console.Write("[H]"); break; case ShotHistory.Miss: Console.ForegroundColor = ConsoleColor.Yellow; Console.Write("[M]"); break; case ShotHistory.Unknown: break; default: break; } Console.ForegroundColor = ConsoleColor.White; } } Console.ReadKey(); Console.Clear(); }
private void CheckShipsForHit(Coordinate coordinate, FireShotResponse response) { response.ShotStatus = ShotStatus.Miss; foreach (Ship ship in Ships) { // no need to check sunk ships 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 PlayerBoard(Players player, Players player2) { string xLetter = "ABCDEFGHIJ"; char row = 'A'; Console.Write(" [1 2 3 4 5 6 7 8 9 10]"); for (int x = 0; x < 10; x++) { row = xLetter[x]; Console.Write($"\n[{row}]"); for (int y = 0; y < 10; y++) { ShotHistory shotDisplay = new ShotHistory(); Coordinate coordinate = new Coordinate(x + 1, y + 1); switch (shotDisplay = player.Board.CheckCoordinate(coordinate)) { case ShotHistory.Hit: Console.ForegroundColor = ConsoleColor.Red; Console.Write("[h]"); break; case ShotHistory.Miss: Console.ForegroundColor = ConsoleColor.Yellow; Console.Write("[m]"); break; case ShotHistory.Unknown: Console.Write(""); break; default: break; } Console.ForegroundColor = ConsoleColor.White; } } Console.ReadLine(); Console.Clear(); }
public static void DisplayBoard(Board board) { Console.WriteLine(" 1 2 3 4 5 6 7 8 9 10"); Console.WriteLine(" +--+--+--+--+--+--+--+--+--+--+"); for (int row = 1; row < 11; row++) { string rowID = (((RowId)row).ToString()); Console.Write($"{rowID} |"); for (int col = 1; col < 11; col++) { Console.Write(" "); var coordinate = new Coordinate(row, col); ShotHistory pastShot = board.CheckCoordinate(coordinate); switch (pastShot) { case ShotHistory.Miss: Console.ForegroundColor = ConsoleColor.Yellow; Console.Write("M"); Console.ResetColor(); break; case ShotHistory.Hit: Console.ForegroundColor = ConsoleColor.Red; Console.Write("H"); Console.ResetColor(); break; case ShotHistory.Unknown: Console.Write(" "); break; default: break; } Console.Write("|"); } Console.WriteLine(); Console.WriteLine(" +--+--+--+--+--+--+--+--+--+--+"); } }