Ejemplo n.º 1
0
        public static void showField(BoardInterface board, int positionLeft)
        {
            int coursorLeft = Console.CursorLeft;
            int coursorTop  = Console.CursorTop;

            Console.SetCursorPosition(positionLeft, 0);
            Console.Write("# 1 2 3 4 5 6 7 8 9 10#");
            Console.SetCursorPosition(positionLeft - 1, 1);

            for (int i = 1; i <= 10; i++)
            {
                string label = (i / 10 == 1)? $"{i}" : $" {i}";
                Console.Write(label);
                for (int j = 1; j <= 10; j++)
                {
                    Position position = new Position(j, i);
                    try
                    {
                        switch (board.getStatus(position))
                        {
                        case ShipStatus.INTACT:
                            Console.Write(" *");
                            break;

                        case ShipStatus.HIT:
                            Console.Write(" X");
                            break;

                        case ShipStatus.SUNK:
                            Console.Write(" #");
                            break;
                        }
                    }
                    catch (InvalidPositionException e)
                    {
                        Console.Write("  ");
                    }
                }
                Console.Write($" {i}");
                Console.SetCursorPosition(positionLeft - 1, i + 1);
            }
            Console.CursorLeft += 1;
            Console.Write("# 1 2 3 4 5 6 7 8 9 10#");
            Console.SetCursorPosition(coursorLeft, coursorTop);
        }
Ejemplo n.º 2
0
        private void checkStatus(Position position, PlayerInterface currPlayer, BoardInterface enemyBoard)
        {
            try
            {
                switch (enemyBoard.getStatus(position))
                {
                case ShipStatus.HIT:
                    currPlayer.shotResult(position, ShotStatus.HIT);
                    break;

                case ShipStatus.SUNK:
                    currPlayer.shotResult(position, ShotStatus.SUNK);
                    break;
                }
            }
            catch
            {
                currPlayer.shotResult(position, ShotStatus.MISS);
            }
        }