示例#1
0
        //Attempt to move the player
        public static void Move(MoveCommand direction)
        {
            InventoryView = false;          //Disable inventory view
            MapDraw       = true;           //Request a fresh map draw

            //Get a list of the entities at the goal position
            List <Entity> goalSquareEntities = MainBoard.GetFromBoard(new Coordinate(Player.position.x + direction.x, Player.position.y + direction.y));

            //If there is something impassable there, fail the move
            if (goalSquareEntities != null && goalSquareEntities.Exists(x => x.Passable == false))
            {
                WriteLine("Can't walk there!");
                return;
            }

            //If you fail a combat check (can't beat an aggressor in the square), fail the move.
            if (!CombatCheck(goalSquareEntities))
            {
                return;
            }

            //Remove the player from its current coordinates, update the position, readd it to the coordinate map.
            MainBoard.entityPos[Player.position].Remove(Player);
            Player.position.x += direction.x;
            Player.position.y += direction.y;
            MainBoard.AddToBoard(Player);

            //Call a cleanup function to remove any dead entities and their inventories if the inventories are empty, and clear their
            //coordinates from the map if there are no more entities there.
            CleanUp(MainBoard);

            //Attempt to generate monsters, likelihood increases with distance from (0,0) (Bugged to not do it in the right way)
            MonsterGen(direction, Player.DistanceFromCenter());

            //List the entities you see in your new square
            foreach (Entity ent in EntityManager.GetLocalEntities(Player, MainBoard).FindAll(x => (x.Name != "Player")))
            {
                WriteLine("You see a " + ent.Name + ent.Status + "\b");
            }
        }
示例#2
0
        //Creates a randomly generated enemy
        public static void EnemyMake(Coordinate pos)
        {
            var EnemyTypes = new List <Type>();                             //Will store potential enemy types

            Type[] types = Assembly.GetExecutingAssembly().GetTypes();      //Get thetypes from the current assembly
            foreach (Type type in types)
            {
                if (type.IsSubclassOf(typeof(Enemy)))
                {
                    EnemyTypes.Add(type);                                   //Add the enemies to the list
                }
            }
            var r          = new Random();
            string entType = EnemyTypes[r.Next(EnemyTypes.Count)].Name;     //Get the name of a random enemy type
            string name;

            do
            {
                EntityNum++;
                name = entType + " " + EntityNum.ToString();                //Generate a unique name from the type + the incrementing entitynum
            }while (GetEntity(name) != null);

            char icon = (char)547;                                                                               //Set the icon

            int drawPriority = 99;                                                                               //Set the drawpriority

            Inventory inventory = GenerateInv();                                                                 //Set the inventory to a randomly generated on

            int hp = 5 + r.Next(0, 20);                                                                          //Set a random hp between 5 and 25

            int[] stats = { hp, hp, r.Next(1), 1 + r.Next(2), -1 };                                              //Set some random stats

            string description = "A fearsome enemy!";                                                            //Set a generic description

            dynamic enemy = EntityCreate(entType, name, pos, icon, drawPriority, inventory, stats, description); //Create the enemy from the data

            GoldMerge(enemy);                                                                                    //Merge any multiple gold items in the enemy's inventory

            MainBoard.AddToBoard(enemy);                                                                         //Add the enemy to the board.
        }