Пример #1
0
        static void Main(string[] args)
        {
            Console.BufferHeight = Console.WindowHeight = 25;
            Console.BufferWidth = Console.WindowWidth = 80;
            int[,] matrix = new int[20, 40];
            Array.Clear(matrix, 0, matrix.Length);

            List<Aliens> All = new List<Aliens>();
            List<Rock> allRocks = new List<Rock>();
            string[] lines = System.IO.File.ReadAllLines(@"C:\Users\Ivko_N76\Desktop\DataBase.txt");

            foreach (string value in lines)
            {
                string[] temp = value.Split(',');
                All.Add(new Aliens(int.Parse(temp[0]), int.Parse(temp[1]), temp[2]));
            }

            string[] lines1 = System.IO.File.ReadAllLines(@"C:\Users\Ivko_N76\Desktop\Rocks.txt");

            foreach (string value in lines1)
            {
                string[] temp = value.Split(',');
                allRocks.Add(new Rock(int.Parse(temp[0]), int.Parse(temp[1])));
            }
            //Read From file

            Hero c = new Hero(10, 15);
            c.placeInGrid(matrix);
            Upgrade up = new Upgrade(10, 16);
            up.PlaceInGrid(matrix);

            foreach (Aliens value in All)
            {
                value.placeInGrid(matrix);
            }

            foreach (Rock value in allRocks)
            {
                value.placeInGrid(matrix);
            }
            int count = 0;
            Console.WriteLine(printGrid(matrix));
            while (count < 20)
            {
                int heromove = c.heroMoves;

                for (int i = 0; i < heromove; i++)
                {
                    Console.SetCursorPosition(50, 10);
                    Console.WriteLine("Moves:{0}/{1}", i + 1, heromove);

                    ConsoleKeyInfo userInput = Console.ReadKey();

                    if (userInput.Key == ConsoleKey.LeftArrow && c.y >= 1)
                    {
                        c.Move(0, -1, matrix);
                        up.HeroUpgradePickup(c, matrix);

                    }
                    if (userInput.Key == ConsoleKey.RightArrow && c.y <= Console.BufferWidth - 1)
                    {
                        c.Move(0, 1, matrix);
                        up.HeroUpgradePickup(c, matrix);
                    }
                    if (userInput.Key == ConsoleKey.UpArrow && c.x >= 1)
                    {
                        c.Move(-1, 0, matrix);
                        up.HeroUpgradePickup(c, matrix);
                    }
                    if (userInput.Key == ConsoleKey.DownArrow && c.x < Console.BufferHeight - 1)
                    {
                        c.Move(1, 0, matrix);
                        up.HeroUpgradePickup(c, matrix);
                    }
                    if (userInput.Key == ConsoleKey.Spacebar)
                    {
                        c.Move(0, 0, matrix);
                    }
                    if (userInput.Key == ConsoleKey.Z && matrix[0,0] == 0 )
                    {
                        Aliens newAlien = c.NewAlien();
                        newAlien.placeInGrid(matrix);
                        All.Add(newAlien);
                        Console.WriteLine(printGrid(matrix));
                    }

                }
                foreach (Aliens value in All)
                {
                    value.zombieMove(c, matrix);
                    if (value.Lose(c) == 1)
                    {
                        Console.WriteLine(count);
                        return;
                    }
                }
                count++;
            }
            if (count > 20)
            {
                Console.Clear();
                Console.WriteLine("You have escape");
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            Console.BufferHeight = Console.WindowHeight = 25;
            Console.BufferWidth  = Console.WindowWidth = 80;
            int[,] matrix        = new int[20, 40];
            Array.Clear(matrix, 0, matrix.Length);


            List <Aliens> All      = new List <Aliens>();
            List <Rock>   allRocks = new List <Rock>();

            string[] lines = System.IO.File.ReadAllLines(@"C:\Users\Ivko_N76\Desktop\DataBase.txt");

            foreach (string value in lines)
            {
                string[] temp = value.Split(',');
                All.Add(new Aliens(int.Parse(temp[0]), int.Parse(temp[1]), temp[2]));
            }

            string[] lines1 = System.IO.File.ReadAllLines(@"C:\Users\Ivko_N76\Desktop\Rocks.txt");

            foreach (string value in lines1)
            {
                string[] temp = value.Split(',');
                allRocks.Add(new Rock(int.Parse(temp[0]), int.Parse(temp[1])));
            }
            //Read From file


            Hero c = new Hero(10, 15);

            c.placeInGrid(matrix);
            Upgrade up = new Upgrade(10, 16);

            up.PlaceInGrid(matrix);

            foreach (Aliens value in All)
            {
                value.placeInGrid(matrix);
            }

            foreach (Rock value in allRocks)
            {
                value.placeInGrid(matrix);
            }
            int count = 0;

            Console.WriteLine(printGrid(matrix));
            while (count < 20)
            {
                int heromove = c.heroMoves;

                for (int i = 0; i < heromove; i++)
                {
                    Console.SetCursorPosition(50, 10);
                    Console.WriteLine("Moves:{0}/{1}", i + 1, heromove);

                    ConsoleKeyInfo userInput = Console.ReadKey();

                    if (userInput.Key == ConsoleKey.LeftArrow && c.y >= 1)
                    {
                        c.Move(0, -1, matrix);
                        up.HeroUpgradePickup(c, matrix);
                    }
                    if (userInput.Key == ConsoleKey.RightArrow && c.y <= Console.BufferWidth - 1)
                    {
                        c.Move(0, 1, matrix);
                        up.HeroUpgradePickup(c, matrix);
                    }
                    if (userInput.Key == ConsoleKey.UpArrow && c.x >= 1)
                    {
                        c.Move(-1, 0, matrix);
                        up.HeroUpgradePickup(c, matrix);
                    }
                    if (userInput.Key == ConsoleKey.DownArrow && c.x < Console.BufferHeight - 1)
                    {
                        c.Move(1, 0, matrix);
                        up.HeroUpgradePickup(c, matrix);
                    }
                    if (userInput.Key == ConsoleKey.Spacebar)
                    {
                        c.Move(0, 0, matrix);
                    }
                    if (userInput.Key == ConsoleKey.Z && matrix[0, 0] == 0)
                    {
                        Aliens newAlien = c.NewAlien();
                        newAlien.placeInGrid(matrix);
                        All.Add(newAlien);
                        Console.WriteLine(printGrid(matrix));
                    }
                }
                foreach (Aliens value in All)
                {
                    value.zombieMove(c, matrix);
                    if (value.Lose(c) == 1)
                    {
                        Console.WriteLine(count);
                        return;
                    }
                }
                count++;
            }
            if (count > 20)
            {
                Console.Clear();
                Console.WriteLine("You have escape");
            }
        }