Esempio n. 1
0
        private FireShotResponse Shot(Player victim, Player Shoter, out Coordinate ShotPoint)
        {
            FireShotResponse fire; Coordinate WhereToShot;

            do
            {
                WhereToShot = ControlInput.GetShotLocationFromUser();
                fire        = victim.PlayerBoard.FireShot(WhereToShot);
                if (fire.ShotStatus == ShotStatus.Invalid || fire.ShotStatus == ShotStatus.Duplicate)
                {
                    ControlOutput.ShowShotResult(fire, WhereToShot, "");
                }


                if (fire.ShotStatus == ShotStatus.Victory)
                {
                    if (gm.IsPlayer1)
                    {
                        gm.Player1.Win += 1;
                    }
                    else
                    {
                        gm.Player2.Win += 1;
                    }
                }
            } while (fire.ShotStatus == ShotStatus.Duplicate || fire.ShotStatus == ShotStatus.Invalid);
            ShotPoint = WhereToShot;
            return(fire);
        }
Esempio n. 2
0
        public void Start()
        {
            GameSetup GameSetup = new GameSetup(gm);

            GameSetup.Setup();

            do
            {
                GameSetup.SetBoard();
                FireShotResponse shotresponse;
                do
                {
                    ControlOutput.ResetScreen(new Player[] { gm.Player1, gm.Player2 });
                    ControlOutput.ShowWhoseTurn(gm.IsPlayer1 ? gm.Player2 : gm.Player1);
                    ControlOutput.DrawHistory(gm.IsPlayer1 ? gm.Player2 : gm.Player1, gm.IsPlayer1 ? 2 : 1);
                    Coordinate ShotPoint = new Coordinate(1, 1);
                    shotresponse = Shot(gm.IsPlayer1 ? gm.Player2 : gm.Player1, gm.IsPlayer1 ? gm.Player1 : gm.Player2, out ShotPoint);

                    ControlOutput.ResetScreen(new Player[] { gm.Player1, gm.Player2 });
                    ControlOutput.ShowWhoseTurn(gm.IsPlayer1 ? gm.Player2 : gm.Player1);
                    ControlOutput.DrawHistory(gm.IsPlayer1 ? gm.Player2 : gm.Player1, gm.IsPlayer1 ? 2 : 1);
                    ControlOutput.ShowShotResult(shotresponse, ShotPoint, gm.IsPlayer1 ? gm.Player1.Name : gm.Player2.Name);
                    if (shotresponse.ShotStatus != ShipHitCheck.Victory)
                    {
                        Console.WriteLine("Press any key to continue to switch to " + (gm.IsPlayer1 ? gm.Player1.Name : gm.Player2.Name));
                        gm.IsPlayer1 = !gm.IsPlayer1;
                        Console.ReadKey();
                    }
                } while (shotresponse.ShotStatus != ShipHitCheck.Victory);
            } while (ControlInput.CheckQuit());
        }
Esempio n. 3
0
        public static void ResetScreen(Player[] player)
        {
            GamePlayers gs = new GamePlayers();

            Console.Clear();
            ControlOutput.ShowHeader();
            ControlOutput.ShowPlayers(player);
        }
Esempio n. 4
0
        public void Setup()
        {
            Console.ForegroundColor = ConsoleColor.White;
            ControlOutput.ShowHeader();

            string[] userSetUp = ControlInput.GetNameFromUser();

            _gm.Player1.Name = userSetUp[0];

            _gm.Player2.Name = userSetUp[1];
        }
Esempio n. 5
0
        public void SetBoard()
        {
            ControlOutput.ResetScreen(new Player[] { _gm.Player1, _gm.Player2 });

            _gm.IsPlayer1 = Responses.GetRandom.WhoseFirst();

            _gm.Player1.PlayerBoard = new Board();
            PlaceShipOnBoard(_gm.Player1);
            ControlOutput.ResetScreen(new Player[] { _gm.Player1, _gm.Player2 });

            _gm.Player2.PlayerBoard = new Board();
            PlaceShipOnBoard(_gm.Player2);
            Console.WriteLine("All ship were placed successfull! Press any key to continue...");
            Console.ReadKey();
        }
Esempio n. 6
0
        public void Music()
        {
            Console.ForegroundColor = ConsoleColor.White;
            ControlOutput.ShowHeader();

            bool IsMusicOn = false;

            IsMusicOn = ControlInput.IsMusicOn();
            if (IsMusicOn)
            {
                SoundPlayer player = new SoundPlayer();
                player.SoundLocation = AppDomain.CurrentDomain.BaseDirectory + "\\1.wav";
                player.Play();
            }
        }
Esempio n. 7
0
        public void PlaceShipOnBoard(Player player)
        {
            bool IsPlaceBoardAuto = false;

            ControlOutput.ShowWhoseTurn(player);
            IsPlaceBoardAuto = ControlInput.IsPlaceBoardAuto();
            if (!IsPlaceBoardAuto)
            {
                Console.WriteLine("Input the location and direction(l, r, u, d) of the ships. Ex:) a2, r:");
            }
            for (ShipType s = ShipType.Destroyer; s <= ShipType.Carrier; s++)
            {
                PlaceShipRequest ShipToPlace = new PlaceShipRequest();
                ShipPlacement    result;
                do
                {
                    if (!IsPlaceBoardAuto)
                    {
                        ShipToPlace          = ControlInput.GetLocationFromUser(s.ToString());
                        ShipToPlace.ShipType = s;
                        result = player.PlayerBoard.PlaceShip(ShipToPlace);
                        if (result == ShipPlacement.NotEnoughSpace)
                        {
                            Console.WriteLine("Not Enough Space!");
                        }
                        else if (result == ShipPlacement.Overlap)
                        {
                            Console.WriteLine("Overlap placement!");
                        }
                    }
                    else
                    {
                        ShipToPlace          = ControlInput.GetLocationFromComputer();
                        ShipToPlace.ShipType = s;
                        result = player.PlayerBoard.PlaceShip(ShipToPlace);
                    }
                } while (result != ShipPlacement.Ok);
            }
        }
Esempio n. 8
0
 public static void ResetScreen(Player[] player)
 {
     Console.Clear();
     ControlOutput.ShowHeader();
     ControlOutput.ShowAllPlayer(player);
 }