Ejemplo n.º 1
0
        /// <summary>
        /// Method to spawn level NPCs
        /// </summary>
        public void SpawnNPC()
        {
            // Initialise the maximum number of NPCs. It increases with level
            int maxNPCsForLevel =
                (int)ProcGenFunctions.Logistic(Level, 20d, 10d, 0.3d);
            // Set the number of NPCs for the current level.
            // It's random between 0 and the maximum number of NPCs.
            int numberOfNPCs = rnd.Next(maxNPCsForLevel + 1);

            // Repeat spawn for the number of NPCs of level
            for (int i = 0; i < numberOfNPCs; i++)
            {
                // Create variables row and columns
                int row;
                int column;
                // Do cycle while tile of row and column contains exit
                do
                {
                    // Define row and column for current NPC
                    row    = rnd.Next(8);
                    column = rnd.Next(8);
                } while (GameGrid[row, column].Contains(Exit));
                // Define position to give to NPC
                Position pos = new Position(row, column);
                // Add NPC to tile
                GameGrid[row, column].AddObject(new NPC(pos, this));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Method to spawn level traps.
        /// </summary>
        public void SpawnTraps()
        {
            // Initialise the maximum number of traps. It increases with level
            int maxTrapsPerLevel =
                (int)ProcGenFunctions.Logistic(Level, 20d, 10d, 0.3d);
            // Set the number of traps for the current level.
            // It's random between 0 and the maximum number of traps.
            int numberOfTraps = rnd.Next(maxTrapsPerLevel + 1);

            // Repeat spawn for the number of traps of level
            for (int i = 0; i < numberOfTraps; i++)
            {
                // Create variables row and columns
                int row;
                int column;
                // Do cycle while the position chosen for the trap is the same
                // as the exit
                do
                {
                    // Define row and column for current NPC
                    row    = rnd.Next(8);
                    column = rnd.Next(8);
                } while (GameGrid[row, column].Contains(Exit));

                // Initialise trap in a random position
                Trap trap = new Trap();
                // Add trap to grid
                GameGrid[row, column].AddObject(trap);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Constructor to Initialise all properties.
        /// </summary>
        /// <param name="pos">Player position.</param>
        /// <param name="grid">Game Grid.</param>
        public NPC(Position pos, GridManager grid)
        {
            // Initialise Max Attack Power for level. It increases with level
            MaxAPForThisLevel =
                ProcGenFunctions.Logistic(grid.Level, 100d, 20d, 0.1d);

            // Initialise Max HP for level. It increases with level
            MaxHPForThisLevel =
                ProcGenFunctions.Logistic(grid.Level, 100d, 20d, 0.1d);

            // Initialise Hostile Probability for level. It increases with level
            HostileProbabilityForThisLevel =
                ProcGenFunctions.Logistic(grid.Level, 1d, 20d, 0.1d);

            // Initialise NPC Type according to Hostile Probability for level
            NpcType = rnd.NextDouble() < HostileProbabilityForThisLevel
                ? StateOfNpc.Enemy : StateOfNpc.Neutral;

            // Initialise NPC Position
            Pos = pos;

            // Set Attack Power for level
            AP = rnd.NextDouble() * MaxAPForThisLevel;
            // Set HP for level
            HP = rnd.NextDouble() * MaxHPForThisLevel;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Method to spawn level items.
        /// </summary>
        public void SpawnItems()
        {
            // Initialise the maximum number of items. It decreases with level
            int maxItensPerLevel =
                (int)ProcGenFunctions.Logistic(Level, 30d, 10d, -0.3d);
            // Set the number of items for the current level.
            // It's random between 0 and the maximum number of items.
            int numberOfItens = rnd.Next(maxItensPerLevel + 1);

            // Repeat spawn for the number of items of level
            for (int i = 0; i < numberOfItens; i++)
            {
                // Create variables row and columns
                int row;
                int column;
                // Do cycle while the position chosen for the trap is the same
                // as the exit
                do
                {
                    // Define row and column for current NPC
                    row    = rnd.Next(8);
                    column = rnd.Next(8);
                } while (GameGrid[row, column].Contains(Exit));

                // 50% probability that item is food
                if (rnd.NextDouble() < 0.5d)
                {
                    // Create and Initialise food
                    Item item = new Food();
                    // Add food to tile
                    GameGrid[row, column].AddObject(item);
                }
                // 50% probability that item is a weapon
                else
                {
                    // Create and Initialise weapon
                    Item item = new Weapon();
                    // Add weapon to tile
                    GameGrid[row, column].AddObject(item);
                }
            }
        }