Exemple #1
0
        /// <summary>
        /// Adds some bugs into the stage.
        /// </summary>
        public void AddBugs(int howMany)
        {
            // Loop through the bugs
            for (int i = 0; i < howMany; i++)
            {
                // Create a bug
                Bug bug = new Bug();

                // Place the bug
                while (true)
                {
                    // Find a random location
                    int col = Entropy.Next(0, Columns);
                    int row = Entropy.Next(0, Constants.BoardRows);
                    BlockStack stack = this[col, row];

                    // Go through the stack, looking for bugs
                    float immobilePosition = 0;
                    bool foundGround = false;
                    bool validStack = false;

                    foreach (Block block in stack)
                    {
                        // Don't bother if we already have a bug here
                        if (block.Sprite.ID == Constants.BugBlockName)
                        {
                        }

                        // Make sure we have at least one land block
                        else if (IsGroundBlock(block))
                        {
                            foundGround = true;
                        }

                        // If we have an immobile, keep it
                        else if (block.Sprite.ID ==
                            Constants.ImmobileBlockName)
                        {
                            immobilePosition =
                                Math.Max(block.TopPosition, immobilePosition);
                            validStack = true;
                        }

                        // Not valid, a character or someting
                        else
                        {
                            validStack = false;
                            break;
                        }
                    }

                    // See if we have a valid one
                    if (!validStack || !foundGround)
                        continue;

                    // Put the bug in
                    bug.BottomPosition = immobilePosition;
                    bug.X = col;
                    bug.Y = row;
                    bug.BlockStack = stack;
                    stack.Add(bug);
                    stack.Sort();
                    Game.State.Bugs.Add(bug);
                    break;
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Adds some bugs into the stage.
        /// </summary>
        public void AddBugs(int howMany)
        {
            // Loop through the bugs
            for (int i = 0; i < howMany; i++)
            {
                // Create a bug
                Bug bug = new Bug();

                // Place the bug
                while (true)
                {
                    // Find a random location
                    int        col   = Entropy.Next(0, Columns);
                    int        row   = Entropy.Next(0, Constants.BoardRows);
                    BlockStack stack = this[col, row];

                    // Go through the stack, looking for bugs
                    float immobilePosition = 0;
                    bool  foundGround      = false;
                    bool  validStack       = false;

                    foreach (Block block in stack)
                    {
                        // Don't bother if we already have a bug here
                        if (block.Sprite.ID == Constants.BugBlockName)
                        {
                        }

                        // Make sure we have at least one land block
                        else if (IsGroundBlock(block))
                        {
                            foundGround = true;
                        }

                        // If we have an immobile, keep it
                        else if (block.Sprite.ID ==
                                 Constants.ImmobileBlockName)
                        {
                            immobilePosition =
                                Math.Max(block.TopPosition, immobilePosition);
                            validStack = true;
                        }

                        // Not valid, a character or someting
                        else
                        {
                            validStack = false;
                            break;
                        }
                    }

                    // See if we have a valid one
                    if (!validStack || !foundGround)
                    {
                        continue;
                    }

                    // Put the bug in
                    bug.BottomPosition = immobilePosition;
                    bug.X          = col;
                    bug.Y          = row;
                    bug.BlockStack = stack;
                    stack.Add(bug);
                    stack.Sort();
                    Game.State.Bugs.Add(bug);
                    break;
                }
            }
        }