Esempio n. 1
0
        //Shot is the shot result on the PCs Ocean
        public ShotResult Shot(Coordinates coordinates)
        {
            var cell = Ocean.CellAtCoordinate(coordinates.Row, coordinates.Column);

            if (!cell.IsOccupied)
            {
                Console.WriteLine(Name + " says: \"Miss!\"");
                cell.OccupationType = OccupationType.Miss;
                return(ShotResult.Miss);
            }
            var ship = Ships.First(x => x.OccupationType == cell.OccupationType);

            ship.Hits++;
            Console.WriteLine(Name + " says: \"Hit!\"");
            if (ship.IsDestroyed)
            {
                Console.WriteLine(Name + " says: \"You Destroy my " + ship.Name + "!\"");
            }
            cell.OccupationType = OccupationType.Hit;
            return(ShotResult.Hit);
        }
Esempio n. 2
0
        public void PrintBoards()
        {
            Console.WriteLine("Player: " + Name);
            Console.WriteLine("Own SeaBoard:                                           Firing Board:\n");
            Console.WriteLine("    1   2   3   4   5   6   7   8   9   10                      1   2   3   4   5   6   7   8   9   10\n");
            for (int row = 1; row <= 10; row++)
            {
                if (row < 10)
                {
                    Console.Write(row + "   ");
                }
                else
                {
                    Console.Write(row + "  ");
                }

                for (int ownColumn = 1; ownColumn <= 10; ownColumn++)
                {
                    Console.Write(Ocean.CellAtCoordinate(row, ownColumn).Status + "   ");
                }
                Console.Write("                ");
                if (row < 10)
                {
                    Console.Write(row + "   ");
                }
                else
                {
                    Console.Write(row + "  ");
                }
                for (int firingColumn = 1; firingColumn <= 10; firingColumn++)
                {
                    Console.Write(ShootingBoard.CellAtCoordinate(row, firingColumn).Status + "   ");
                }
                Console.WriteLine(Environment.NewLine);
            }
            Console.WriteLine(Environment.NewLine);
        }