Beispiel #1
0
        static void Main(string[] args)
        {
            DoAI();

            var grid = new Grid();

            while (!grid.AllShipsDestroyed)
            {
                grid.DisplayGrid(true);
                string x; string y;
                do
                {
                    Console.WriteLine("Enter coordinates (x, y):");
                    Console.Write("(");
                    x = Console.ReadKey().KeyChar.ToString();
                    Console.Write(", ");
                    y = Console.ReadKey().KeyChar.ToString();
                    Console.Write(")");
                    Console.WriteLine();
                } while (!("0123456789".Contains(x) && "0123456789".Contains(y)));

                if ("asdfsdf".All(char.IsDigit))
                {

                }
                int aNumber = 0;
                if (!int.TryParse(Console.ReadLine(), out aNumber))
                {

                }

                grid.Target(int.Parse(x), int.Parse(y));
            }

            grid.DisplayGrid();
            Console.WriteLine();
            Console.WriteLine("YOU WON!!!!!!!!!! YEAH!");
            Console.WriteLine();

            Console.ReadKey();
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            DoAI();


            var grid = new Grid();

            while (!grid.AllShipsDestroyed)
            {
                grid.DisplayGrid(true);
                string x; string y;
                do
                {
                    Console.WriteLine("Enter coordinates (x, y):");
                    Console.Write("(");
                    x = Console.ReadKey().KeyChar.ToString();
                    Console.Write(", ");
                    y = Console.ReadKey().KeyChar.ToString();
                    Console.Write(")");
                    Console.WriteLine();
                } while (!("0123456789".Contains(x) && "0123456789".Contains(y)));

                if ("asdfsdf".All(char.IsDigit))
                {
                }
                int aNumber = 0;
                if (!int.TryParse(Console.ReadLine(), out aNumber))
                {
                }

                grid.Target(int.Parse(x), int.Parse(y));
            }

            grid.DisplayGrid();
            Console.WriteLine();
            Console.WriteLine("YOU WON!!!!!!!!!! YEAH!");
            Console.WriteLine();

            Console.ReadKey();
        }
Beispiel #3
0
        public void TurnLoop()
        {
            Console.WriteLine(Player1.PlayerName + "'s turn.");
            Console.WriteLine("Your Grid: ");
            P1Grid.DisplayGrid();
            Console.WriteLine("Enemy Grid: ");
            P1PreviewGrid.DisplayGrid();
            PrintScore(Player1);

            PlayerShoot(Player1, P2Grid, P1PreviewGrid);
            if (Player1.DownedShips.Count == 4)
            {
                return;
            }
            P1PreviewGrid.DisplayGrid();

            Console.WriteLine("Press ENTER for the next player's turn");
            Console.ReadLine();
            Console.Clear();

            Console.WriteLine(Player2.PlayerName + "'s turn.");
            Console.WriteLine("Your Grid: ");
            P2Grid.DisplayGrid();
            Console.WriteLine("Enemy Grid: ");
            P2PreviewGrid.DisplayGrid();
            PrintScore(Player2);

            PlayerShoot(Player2, P1Grid, P2PreviewGrid);
            if (Player2.DownedShips.Count == 4)
            {
                return;
            }
            P2PreviewGrid.DisplayGrid();

            Console.WriteLine("Press ENTER for the next player's turn");
            Console.ReadLine();
            Console.Clear();
        }
Beispiel #4
0
        public void Setup()
        {
            Console.WriteLine("What will player 1's name be? Type below a name under 10 characters.");
            Player1.PlayerName = Player1.NamePlayer();

            Console.WriteLine("What will player 2's name be? Type below a name under 10 characters.");
            Player2.PlayerName = Player2.NamePlayer();

            P1Grid.MakeNewGrid();
            P2Grid.MakeNewGrid();

            BlankGrid.MakeNewGrid();

            P1PreviewGrid.MakeNewGrid();
            P2PreviewGrid.MakeNewGrid();

            P1Grid.DisplayGrid();
            ShipSetup(Player1, P1Grid);

            P2Grid.DisplayGrid();
            ShipSetup(Player2, P2Grid);

            Console.WriteLine("");
        }
