Exemple #1
0
        public void HitShip(Player player, Player computer, Position shootPosition, List <Ship> enermyShips, Battlefield battlefield)
        {
            Ship hittedShip = HittedShip(shootPosition, enermyShips);

            // Display Graphic
            GraphicManager.DisplayBattleView(player, computer, battlefield);

            // remove Hit Position
            RemoveHitPosition(shootPosition, enermyShips);
            //isSunk or isHit
            SunkenHitInfo(hittedShip);
        }
Exemple #2
0
 public void HitWater(Player player, Player computer, Position iShootPosition, Battlefield battlefield, IPositionParser positionParser)
 {
     // Display Graphic
     GraphicManager.DisplayBattleView(player, computer, battlefield);
     //Sound Effects
     SoundEffects.HitWaterSoundPlayer();
     //information
     Console.ForegroundColor = ConsoleColor.DarkCyan;
     Console.WriteLine("                                               \" Shoot [ {0} ]\" ",
                       positionParser.BackParser(iShootPosition));
     Console.WriteLine();
     Console.Write("                                                     LOST ");
     //Thread.Sleep(500);
     //Console.Write("...");
     //Thread.Sleep(1000);
     Console.ReadKey();
 }
Exemple #3
0
        public static Position PlayerShoot(Player player, Player computer, Battlefield battlefield, IPositionParser positionParser, IPositionValidator positionValidator)
        {
            GraphicManager.DisplayBattleView(player, computer, battlefield);

            // isShootOk
            Position iShootPosition;

            do
            {
                Console.WriteLine("                                               \" I Shoot \" ");
                Console.WriteLine();
                Console.Write("                                                POSITION >");

                //convert to "Position"
                iShootPosition = positionParser.Parse(Console.ReadLine());
            } while (positionValidator.IsShootOk(iShootPosition, battlefield.ColumnSize, battlefield.RowSize, computer) == false);
            return(iShootPosition);
        }
Exemple #4
0
        public static Position ComputerShoot(Player player, Player computer, Battlefield battlefield, IRandomManager randomManager, IPositionParser positionParser)
        {
            Console.Clear();
            GraphicManager.DisplayBattleView(player, computer, battlefield);
            // [!!!] should be better
            Position pcShootPosition = randomManager.RandomPosition(battlefield.ColumnSize, battlefield.RowSize);

            Console.WriteLine("                                                \" PC Shoot \" ");
            Console.WriteLine();
            Console.Write("                                                  THINKING");
            // imitate Thinking
            Thread.Sleep(1000);
            Console.Write("... ");
            Thread.Sleep(500);
            Console.Write("[ {0} ]", positionParser.BackParser(pcShootPosition));
            Thread.Sleep(500);
            Console.Write(" ...");
            Thread.Sleep(500);
            return(pcShootPosition);
        }
Exemple #5
0
        public void PlacePlayerShips(List <Ship> playerShips, IPositionParser positionParser, IPositionValidator positionValidator, IShipManager shipManager, Battlefield battlefield)
        {
            foreach (var ship in playerShips)
            {
                Console.Clear();
                Console.WriteLine();
                //display battle field
                Console.WriteLine(GraphicManager.DisplayBattlefield(battlefield.ColumnSize, battlefield.RowSize, playerShips));
                //display place table
                Console.WriteLine(GraphicManager.DisplayPlaceTable(playerShips, ship.ShipType));

                //get the StartPosition
                Position position;
                do
                {
                    Console.Write(" Enter position for {0} > ", ship.ShipType);
                    position = positionParser.Parse(Console.ReadLine());
                } while (position == null);

                //get the direction
                Direction direction;
                do
                {
                    direction = GetDirection();
                } while (direction == Direction.None);

                //get whole ship positions
                var shipPositions = shipManager.WholeShipPositions(position, ship.Size, direction);

                //validate player position
                shipPositions = ValidatePlayerPositions(playerShips, positionParser, positionValidator, shipManager, shipPositions, ship, battlefield);

                ship.Positions.AddRange(shipPositions);
                SoundEffects.SetShipSoundPlayer();
            }
        }