Ejemplo n.º 1
0
        public void CreateObstacles()
        {
            int boxCount = 0;
            int rand;

            for (int y = 0; y < boardInfo.height; y++)
            {
                if (boxCount == boardInfo.nBoxes)
                {
                    break;
                }

                for (int x = 0; x < boardInfo.width; x++)
                {
                    if (boxCount == boardInfo.nBoxes)
                    {
                        break;
                    }

                    if (nodes[x, y] != null)
                    {
                        placementChance = Functions.GetPlacementChance(x, y, boardInfo.width, boardInfo.height, boardInfo.nBoxes);
                        rand            = RNG.Next(100);

                        //it's not the first or last line/collumn
                        if (y != boardInfo.height - 1 && y > 0 &&
                            x > 0 && x != boardInfo.width - 1)
                        {
                            //if there's 2 free nodes next to the box (above and below)
                            if (nodes[x, y + 1] != null && nodes[x, y - 1] != null &&
                                nodes[x, y + 1].isEmpty && nodes[x, y - 1].isEmpty &&
                                rand > placementChance)
                            {
                                CreateBox(x, y, ref boxCount);
                            }

                            else if (BoardInfo.nDirections == 6)
                            {
                                rand = RNG.Next(100);

                                if (rand > placementChance)
                                {
                                    //check the first diagonals - free nodes to the upper right/lower left
                                    //&& check the second diagonals - free nodes to the lower right/upper left
                                    if ((nodes[x + 1, y] != null && nodes[x - 1, y - 1] != null &&
                                         nodes[x + 1, y].isEmpty && nodes[x - 1, y - 1].isEmpty) ||
                                        (nodes[x + 1, y - 1] != null && nodes[x - 1, y] != null &&
                                         nodes[x + 1, y - 1].isEmpty && nodes[x - 1, y].isEmpty))
                                    {
                                        CreateBox(x, y, ref boxCount);
                                    }
                                }
                            }
                        }

                        //if this is a 4 direction board, the box can be placed on a node as long as it can be pushed to the right/left
                        else if ((x != 0 || y != 0) && (BoardInfo.nDirections == 4 || BoardInfo.nDirections == 8))
                        {
                            rand = RNG.Next(100);
                            if (BoardInfo.nDirections == 8)
                            {
                                rand -= 20;
                            }

                            //it's not the first or last column
                            if (x != boardInfo.width - 1 && x != 0 &&
                                rand > placementChance)
                            {
                                //if there's 2 free nodes next to the box (to the right and left)
                                if (nodes[x + 1, y] != null && nodes[x - 1, y] != null &&
                                    nodes[x + 1, y].isEmpty && nodes[x - 1, y].isEmpty)
                                {
                                    CreateBox(x, y, ref boxCount);
                                }
                            }
                        }

                        //we're in the 4 extreme lines/collumns
                        //else
                        //{
                        //    rand = RNG.Next(100);

                        //    CreateBox(x, y, ref boxCount);
                        //}
                    }
                }
            }

            //Update the nBoxes var so there aren't too many win objects for the amount of boxes
            boardInfo.nBoxes = boxCount;
        }