Beispiel #5
0
        public void ShipSetup(Player Player, Grid Grid)
        {
            Submarine       Sub = new Submarine();
            Destroyer       Des = new Destroyer();
            Battleship      Bat = new Battleship();
            AircraftCarrier Air = new AircraftCarrier();

            for (int i = 0; i < 4; i++)
            {
                if (i == 0)
                {
                    int[] originCords = new int[2] {
                        1, 1
                    };

                    while (Sub.Authorize() == false)
                    {
                        Console.Clear();
                        Sub.ShipPlace(originCords, Grid);
                        Grid.DisplayGrid();
                        Grid.AssembleYard();
                        Console.WriteLine("-- " + Player.PlayerName + "'s setup phase --");
                        Console.WriteLine("Press Enter to place your ship.");
                        Console.WriteLine("Press the arrow keys to move your ship.");
                        ErrorCheck(Sub, Des, Bat, Air);
                        Sub.ShipMove(originCords, Grid, Console.ReadKey().Key);
                        Sub.Authorize();
                    }
                    Console.Clear();
                    Sub.ShipPlace(originCords, Grid);
                    Grid.DisplayGrid();
                }
                else if (i == 1)
                {
                    int[] originCords = new int[2] {
                        1, 1
                    };

                    while (Des.Authorize() == false)
                    {
                        Console.Clear();
                        Des.ShipPlace(originCords, Grid);
                        Grid.DisplayGrid();
                        Grid.AssembleYard();
                        Console.WriteLine("-- " + Player.PlayerName + "'s setup phase --");
                        Console.WriteLine("Press Enter to place your ship.");
                        Console.WriteLine("Press the arrow keys to move your ship.");
                        ErrorCheck(Sub, Des, Bat, Air);
                        Des.ShipMove(originCords, Grid, Console.ReadKey().Key);
                        Des.Authorize();
                    }
                    Console.Clear();
                    Des.ShipPlace(originCords, Grid);
                    Grid.DisplayGrid();
                }
                else if (i == 2)
                {
                    int[] originCords = new int[2] {
                        1, 1
                    };

                    while (Bat.Authorize() == false)
                    {
                        Console.Clear();
                        Bat.ShipPlace(originCords, Grid);
                        Grid.DisplayGrid();
                        Grid.AssembleYard();
                        Console.WriteLine("-- " + Player.PlayerName + "'s setup phase --");
                        Console.WriteLine("Press Enter to place your ship.");
                        Console.WriteLine("Press the arrow keys to move your ship.");
                        ErrorCheck(Sub, Des, Bat, Air);
                        Bat.ShipMove(originCords, Grid, Console.ReadKey().Key);
                        Bat.Authorize();
                    }
                    Console.Clear();
                    Bat.ShipPlace(originCords, Grid);
                    Grid.DisplayGrid();
                }
                else if (i == 3)
                {
                    int[] originCords = new int[2] {
                        1, 1
                    };

                    while (Air.Authorize() == false)
                    {
                        Console.Clear();
                        Air.ShipPlace(originCords, Grid);
                        Grid.DisplayGrid();
                        Grid.AssembleYard();
                        Console.WriteLine("-- " + Player.PlayerName + "'s setup phase --");
                        Console.WriteLine("Press Enter to place your ship.");
                        Console.WriteLine("Press the arrow keys to move your ship.");
                        ErrorCheck(Sub, Des, Bat, Air);
                        Air.ShipMove(originCords, Grid, Console.ReadKey().Key);
                        Air.Authorize();
                    }
                    Console.Clear();
                    Air.ShipPlace(originCords, Grid);
                    Grid.DisplayGrid();
                }
            }
            Console.Clear();
        }