Exemplo n.º 1
0
        public void AddUnit(Players playerId, Vector2 position, UnitTypes name, float rot = 0f, int health = 0)
        {
            IUnit unit;

            switch (name)
            {
            case UnitTypes.Arrow:
                unit = new Arrow(playerId, position, rot, mGridSize, position);
                break;

            case UnitTypes.Swordsman:
                unit = new Swordsman(playerId, position, rot, mGridSize);
                break;

            case UnitTypes.Cavalry:
                unit = new Cavalry(playerId, position, rot, mGridSize);
                break;

            case UnitTypes.Hero:
                var hero = new Hero(playerId, position, rot, mGridSize, mContent);
                unit = hero;
                HeroesByPlayer[playerId] = hero;
                break;

            case UnitTypes.Bowman:
                unit = new Bowman(playerId, position, rot, mGridSize);
                break;

            case UnitTypes.BatteringRam:
                unit = new BatteringRam(playerId, position, rot, mGridSize);
                break;

            default:
                return;
            }

            if (unit is IDamageableUnit damageableUnit && health != 0)
            {
                damageableUnit.Health = health;
            }

            if (!UnitsByPlayer.ContainsKey(playerId))
            {
                UnitsByPlayer.Add(playerId, new List <IUnit>());
            }

            UnitsByPlayer[playerId].Add(unit);
            if (unit.UnitType == UnitTypes.Hero || unit.UnitType == UnitTypes.Swordsman || unit.UnitType == UnitTypes.Cavalry ||
                unit.UnitType == UnitTypes.BatteringRam || unit.UnitType == UnitTypes.Bowman)
            {
                StatisticsByPlayer[playerId]["CreateTroops"] += 1;
            }
            if (!UnitsByModel.ContainsKey(unit.ModelType))
            {
                UnitsByModel.Add(unit.ModelType, new List <IUnit>());
            }

            UnitsByModel[unit.ModelType].Add(unit);
        }
Exemplo n.º 2
0
        public void AddHero(Players playerId, Vector2 pos, float rot, int mana, int health, LevelManager levelManager, SkillManager skillManager)
        {
            var hero = new Hero(playerId, pos, rot, mGridSize, mana, health, levelManager, skillManager, mContent);

            HeroesByPlayer[playerId] = hero;
            if (!UnitsByPlayer.ContainsKey(playerId))
            {
                UnitsByPlayer.Add(playerId, new List <IUnit>());
            }

            UnitsByPlayer[playerId].Add(hero);
            StatisticsByPlayer[playerId]["CreateTroops"] += 1;
            if (!UnitsByModel.ContainsKey(hero.ModelType))
            {
                UnitsByModel.Add(hero.ModelType, new List <IUnit>());
            }

            UnitsByModel[hero.ModelType].Add(hero);
        }