예제 #1
0
        private ShotResponse Shot(Player victim, Player Shoter, out Coordinate ShotPoint)
        {
            ShotResponse fire; Coordinate WhereToShot;

            do
            {
                if (!Shoter.IsPC)
                {
                    WhereToShot = InputHandler.GetShotLocationFromUser();
                    fire        = victim.PlayerBoard.FireShot(WhereToShot);
                    if (fire.ShotStatus == Shots.Invalid || fire.ShotStatus == Shots.Duplicate)
                    {
                        OutputHandler.ShowShotResult(fire, WhereToShot, "");
                    }
                }
                else
                {
                    WhereToShot = InputHandler.GetShotLocationFromComputer(victim.PlayerBoard, Shoter.GameLevel);
                    fire        = victim.PlayerBoard.FireShot(WhereToShot);
                }
                if (fire.ShotStatus == Shots.Victory)
                {
                    if (gm.IsPlayer1)
                    {
                        gm.Player1.Win += 1;
                    }
                    else
                    {
                        gm.Player2.Win += 1;
                    }
                }
            } while (fire.ShotStatus == Shots.Duplicate || fire.ShotStatus == Shots.Invalid);
            ShotPoint = WhereToShot;
            return(fire);
        }
예제 #2
0
        public void Start()
        {
            GameSetup GameSetup = new GameSetup(gm);

            GameSetup.Setup();

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

                    OutputHandler.ResetScreen(new Player[] { gm.Player1, gm.Player2 });
                    OutputHandler.ShowWhoseTurn(gm.IsPlayer1 ? gm.Player1 : gm.Player2);
                    OutputHandler.DrawHistory(gm.IsPlayer1 ? gm.Player2 : gm.Player1);
                    OutputHandler.ShowShotResult(shotresponse, ShotPoint, gm.IsPlayer1 ? gm.Player1.Name : gm.Player2.Name);
                    if (shotresponse.ShotStatus != Shots.Victory)
                    {
                        Console.WriteLine("Press any key to continue to switch to " + (gm.IsPlayer1 ? gm.Player2.Name : gm.Player1.Name));
                        gm.IsPlayer1 = !gm.IsPlayer1;
                        Console.ReadKey();
                    }
                } while (shotresponse.ShotStatus != Shots.Victory);
            } while (InputHandler.CheckQuit());
        }
예제 #3
0
        public void SetBoard()
        {
            OutputHandler.ResetScreen(new Player[] { _gm.Player1, _gm.Player2 });

            _gm.IsPlayer1 = GetRandom.WhoseFirst();

            _gm.Player1.PlayerBoard = new Board();
            PlaceShipOnBoard(_gm.Player1);
            OutputHandler.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();
        }
예제 #4
0
        public void PlaceShipOnBoard(Player player)
        {
            bool IsPlaceBoardAuto = false;

            if (player.IsPC != true)
            {
                OutputHandler.ShowWhoseTurn(player);
                IsPlaceBoardAuto = InputHandler.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++)
            {
                ShipPlacement ShipToPlace = new ShipPlacement();
                ShipPlacing   result;
                do
                {
                    if (!player.IsPC && !IsPlaceBoardAuto)
                    {
                        ShipToPlace          = InputHandler.GetLocationFromUser(s.ToString());
                        ShipToPlace.ShipType = s;
                        result = player.PlayerBoard.PlaceShip(ShipToPlace);
                        if (result == ShipPlacing.NotEnoughSpace)
                        {
                            Console.WriteLine("Not Enough Space!");
                        }
                        else if (result == ShipPlacing.Overlap)
                        {
                            Console.WriteLine("Overlap placement!");
                        }
                    }
                    else
                    {
                        ShipToPlace          = InputHandler.GetLocationFromComputer();
                        ShipToPlace.ShipType = s;
                        result = player.PlayerBoard.PlaceShip(ShipToPlace);
                    }
                } while (result != ShipPlacing.Ok);
            }
        }
예제 #5
0
        public void Setup()
        {
            Console.ForegroundColor = ConsoleColor.White;
            OutputHandler.ShowFlashScreen();
            OutputHandler.ShowHeader();

            Level gamelevel = Level.Easy;

            string[] userSetUp = InputHandler.GetNameFromUser();
            switch (userSetUp[2])
            {
            case "h":
                gamelevel = Level.Hard;
                break;

            case "m":
                gamelevel = Level.Medium;
                break;

            default:
                gamelevel = Level.Easy;
                break;
            }

            _gm.Player1.Name      = userSetUp[0];
            _gm.Player1.IsPC      = false;
            _gm.Player1.Win       = 0;
            _gm.Player1.GameLevel = gamelevel;

            _gm.Player2.Name      = userSetUp[1];
            _gm.Player2.Win       = 0;
            _gm.Player2.GameLevel = gamelevel;

            //vs Computer
            if (userSetUp[1] == "")
            {
                _gm.Player2.Name = "Computer";
                _gm.Player2.IsPC = true;
            }
        }
예제 #6
0
 public static void ResetScreen(Player[] player)
 {
     Console.Clear();
     OutputHandler.ShowHeader();
     OutputHandler.ShowAllPlayer(player);
 }