public override Collectable[] GenerateCollectables(int count)
        {
            Random randomCoordinatesGenerator = new Random(DateTime.Now.Millisecond);
            int    nextX = 0;
            int    nextY = 0;

            Collectable[] collectables = new BonusCollectable[count];
            for (int i = 0; i < count; i++)
            {
                nextX = randomCoordinatesGenerator.Next(1, 140);
                nextY = randomCoordinatesGenerator.Next(1, 35);
                if (GameField.matrix[nextY, nextX].Equals("█"))
                {
                    bool isEqual;
                    do
                    {
                        nextX   = randomCoordinatesGenerator.Next(1, 140);
                        nextY   = randomCoordinatesGenerator.Next(1, 35);
                        isEqual = GameField.matrix[nextY, nextX].Equals("█");
                    } while (isEqual);
                }
                collectables[i] = new BonusCollectable(nextX, nextY);
            }

            return(collectables);
        }
Exemple #2
0
        public static void Main()
        {
            int bufferHeight = 40;
            int bufferWidth  = 170;

            // Setting the parameters of the Console
            Console.BufferHeight  = bufferHeight;
            Console.BufferWidth   = bufferWidth;
            Console.WindowHeight  = bufferHeight;
            Console.WindowWidth   = bufferWidth;
            Console.CursorVisible = false;
            GameField gameField = new GameField();

            List <Enemy> dragons = new List <Enemy>()
            {
                new DragonEnemy(),
                new DragonEnemy(),
                new DragonEnemy(),
                new DragonEnemy(),
                new DragonEnemy(),
                new DragonEnemy(),
                new DragonEnemy(),
                new DragonEnemy(),
                new DragonEnemy()
            };

            for (int col = 0; col < GameField.matrix.GetLength(0); col++)
            {
                for (int row = 0; row < GameField.matrix.GetLength(1); row++)
                {
                    Console.Write(GameField.matrix[col, row]);
                }
                Console.WriteLine();
            }

            Gate gate = new Gate(33, 1, "R", ConsoleColor.Red);

            gate.DrawGate();

            Collectable[] healthCollectables     = new HealthCollectable(0, 0).GenerateCollectables(5);
            Collectable[] experienceCollectables = new ExperienceCollectable(0, 0).GenerateCollectables(5);
            Collectable[] gunCollectables        = new BombCollectable(0, 0).GenerateCollectables(5);
            Collectable[] bonusCollectables      = new BonusCollectable(0, 0).GenerateCollectables(5);

            Collectable[][] allCollectables = { healthCollectables, experienceCollectables, gunCollectables, bonusCollectables };

            for (int i = 0; i < allCollectables.Length; i++)
            {
                for (int j = 0; j < allCollectables[i].Length; j++)
                {
                    allCollectables[i][j].drawCollectable();
                }
            }
            Player tempPlayer = new Player();

            tempPlayer.DrawPlayer();
            SideInfo.PrintInfo();
            while (tempPlayer.isAlive)
            {
                tempPlayer.MovePlayer();
                foreach (Enemy dragon in dragons)
                {
                    dragon.MoveEnemy();
                    tempPlayer.ChekForEnemy();
                }
            }

            SideInfo.GameOver();
        }