示例#1
0
        /// <summary>
        /// Initializes the game world by creating a new map, player and enemy.
        /// </summary>
        public void Create(Size size)
        {
            Size = size;
            Map = new Map(size.Width / GridSize + 1, size.Height / GridSize + 1);

            player = new Player(Map.CellCenter(new Point(0, 0)));
            enemy = new Enemy(Map.RandomFreePosition(), new MoveLogicRandom());
            Entities.Add(enemy);
            Entities.Add(player);
            Created = true;
        }
示例#2
0
        public void Create(Size size, int NumberOfEnemies, string AI)
        {
            Entities.Clear();
            Size = size;
            Map = new Map(size.Width / GridSize + 1, size.Height / GridSize + 1);

            player = new Player(Map.CellCenter(new Point(0, 0)));
            Entities.Add(player);
            if (AI == "LogicRandom")
            {
                for (int i = 0; i < NumberOfEnemies; i++)
                {
                    enemy = new Enemy(Map.RandomFreePosition(), new MoveLogicRandom());
                    Entities.Add(enemy);
                }
            }
            if (AI == "AiMoveSpeedy")
            {
                for (int i = 0; i < NumberOfEnemies; i++)
                {
                    enemy = new Enemy(Map.RandomFreePosition(), new AIMove());
                    Entities.Add(enemy);
                }
            }
            if(AI == "Random")
            {
                for (int i = 0; i < NumberOfEnemies; i++)
                {
                    if (random.Next(0, 1) == 0)
                    {
                        enemy = new Enemy(Map.RandomFreePosition(), new MoveLogicRandom());
                    }
                    else
                    {
                        enemy = new Enemy(Map.RandomFreePosition(), new AIMove());
                    }
                    Entities.Add(enemy);
                }

            }

            Created = true;
        }
示例#3
0
文件: World.cs 项目: Hugomka/SE2Game
        /// <summary>
        /// Initializes the game world by creating a new map, player and enemy.
        /// </summary>
        /// <param name="size">The size of the map.</param>
        /// <param name="enemyCount">The number of enemies to create.</param>
        /// <param name="moveLogic">The AI to use, or null for random AI.</param>
        /// <param name="createNewMap">Create a new map, or reuse the current map.</param>
        public void Create(Size size, int enemyCount, Type moveLogic, bool createNewMap, string filePath)
        {
            // Prevent sprite jumps when restarting
            prevTime = 0;

            // Create a new map if needed
            Size = size;

            if(filePath != null)
            {
                Map = new Map(filePath);
            }
            else if (Map == null || createNewMap)
            {
                Map = new Map(size.Width / GridSize + 1, size.Height / GridSize + 1, createNewMap);
            }

            // Create a new player, always in the top left corner
            player = new Player(Map.CellCenter(new Point(0, 0)));

            // Create the enemies, using either a given AI or a random one
            enemies = new List<Enemy>();
            List<Type> availableMoveLogic = Util.AvailableMoveLogics();
            for (int x = 0; x < enemyCount; x++)
            {
                // Add the enemies, using a random AI if requested
                IMoveLogic newMoveLogic;
                if (moveLogic == null)
                {
                    int r = World.Instance.RandomNumber(availableMoveLogic.Count);
                    newMoveLogic = Util.NewMoveLogic(availableMoveLogic[r]);
                }
                else
                {
                    newMoveLogic = Util.NewMoveLogic(moveLogic);
                }
                enemies.Add(new Enemy(Map.RandomFreePosition(), newMoveLogic));
            }

            // Create the pickups
            pickups = new List<Item>();
            pickups.Add(new Key(Map.RandomFreePosition()));
            pickups.Add(new Helmet(Map.RandomFreePosition()));
            pickups.Add(new Boots(Map.RandomFreePosition()));

            Created = true;
        }