Ejemplo n.º 2
0
        //Creates all enemy objects
        public void CreateEnemyObjects()
        {
            int objCount = 0;
            int rand;

            for (int y = 0; y < boardInfo.height; y++)
            {
                if (objCount < boardInfo.nEnemies)
                {
                    for (int x = 0; x < boardInfo.width; x++)
                    {
                        if (objCount < boardInfo.nEnemies)
                        {
                            if (nodes[x, y] != null)
                            {
                                placementChance = Functions.GetPlacementChance(x, y, boardInfo.width, boardInfo.height, boardInfo.nEnemies);
                                rand            = RNG.Next(100);

                                int winObjCount = 0;

                                foreach (WinObject winObj in winObjects)
                                {
                                    //if the node is taken by a winObject, jump to the next node
                                    if (nodes[x, y].position == winObj.position)
                                    {
                                        break;
                                    }

                                    winObjCount++;
                                }

                                if (rand > placementChance)
                                {
                                    if (winObjCount == winObjects.Count &&
                                        nodes[x, y].isEmpty &&
                                        (x != 0 || y != 0) &&
                                        !(x == 1 || y == 0) &&
                                        !(x == 1 || y == 1))
                                    {
                                        //create and place the spikes
                                        Spike spike = new Spike(game);
                                        spike.position = nodes[x, y].position;
                                        bool error = false;

                                        //confirms if the enemy is separated from the other enemies by at least X units
                                        foreach (EnemyObject enemy in enemyObjects)
                                        {
                                            if (Math.Abs(enemy.position.X - spike.position.X) < 2 &&
                                                Math.Abs(enemy.position.Y - spike.position.Y) < 2)
                                            {
                                                error = true;
                                                break;
                                            }
                                        }

                                        //Place the spike
                                        if (!error)
                                        {
                                            rand = RNG.Next(100);
                                            if (rand > 30)
                                            {
                                                enemyObjects.Add(spike);
                                            }
                                            else
                                            {
                                                Vector2 dir = new Vector2(0, 1);
                                                if (rand <= 15 && x != boardInfo.width - 1)
                                                {
                                                    dir = new Vector2(0, -1);
                                                }

                                                MovableEnemy movingEnemy = new MovableEnemy(nodes[x, y].position, 3, "Copycat", dir);
                                                enemyObjects.Add(movingEnemy);
                                            }
                                            objCount++;
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                else
                {
                    break;
                }
            }
        }
Ejemplo n.º 3
0
        //Creates win objects
        public void CreateWinObjects()
        {
            int objCount         = 0;
            int CollectibleCount = 0;
            int rand;

            //go through the nodes
            for (int y = 0; y < boardInfo.height; y++)
            {
                if (CollectibleCount == boardInfo.nCollectibles &&
                    objCount == boardInfo.nBoxes)
                {
                    break;
                }

                for (int x = 0; x < boardInfo.width; x++)
                {
                    rand = RNG.Next(100);

                    if (CollectibleCount == boardInfo.nCollectibles &&
                        objCount == boardInfo.nBoxes)
                    {
                        break;
                    }

                    if (nodes[x, y] != null && !(x == 0 && y == 0))
                    {
                        //place Collectible
                        if (CollectibleCount < boardInfo.nCollectibles && rand > 50)
                        {
                            if (nodes[x, y].isEmpty)
                            {
                                bool canPlace = true;

                                foreach (WinObject c in winObjects)
                                {
                                    //if there's already a collectible in that cell, it can't be used again
                                    if (c.tag == "Collectible" &&
                                        (c.position.X == x || c.position.Y == y))
                                    {
                                        canPlace = false;
                                        break;
                                    }
                                }

                                //the node cell is empty
                                if (canPlace)
                                {
                                    Collectible winObject = new Collectible(game);
                                    winObject.position = nodes[x, y].position;
                                    winObjects.Add(winObject);
                                    CollectibleCount++;
                                }
                            }
                        }
                        //while there's still Toggles to place
                        else if (objCount < boardInfo.nBoxes)
                        {
                            placementChance = Functions.GetPlacementChance(x, y, boardInfo.width, boardInfo.height, boardInfo.nBoxes);
                            rand            = RNG.Next(100);

                            foreach (Obstacle obstacle in obstacles)
                            {
                                //if there's a box in an extreme line, put a toggle nearby
                                if (nodes[x, y].isEmpty && y == obstacle.position.Y &&
                                    (y == boardInfo.height - 1 || (y == 0 && x != 0)) && x != obstacle.position.X)
                                {
                                    //create and place the object
                                    Toggle winObject = new Toggle(game);
                                    winObject.position = nodes[x, y].position;
                                    bool canCreate = true;

                                    foreach (WinObject obj in winObjects)
                                    {
                                        if (winObject.tag == obj.tag &&
                                            ((winObject.position.X == obj.position.X && Math.Abs(winObject.position.Y - obj.position.Y) < 3) ||
                                             (winObject.position.Y == obj.position.Y && Math.Abs(winObject.position.X - obj.position.X) < 3)))
                                        {
                                            canCreate = false;
                                        }
                                    }

                                    if (canCreate)
                                    {
                                        winObjects.Add(winObject);
                                        objCount++;
                                        break;
                                    }
                                }

                                //if there's a box in an extreme collumn, put a toggle nearby
                                else if (nodes[x, y].isEmpty && x == obstacle.position.X &&
                                         (x == boardInfo.width - 1 || (x == 0 && y != 0)) && y != obstacle.position.Y)
                                {
                                    //create and place the object
                                    Toggle winObject = new Toggle(game);
                                    winObject.position = nodes[x, y].position;
                                    winObjects.Add(winObject);
                                    objCount++;
                                    break;
                                }

                                //if the node is not a hole and the random rolls over 30
                                //and there's a box in the same line or column but not on the same cell
                                else if (nodes[x, y].isEmpty &&
                                         ((x == obstacle.position.X && x != 0) || (y == obstacle.position.Y && y != 0)) &&
                                         rand > placementChance)
                                {
                                    //create and place the object
                                    Toggle winObject = new Toggle(game);
                                    winObject.position = nodes[x, y].position;
                                    winObjects.Add(winObject);
                                    objCount++;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
 public RNG(Int32 seed)
 {
     rng   = new Random(seed);
     rngen = this;
 }