void AddOneShipRandom(Board board, Ship ship) { do { NewRandomPosition(ship, board.Size); }while (!board.possibleShip(ship)); board.AddShip(ship); }
void AddOneShipManual(Board board, Ship ship) { int x = 0; int y = 0; int size = board.Size; Ship.Direction dir = Ship.Direction.horizontal; ConsoleKey key; bool CordsNotSet = true; bool wrongPositionMessage = false; do { ship.OriginPoint = (x, y); ship.InstanceDirection = dir; _display.PrintBoard(board, ship); if (wrongPositionMessage) { _display.PrintMessage("Invalid Ship Position", ConsoleColor.Red); wrongPositionMessage = false; } key = _input.ReadKey(); switch (key) { case ConsoleKey.UpArrow: if (y == 0 && dir == Ship.Direction.vertical) { y = size - ship.Length; } else if (y == 0 && dir == Ship.Direction.horizontal) { y = size - 1; } else { y--; } break; case ConsoleKey.DownArrow: if ((y == size - ship.Length && dir == Ship.Direction.vertical) || (y == size - 1)) { y = 0; } else { y++; } break; case ConsoleKey.LeftArrow: if (x == 0 && dir == Ship.Direction.horizontal) { x = size - ship.Length; } else if (x == 0 && dir == Ship.Direction.vertical) { x = size - 1; } else { x--; } break; case ConsoleKey.RightArrow: if ((x == size - ship.Length && dir == Ship.Direction.horizontal) || (x == size - 1)) { x = 0; } else { x++; } break; case ConsoleKey.Spacebar: if (dir == Ship.Direction.horizontal) { dir = Ship.Direction.vertical; if (y >= size - ship.Length) { y = size - ship.Length; } } else { dir = Ship.Direction.horizontal; if (x >= size - ship.Length) { x = size - ship.Length; } } break; case ConsoleKey.Enter: if (board.possibleShip(ship)) { board.AddShip(ship); CordsNotSet = false; } else { wrongPositionMessage = true; } break; default: break; } } while (CordsNotSet); }