예제 #1
0
        public void GenerateBonus(GraphicalObjectContainer graphicalObjects)
        {
            if (this.BonusGeneratorTimer.ElapsedMilliseconds > BonusGenerationInterval)
            {
                Random randomGenerator = new Random();

                bool generationOnAnEmptySpaceSuccessful = false;

                byte potentialXposition = 0;
                byte potentialYposition = 0;

                while (!generationOnAnEmptySpaceSuccessful)
                {
                    generationOnAnEmptySpaceSuccessful = true;

                    potentialXposition = (byte)randomGenerator.Next(1, Console.BufferWidth - 2);
                    potentialYposition = (byte)randomGenerator.Next(1, Console.BufferHeight - 2);

                    List <GraphicalObject> currentGraphicalObjects = graphicalObjects.GetAll();

                    for (int i = 0; i < currentGraphicalObjects.Count; i++)
                    {
                        if (currentGraphicalObjects[i].Xposition == potentialXposition &&
                            currentGraphicalObjects[i].Yposition == potentialYposition)
                        {
                            generationOnAnEmptySpaceSuccessful = false;
                            break;
                        }
                    }
                }

                switch (this.currentBonusToGenerate)
                {
                case Bonus.Heart:
                    graphicalObjects.Bonuses.Add(new HealthBonus(potentialXposition, potentialYposition, ConsoleColor.Red, 20));
                    this.currentBonusToGenerate = Bonus.Shield;
                    break;

                case Bonus.Shield:
                    graphicalObjects.Bonuses.Add(new ShieldBonus(potentialXposition, potentialYposition, ConsoleColor.Yellow, 10));
                    this.currentBonusToGenerate = Bonus.Ammo;
                    break;

                case Bonus.Ammo:
                    graphicalObjects.Bonuses.Add(new AmmoBonus(potentialXposition, potentialYposition, ConsoleColor.White, 20));
                    this.currentBonusToGenerate = Bonus.Tron;
                    break;

                case Bonus.Tron:
                    graphicalObjects.Bonuses.Add(new TronBonus(potentialXposition, potentialYposition, ConsoleColor.Cyan));
                    this.currentBonusToGenerate = Bonus.Heart;
                    break;

                default:
                    break;
                }

                this.BonusGeneratorTimer.Restart();
            }
        }
예제 #2
0
        private static void FindEmptySpace(GraphicalObjectContainer graphicalObjects, out byte potentialXposition, out byte potentialYposition)
        {
            Random randomGenerator = new Random();

            bool generationOnAnEmptySpaceSuccessful = false;

            potentialXposition = 0;
            potentialYposition = 0;

            while (!generationOnAnEmptySpaceSuccessful)
            {
                generationOnAnEmptySpaceSuccessful = true;

                potentialXposition = (byte)randomGenerator.Next(1, Console.BufferWidth - 2);
                potentialYposition = (byte)randomGenerator.Next(1, Console.BufferHeight - 2);

                List <GraphicalObject> currentGraphicalObjects = graphicalObjects.GetAll();

                for (int i = 0; i < currentGraphicalObjects.Count; i++)
                {
                    if (currentGraphicalObjects[i].Xposition == potentialXposition &&
                        currentGraphicalObjects[i].Yposition == potentialYposition)
                    {
                        generationOnAnEmptySpaceSuccessful = false;
                        break;
                    }
                }
            }
        }