Inheritance: NetworkBehaviour
    public void CreateBigUFOShip()
    {
        UnitFactory unitFactory  = new UnitFactory();

        Unit unit = unitFactory.makeUnit("B", false);

        Assert.IsInstanceOf<BigUFOShip>(unit);
    }
    public void CreateRocketShip()
    {
        UnitFactory unitFactory  = new UnitFactory();

        Unit unit = unitFactory.makeUnit("R", false);

        Assert.IsInstanceOf<RocketShip>(unit);
    }
Ejemplo n.º 3
0
 void Awake()
 {
     if (instance == null)
     {
         _instance = this;
     }
     else
         Destroy(gameObject);
 }
Ejemplo n.º 4
0
        static void Main()
        {
            var buildingFactory = new BuildingFactory();
            var unitFactory = new UnitFactory();
            var resourceFactory = new ResourceFactory();
            var reader = new ConsoleReader();
            var writer = new ConsoleWriter();
            var data = new EmpiresData();

            var engine = new Engine(buildingFactory,resourceFactory,unitFactory,data,reader,writer);
            engine.Run();
        }
Ejemplo n.º 5
0
        public static void Main(string[] args)
        {
            IBuildingFactory buildingFactory = new BuildingFactory();
            IUnitFactory unitFactory = new UnitFactory();
            IResourceFactory resourceFactory = new ResourceFactory();
            IInputReader reader = new ConsoleReader();
            IOutputWriter writer = new ConsoleWriter();
            IEmpiresData database = new Database();

            IEngine engine = new Engine(unitFactory, resourceFactory, buildingFactory, reader, writer, database);
            engine.Run();
        }
Ejemplo n.º 6
0
	public UnitFactory() {
		instance = this;
		creationTable = new Dictionary<string, System.Func<GameObject>>();
		creationTable.Add("commander", createCircleUnit);
		creationTable.Add("construction", createConstructionGuy);
		creationTable.Add("normandy",createNormandy);
		creationTable.Add("lambo",createLambo);
		creationTable.Add("centurion",createCenturion);
		creationTable.Add("predator",createPredator);
		creationTable.Add("healer",createHealer);
		creationTable.Add("archer", createArcher);
        creationTable.Add("wizard", createWizard);
	}
Ejemplo n.º 7
0
        public override void Execute(params string[] commandParams)
        {
            int numberOfUnits = int.Parse(commandParams[0]);

            if (numberOfUnits < 0)
            {
                throw new ArgumentOutOfRangeException("Number of units should be non-negative");
            }

            string cityName = commandParams[2];
            var city = this.Engine.Continent.GetCityByName(cityName);

            if (city == null)
            {
                throw new ArgumentNullException();
            }

            string unitType = commandParams[1];
            var factory = new UnitFactory();
            var units = factory.CreateUnits(unitType, numberOfUnits);
            
            if (city.AvailableUnitCapacity(units.First().Type) < 
                    units.Sum(u => u.HousingSpacesRequired))
            {
                throw new InvalidOperationException(string.Format(
                    "City {0} does not have enough housing spaces to accommodate {1}" +
                    " units of {2}",
                    cityName,
                    numberOfUnits,
                    unitType));
            }

            if (city.ControllingHouse.TreasuryAmount < units.Sum(u => u.TrainingCost))
            {
                throw new InvalidOperationException(string.Format(
                    "House {0} does not have enough funds to train {1} units of {2}",
                    city.ControllingHouse.Name,
                    numberOfUnits,
                    unitType));
            }

            city.AddUnits(units);
            city.ControllingHouse.TreasuryAmount -= units.Sum(u => u.TrainingCost);

            this.Engine.Render(
                "Successfully added {0} units of {1} to city {2}",
                numberOfUnits,
                unitType,
                cityName);
        }
Ejemplo n.º 8
0
        public StrongholdCombatUnit(uint id,
                                    uint battleId,
                                    ushort type,
                                    byte lvl,
                                    ushort count,
                                    IStronghold stronghold,
                                    decimal leftOverHp,
                                    UnitFactory unitFactory,
                                    IBattleFormulas battleFormulas,
                                    Formula formula,
                                    IDbManager dbManager)
            : base(id, battleId, battleFormulas, dbManager)
        {
            Stronghold       = stronghold;
            this.type        = type;
            this.count       = count;
            this.unitFactory = unitFactory;
            this.lvl         = lvl;
            LeftOverHp       = leftOverHp;
            this.formula     = formula;

            stats = new BattleStats(unitFactory.GetUnitStats(type, lvl).Battle);
        }
Ejemplo n.º 9
0
    public void Init(WeaponMesh mesh)
    {
        if (current != null)
        {
            Destroy(current.AttachmentLeft);
            Destroy(current.AttachmentRight);
            Destroy(current.gameObject);
        }

        /*
         * if(m_Animator != null)
         * {
         *  caster.OnAbilityTrigger -= m_Animator.AbilityCallback;
         *  caster.OnWeaponHide -= m_Animator.WeaponHide;
         *  caster.OnWeaponShow -= m_Animator.WeaponShow;
         * }*/
        AnimationCallbackCaster caster = TargetUnit.GetComponent <AnimationCallbackCaster>();

        current = UnitFactory.SpawnWeaponMeshToUnit(TargetUnit, mesh);

        // UnitAnimation_IdleController idle = mesh.GetComponent<UnitAnimation_IdleController>();
        m_Animator = UnitFactory.MakeUnitAnimations(TargetUnit, current, current.WeaponIndex, caster, () => { return(IsRaged); });
    }
Ejemplo n.º 10
0
    void SpawnTestUnits()
    {
        string[] recipes = new string[]
        {
            "Alaois",
            "Hania",
            "Kamau",
            "Enemy Rogue",
            "Enemy Warrior",
            "Enemy Wizard"
        };

        GameObject unitContainer = new GameObject("Units");

        unitContainer.transform.SetParent(owner.transform);

        List <Tile> locations = new List <Tile>(board.tiles.Values);

        for (int i = 0; i < recipes.Length; ++i)
        {
            int        level    = UnityEngine.Random.Range(9, 12);
            GameObject instance = UnitFactory.Create(recipes[i], level);
            instance.transform.SetParent(unitContainer.transform);

            int  random     = UnityEngine.Random.Range(0, locations.Count);
            Tile randomTile = locations[random];
            locations.RemoveAt(random);

            Unit unit = instance.GetComponent <Unit>();
            unit.Place(randomTile);
            unit.dir = (Directions)UnityEngine.Random.Range(0, 4);
            unit.Match();

            units.Add(unit);
        }
        //SelectTile(units[0].tile.pos);
    }
Ejemplo n.º 11
0
        public CityPassiveAction(IObjectTypeFactory objectTypeFactory,
                                 ILocker locker,
                                 Formula formula,
                                 IActionFactory actionFactory,
                                 Procedure procedure,
                                 IGameObjectLocator locator,
                                 IBattleFormulas battleFormulas,
                                 IStructureCsvFactory structureFactory,
                                 TechnologyFactory technologyFactory,
                                 UnitFactory unitFactory)
        {
            this.objectTypeFactory = objectTypeFactory;
            this.locker            = locker;
            this.formula           = formula;
            this.actionFactory     = actionFactory;
            this.procedure         = procedure;
            this.locator           = locator;
            this.battleFormulas    = battleFormulas;
            this.structureFactory  = structureFactory;
            this.technologyFactory = technologyFactory;
            this.unitFactory       = unitFactory;

            CreateSubscriptions();
        }
Ejemplo n.º 12
0
        private static List <Unit> GenerateAndAddCompanies(int numberOfCompanies, PersonalLegacyContext context)
        {
            var companies = UnitFactory.GetCompanyFactory(_regionIdHardcoded)
                            .Generate(numberOfCompanies);

            context.Units.AddRange(companies);
            context.SaveChanges();
            var unitContentBooks = companies.SelectMany(c => new List <UnitContentBook>
            {
                new UnitContentBook {
                    UnitId = c.Id, ContentBookId = 1
                },
                new UnitContentBook {
                    UnitId = c.Id, ContentBookId = 2
                },
                new UnitContentBook {
                    UnitId = c.Id, ContentBookId = 8
                },
            });

            context.UnitContentBooks.AddRange(unitContentBooks);
            context.SaveChanges();
            return(companies);
        }
Ejemplo n.º 13
0
        public void CreateFarmerTest()
        {
            Assert.Throws <Exception>(() => UnitFactory.CreateUnit(typeof(Farmer)));
            FarmerUnitRegister visitor = new FarmerUnitRegister();

            UnitFactory.AddFactory(visitor);
            var unit = UnitFactory.CreateUnit(typeof(Farmer));

            Assert.IsType <Farmer>(unit);
            var farmer = unit as Farmer;

            Assert.Equal(1, farmer.FoodNeeded);
            Assert.Equal(Satisfaction.Ok, farmer.Satisfaction);
            Assert.Equal(5, farmer.MaxInput);
            Assert.Equal(3, farmer.InputOutputMapping.Count);
            Assert.Equal(2, farmer.InputOutputMapping["cow"].Count);
            Assert.Single(farmer.InputOutputMapping["cow"].Where(r => r.Type == "meat" && r.Amount == 2));
            Assert.Single(farmer.InputOutputMapping["cow"].Where(r => r.Type == "milk" && r.Amount == 2));
            Assert.Single(farmer.InputOutputMapping["pig"]);
            Assert.Single(farmer.InputOutputMapping["pig"].Where(r => r.Type == "meat" && r.Amount == 4));
            Assert.Equal(2, farmer.InputOutputMapping["chicken"].Count);
            Assert.Single(farmer.InputOutputMapping["chicken"].Where(r => r.Type == "meat" && r.Amount == 2));
            Assert.Single(farmer.InputOutputMapping["chicken"].Where(r => r.Type == "egg" && r.Amount == 2));
        }
Ejemplo n.º 14
0
 public PlayerCommandLineModule(IPlayersRemoverFactory playerRemoverFactory,
                                IPlayerSelectorFactory playerSelectorFactory,
                                ICityRemoverFactory cityRemoverFactory,
                                Chat chat,
                                IDbManager dbManager,
                                ITribeManager tribeManager,
                                IWorld world,
                                ILocker locker,
                                IStructureCsvFactory structureFactory,
                                UnitFactory unitFactory,
                                TechnologyFactory technologyFactory)
 {
     this.playerRemoverFactory  = playerRemoverFactory;
     this.playerSelectorFactory = playerSelectorFactory;
     this.cityRemoverFactory    = cityRemoverFactory;
     this.chat              = chat;
     this.dbManager         = dbManager;
     this.tribeManager      = tribeManager;
     this.world             = world;
     this.locker            = locker;
     this.structureFactory  = structureFactory;
     this.unitFactory       = unitFactory;
     this.technologyFactory = technologyFactory;
 }
Ejemplo n.º 15
0
        public static void CreatePlayer(this UnitFactory factory, GameObject gameObject)
        {
            var moduleMgr           = WorldManager.Instance.Module;
            var requiredModuleGroup = moduleMgr.TagToModuleGroupType(Constant.OBJECT_MODULE_GROUP_NAME)
                                      | moduleMgr.TagToModuleGroupType(Constant.CONTROL_MODULE_GROUP_NAME)
                                      | moduleMgr.TagToModuleGroupType(Constant.STATE_MODULE_GROUP_NAME)
                                      | moduleMgr.TagToModuleGroupType(Constant.SYNC_MODULE_GROUP_NAME);

            var unit = factory.CreateAsset(requiredModuleGroup, gameObject);

            unit.AddData <ObjectSyncData>();

            factory.InitBuffModuleList();

            AttachStateData(unit);
            AttachAttributeData(unit);
            AttachControlData(unit);
            AttachKeyboardControlData(unit);
            AttachBuffData(unit);

            var unitData = unit.GetData <UnitData>();

            unitData.stateTypeProperty.Value = UnitStateType.Init;
        }
Ejemplo n.º 16
0
 public SystemRepository()
 {
     _UnitFactory = new UnitFactory();
 }
Ejemplo n.º 17
0
 private void SpawnUnit()
 {
     UnitFactory.Create("mech");
 }
Ejemplo n.º 18
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            GraphicsDevice t = GraphicsDevice;

            // Create a new SpriteBatch, which can be used to draw textures.
            _spriteBatch = new SpriteBatch(GraphicsDevice);

            // Load the camera class
            _camera = new Camera(new Vector2(400, 300), 800, 600);

            // Check required resources exist

            var txPixel = new Texture2D(GraphicsDevice, 1, 1);

            txPixel.SetData(new[] { Color.White });

            //Content.RootDirectory = "Content";
            // load the map, get the map elements and load them
            Textures.Add(UnitsEnum.ADELAIDE, Content.Load <Texture2D>("Adelaide"));
            Textures.Add(UnitsEnum.TURRET, Content.Load <Texture2D>("Turret"));
            Textures.Add(UnitsEnum.RAPTOR, Content.Load <Texture2D>("Raptor"));
            Textures.Add(UnitsEnum.MISSILE, Content.Load <Texture2D>("Missile"));
            Textures.Add(UnitsEnum.CLOUD1, Content.Load <Texture2D>("Cloud11"));
            Textures.Add(UnitsEnum.CLOUD2, Content.Load <Texture2D>("Cloud15"));
            Textures.Add(UnitsEnum.CLOUD3, Content.Load <Texture2D>("Cloud3"));
            Textures.Add(UnitsEnum.WATER1, Content.Load <Texture2D>("Water1"));
            Textures.Add(UnitsEnum.WATERBUMP1, Content.Load <Texture2D>("WaterBump1"));

            // Load the map class
            _map             = new Map(2, 2);
            _map.Wind        = new Vector2(0.3f, 0.2f);
            _map.Tiles[0, 0] = new Tile(Textures[UnitsEnum.WATER1])
            {
                Bumpmap = Textures[UnitsEnum.WATERBUMP1]
            };
            _map.Tiles[1, 0] = new Tile(Textures[UnitsEnum.WATER1])
            {
                Bumpmap = Textures[UnitsEnum.WATERBUMP1]
            };
            _map.Tiles[0, 1] = new Tile(Textures[UnitsEnum.WATER1])
            {
                Bumpmap = Textures[UnitsEnum.WATERBUMP1]
            };
            _map.Tiles[1, 1] = new Tile(Textures[UnitsEnum.WATER1])
            {
                Bumpmap = Textures[UnitsEnum.WATERBUMP1]
            };
            _map.Tiles[0, 0].UpdateBumpmap();


            //Load units data
            var ud = new UnitData
            {
                Position = new Vector2(0, 0),
                //Destination = new List<UnitData> {new Vector2(150, 200)};
                Destination = new List <UnitData> {
                    new UnitData {
                        Position = new Vector2(10, 10)
                    }
                }
            };

            var ud2 = new UnitData
            {
                Position = new Vector2(400, 250),
                //Destination = new List<Vector2> {new Vector2(200, 550)}
                //Destination = new List<UnitData> { new UnitData { Position = new Vector2(100, 55) } }
                MovementMode = MovementMode.PATROL,
            };

            //var ud3 = new UnitData
            //{
            //    Position = new Vector2(1000, 1000),
            //    MovementMode = MovementMode.INTERCEPT,
            //    Timeout = 2000,
            //    Timer = new System.Diagnostics.Stopwatch(),
            //};
            //ud3.Timer.Start();

            //Load each unit into memory
            //_units.Add(UnitFactory.New(UnitsEnum.ADELAIDE, ud));
            _units.Add(UnitFactory.New(UnitsEnum.RAPTOR, ud));
            _units.Add(UnitFactory.New(UnitsEnum.ADELAIDE, ud2));
            //_units.Add(UnitFactory.New(UnitsEnum.MISSILE, ud3));
        }
Ejemplo n.º 19
0
 public void SetTestingFactory(UnitFactory factory)
 {
     //_dataContext = new FactoryDataContext();
     _dataContext.Builder = factory;
     _dataContext.Builder.FactoryStatus += Builder_FactoryProgress;
 }
Ejemplo n.º 20
0
    public void FixedUpdate()
    {
        if (factory == null)
            factory = GameObject.Find("GameManager").GetComponent<UnitFactory>();

        if (!isLocalPlayer)
            return;

        if (!gameOver) {
            string endText = "";
            if (health <= 0) { health = 0;
                endText = "Game Over! \n You Lose.";
            } else if (opponent != null && opponent.GetComponent<Player>().health <= 0) {
                opponent.GetComponent<Player>().health = 0;
                endText = "Game Over! \n You Win.";
            }

            if (endText.Length > 0) {
                GameObject.Find("WaitingPanel").transform.position = new Vector3();
                GameObject.Find("WaitingPanel").transform.FindChild("Text").GetComponent<Text>().text = endText;
                gameOver = true;

                foreach (GameObject go in GameObject.FindGameObjectsWithTag("Tile")) {
                    Destroy(go);
                }
            }
            updateUI();
        }
    }
Ejemplo n.º 21
0
        public void FarmTest()
        {
            Farm    farm    = new Farm(1, 2);
            Builder builder = (Builder)UnitFactory.CreateUnit(typeof(Builder));
            Farmer  farmer  = (Farmer)UnitFactory.CreateUnit(typeof(Farmer));

            Assert.False(farm.AbleToFunction);
            Assert.Equal(2, farm.BuildingTime);
            Assert.Equal(0, farm.BuildProgress);
            Assert.Equal(0, farm.CurrentCapacity);
            Assert.Equal(1, farm.MaxCapacity);
            Assert.Equal(0, farm.CurrentConstructionUnitCount);
            Assert.Single(farm.UnitTypes);
            Assert.Single(farm.UnitTypes.Where(u => u == typeof(Farmer)));

            farm.DoBuildProcess();
            Assert.Equal(0, farm.BuildProgress);

            farm.AddConstructionUnit(builder);
            Assert.Equal(1, farm.CurrentConstructionUnitCount);
            farm.DoBuildProcess();
            Assert.Equal(1, farm.BuildProgress);
            Assert.False(farm.AbleToFunction);

            farm.DoBuildProcess();
            Assert.Equal(2, farm.BuildProgress);
            Assert.True(farm.AbleToFunction);

            farm.AssignUnit(farmer);
            Assert.Equal(1, farm.CurrentCapacity);
            var resources = farm.DoWork();

            Assert.NotNull(resources);
            Assert.Empty(resources);

            farm.AddInput(new ResourceAmount("cow", 3));
            resources = farm.DoWork();
            Assert.Equal(2, resources.Count);
            Assert.Single(resources.Where(r => r.Type == "meat"));
            Assert.Single(resources.Where(r => r.Type == "meat" && r.Amount == 6)); //3 cow -> 2*3
            Assert.Single(resources.Where(r => r.Type == "milk"));
            Assert.Single(resources.Where(r => r.Type == "milk" && r.Amount == 6));

            resources = farm.DoWork();
            Assert.NotNull(resources);
            Assert.Empty(resources);

            farm.AddInput(new ResourceAmount("cow", 2));
            farm.RemoveInput(new ResourceAmount("cow", 2));
            Assert.NotNull(resources);
            Assert.Empty(resources);

            farm.AddInput(new ResourceAmount("cow", 2));
            farm.RemoveInput(new ResourceAmount("cow", 1));
            resources = farm.DoWork();
            Assert.Equal(2, resources.Count);
            Assert.Single(resources.Where(r => r.Type == "meat"));
            Assert.Single(resources.Where(r => r.Type == "meat" && r.Amount == 2));
            Assert.Single(resources.Where(r => r.Type == "milk"));
            Assert.Single(resources.Where(r => r.Type == "milk" && r.Amount == 2));
        }
Ejemplo n.º 22
0
 public void SetTestingFactory(UnitFactory factory)
 {
     _dataContext.Builder = factory; /***** casting *****/
     //_dataContext.Builder.FactoryProgress += Builder_FactoryProgress;
     _dataContext.Builder.FactoryProgress += Builder_FactoryProgress;
 }
 void Awake()
 {
     unitFactory = new UnitFactory();
 }
Ejemplo n.º 24
0
        public void LoadContent(int levelValue)
        {
            _levelValue  = levelValue;
            _currentWave = -1;
            _waveTimer   = 5000;
            // Load the enemies into the unit list
            List <Tuple <string, int> > list = LoadFromFile();

            foreach (Tuple <string, int> val in list)
            {
                string type = val.Item1;
                int    num  = val.Item2;

                switch (type)
                {
                case "---":
                    _waves.Add(new Wave(++_currentWave, _numLanes, FIELD_SIZE, FIELD_ORIGIN));
                    break;

                case "WeakMelee":
                    for (int i = 0; i < num; i++)
                    {
                        _waves[_currentWave].AddUnit(UnitFactory.CreateWeakMelee());
                    }
                    break;

                case "MediumMelee":
                    for (int i = 0; i < num; i++)
                    {
                        _waves[_currentWave].AddUnit(UnitFactory.CreateMediumMelee());
                    }
                    break;

                case "StrongMelee":
                    for (int i = 0; i < num; i++)
                    {
                        _waves[_currentWave].AddUnit(UnitFactory.CreateStrongMelee());
                    }
                    break;

                case "WeakRanged":
                    for (int i = 0; i < num; i++)
                    {
                        _waves[_currentWave].AddUnit(UnitFactory.CreateWeakRanged());
                    }
                    break;

                case "MediumRanged":
                    for (int i = 0; i < num; i++)
                    {
                        _waves[_currentWave].AddUnit(UnitFactory.CreateMediumRanged());
                    }
                    break;

                case "StrongRanged":
                    for (int i = 0; i < num; i++)
                    {
                        _waves[_currentWave].AddUnit(UnitFactory.CreateStrongRanged());
                    }
                    break;

                default:
                    throw new ArgumentException("you cant spell for shit");
                }
            }
            _currentWave = -1;

            foreach (Wave w in _waves)
            {
                w.LoadContent();
            }
        }
Ejemplo n.º 25
0
        IEnumerator Start()
        {
            #region Config

            log.Info("\n\nStart");
            var units                 = new UnitInfoLoader().Load();
            var saveDataLoader        = new SaveInfoLoader();
            var saves                 = saveDataLoader.Load();
            var decisionTreeLoader    = new DecisionTreeLoader();
            var decisionTreeComponent = decisionTreeLoader.Load();

            #endregion
            #region Infrastructure

            var tickController  = new TickController();
            var inputController = new InputController(tickController);
            //TODO: implement event bus that won't allocate(no delegates)
            var eventBus = new EventBus();            //TODO: stop using eventbus Ievent interface to remove reference on that library from model
            EventBus.Log     = m => log.Info($"{m}"); //TODO: remove that lmao
            EventBus.IsLogOn = () => DebugController.Info.IsDebugOn;

            #endregion
            #region View

            var mainCamera                  = Camera.main;
            var tileSpawner                 = new TilePresenter(TileStartPoints, new TileViewFactory(TileViewPrefab));
            var coordFinder                 = new CoordFinder(TileStartPoints);
            var unitViewFactory             = new UnitViewFactory(units, UnitViewPrefab, coordFinder, mainCamera);
            var unitViewCoordChangedHandler = new UnitViewCoordChangedHandler(coordFinder);
            var boardPresenter              = new BoardPresenter(unitViewCoordChangedHandler);

            var playerPresenterContext = new PlayerPresenterContext(
                new PlayerPresenter(unitViewFactory, unitViewCoordChangedHandler),
                new PlayerPresenter(unitViewFactory, unitViewCoordChangedHandler));

            #endregion
            #region Model
            var decisionTreeLookup = new DecisionTreeLookup();

            var decisionTreeCreatorVisitor = new DecisionTreeCreatorVisitor(eventBus,
                                                                            d => new LoggingDecorator(d, DebugController.Info), decisionTreeLookup);

            var unitFactory = new UnitFactory(units, new DecisionFactory(
                                                  decisionTreeCreatorVisitor, decisionTreeComponent));

            //TODO: replace board/bench dictionaries with array?
            var playerContext = new PlayerContext(new Player(unitFactory), new Player(unitFactory));
            var board         = new Board();
            var aiHeap        = new AiHeap();
            var aiContext     = new AiContext(board, aiHeap);

            #endregion
            #region Shared

            var worldContext = new PlayerSharedContext(playerContext, playerPresenterContext, BattleSetupUI);

            #endregion
            #region Controller

            var raycastController = new RaycastController(mainCamera,
                                                          LayerMask.GetMask("Terrain", "GlobalCollider"), LayerMask.GetMask("Unit"));

            var unitSelectionController = new UnitSelectionController(inputController,
                                                                      raycastController, coordFinder);

            var unitTooltipController = new UnitTooltipController(UnitTooltipUI,
                                                                  unitSelectionController);

            #endregion
            #region Unit drag

            var battleStateController = new BattleStateController(BattleSimulationUI);
            var unitDragController    = new UnitDragController(raycastController,
                                                               new CoordFinderBySelectedPlayer(coordFinder, BattleSetupUI),
                                                               inputController, unitSelectionController,
                                                               new CanStartDrag(battleStateController, BattleSetupUI));

            var tileHighlightController = new TileHighlighterController(tileSpawner,
                                                                        unitDragController);

            var unitMoveController = new UnitMoveController(worldContext, unitDragController);

            #endregion
            #region Battle simulation

            var movementController  = new MovementController(boardPresenter, coordFinder);
            var attackController    = new AttackController(boardPresenter, unitTooltipController);
            var animationController = new AnimationController(boardPresenter);
            eventBus.Register <StartMoveEvent>(movementController, animationController); //TODO: register implicitly?
            eventBus.Register <FinishMoveEvent>(movementController);
            eventBus.Register <RotateEvent>(movementController);
            eventBus.Register <UpdateHealthEvent>(attackController);
            eventBus.Register <DeathEvent>(attackController);
            eventBus.Register <IdleEvent>(animationController);
            eventBus.Register <StartAttackEvent>(animationController);

            var battleSimulationPresenter = new BattleSimulationPresenter(coordFinder,
                                                                          boardPresenter, movementController, movementController);

            var battleSimulation = new BattleSimulation(aiContext, board, aiHeap);

            var realtimeBattleSimulationController = new RealtimeBattleSimulationController(
                movementController, battleSimulation);

            #endregion
            #region Debug

            var battleSimulationDebugController = new BattleSimulationDebugController(
                battleSimulation, BattleSimulationUI,
                aiContext, playerContext, playerPresenterContext, realtimeBattleSimulationController,
                battleSimulationPresenter);

            var battleSaveController = new BattleSaveController(playerContext,
                                                                playerPresenterContext, BattleSaveUI, saveDataLoader, saves,
                                                                battleSimulationDebugController);

            var battleSetupController = new BattleSetupController(playerContext,
                                                                  playerPresenterContext, BattleSetupUI);

            var unitModelDebugController = new UnitModelDebugController(playerContext, board, ModelUI,
                                                                        DebugController.Info, unitSelectionController);

            var takenCoordDebugController = new TakenCoordDebugController(board, DebugController,
                                                                          tileSpawner);

            var targetDebugController = new TargetDebugController(
                board, coordFinder, DebugController.Info);

            var uiDebugController = new UIDebugController(
                BattleSetupUI, BattleSaveUI, BattleSimulationUI,
                unitModelDebugController);

            #endregion

            yield return(null);

            #region Infrastructure

            tickController.InitObservable(takenCoordDebugController, targetDebugController,
                                          uiDebugController, unitModelDebugController, realtimeBattleSimulationController,
                                          DebugController); //TODO: register implicitly?
            inputController.InitObservables();

            #endregion
            #region View

            BattleSetupUI.SetDropdownOptions(units.Keys.ToList());
            BattleSaveUI.SubToUI(saves.Keys.ToList());
            tileSpawner.SpawnTiles();

            #endregion
            decisionTreeCreatorVisitor.Init();
            #region Controller

            unitSelectionController.SubToInput(disposable);
            battleStateController.SubToUI();
            unitDragController.SubToUnitSelection(disposable);
            tileHighlightController.SubToDrag(disposable);
            unitMoveController.SubToDrag(disposable);
            unitTooltipController.SubToUnitSelection(disposable);

            #endregion
            #region Debug

            battleSaveController.SubToUI();
            battleSetupController.SubToUI();
            unitModelDebugController.SubToUnitSelection(disposable);
            battleSimulationDebugController.SubToUI();
            DebugController.Init(UnitTooltipUI);

            #endregion

            MonoBehaviourCallBackController.StartUpdating(tickController);
        }
Ejemplo n.º 26
0
 void Start()
 {
     if (isServer) {
         unitFactory = gameObject.GetComponent<UnitFactory>();
         gruntPoolInitialised = false;
         numberOfHeros = 0;
     }
 }
Ejemplo n.º 27
0
 public override void Given()
 {
     subject = new UnitFactory();
 }
Ejemplo n.º 28
0
 protected Command(string[] data, UnitFactory unitFactory, IRepository unitRepository)
 {
     this.data           = data;
     this.unitFactory    = unitFactory;
     this.unitRepository = unitRepository;
 }
Ejemplo n.º 29
0
 public LogRepository()
 {
     _UnitFactory = new UnitFactory();
 }
Ejemplo n.º 30
0
        public void UpdateUnits()
        {
            Dictionary <double, double> clickedLocations = MouseCapture.getClicks();

            foreach (MovingUnit unit in _movingUnits)
            {
                foreach (KeyValuePair <double, double> coords in clickedLocations)
                {
                    unit.SetIsShot(coords);
                }
                unit.IsOutOfBounds(_yMaxBounds, _xMaxBounds);

                bool wasCollide = false;
                unit.MoveX();

                foreach (Unit nonMovingUnit in _nonMovingUnits)
                {
                    wasCollide = unit.CheckCollisionX(nonMovingUnit);
                }

                unit.MoveY();

                if (!wasCollide)
                {
                    foreach (Unit nonMovingUnit in _nonMovingUnits)
                    {
                        unit.CheckCollisionY(nonMovingUnit);
                    }
                }
            }

            MovingUnit newMovingUnit = null;
            // Add MovingUnit
            int randomNum = _random.Next(35);

            if (randomNum % 2 == 0 && _movingUnits.Count < this.MovingUnitAmount)
            {
                bool collides = true;
                while (collides)
                {
                    // set location
                    var xPos = _random.Next(_xMinBounds, _xMaxBounds);
                    var yPos = _random.Next(_yMinBounds, _yMaxBounds);

                    var unitType = (UnitEnum)_random.Next(2, 4);
                    newMovingUnit = (MovingUnit)UnitFactory.CreateUnit(unitType, xPos, yPos);

                    if (
                        !_nonMovingUnits.Any(
                            unit1 =>
                            xPos >= unit1.LeftPosition && xPos <= (unit1.LeftPosition + 50) &&
                            yPos >= unit1.TopPosition &&
                            yPos <= (unit1.TopPosition + 50)))
                    {
                        collides = false;
                    }
                }

                newMovingUnit.SetSteps(this.MinSpeed, this.MaxSpeed);
                _movingUnits.Add(newMovingUnit);
            }
        }
Ejemplo n.º 31
0
        public void ForestCampTest2()
        {
            ForestCamp forestCamp = new ForestCamp(5, 1);
            Builder    builder    = (Builder)UnitFactory.CreateUnit(typeof(Builder));
            Gatherer   gatherer   = (Gatherer)UnitFactory.CreateUnit(typeof(Gatherer));
            Gatherer   gatherer2  = (Gatherer)UnitFactory.CreateUnit(typeof(Gatherer));
            Gatherer   gatherer3  = (Gatherer)UnitFactory.CreateUnit(typeof(Gatherer));

            Assert.False(forestCamp.AbleToFunction);
            Assert.Equal(1, forestCamp.BuildingTime);
            Assert.Equal(0, forestCamp.BuildProgress);
            Assert.Equal(0, forestCamp.CurrentCapacity);
            Assert.Equal(5, forestCamp.MaxCapacity);
            Assert.Equal(0, forestCamp.CurrentConstructionUnitCount);
            Assert.Single(forestCamp.UnitTypes);
            Assert.Single(forestCamp.UnitTypes.Where(u => u == typeof(Gatherer)));

            forestCamp.AddConstructionUnit(builder);
            Assert.Equal(1, forestCamp.CurrentConstructionUnitCount);
            var removed = forestCamp.RemoveLastConstructionUnit();

            Assert.Equal(builder, removed);
            Assert.Equal(0, forestCamp.CurrentConstructionUnitCount);

            forestCamp.AddConstructionUnit(builder);
            Assert.Equal(1, forestCamp.CurrentConstructionUnitCount);
            forestCamp.DoBuildProcess();
            Assert.Equal(1, forestCamp.BuildProgress);
            Assert.True(forestCamp.AbleToFunction);

            forestCamp.AssignUnit(gatherer);
            Assert.Equal(1, forestCamp.CurrentCapacity);
            var resources = forestCamp.DoWork();

            Assert.NotNull(resources);
            Assert.NotEmpty(resources);
            Assert.Single(resources);
            Assert.Single(resources.Where(r => r.Type == "wood"));
            Assert.Single(resources.Where(r => r.Type == "wood" && r.Amount == 1));

            forestCamp.AssignUnit(gatherer2);
            Assert.Equal(2, forestCamp.CurrentCapacity);
            resources = forestCamp.DoWork();
            Assert.NotNull(resources);
            Assert.NotEmpty(resources);
            Assert.Single(resources);
            Assert.Single(resources.Where(r => r.Type == "wood"));
            Assert.Single(resources.Where(r => r.Type == "wood" && r.Amount == 2));

            forestCamp.AssignUnit(gatherer3);
            Assert.Equal(3, forestCamp.CurrentCapacity);
            resources = forestCamp.DoWork();
            Assert.NotNull(resources);
            Assert.NotEmpty(resources);
            Assert.Single(resources);
            Assert.Single(resources.Where(r => r.Type == "wood"));
            Assert.Single(resources.Where(r => r.Type == "wood" && r.Amount == 3));

            var unit = forestCamp.RemoveLastUnit();

            Assert.Equal(gatherer3, unit);
            Assert.Equal(2, forestCamp.CurrentCapacity);
            resources = forestCamp.DoWork();
            Assert.NotNull(resources);
            Assert.NotEmpty(resources);
            Assert.Single(resources);
            Assert.Single(resources.Where(r => r.Type == "wood"));
            Assert.Single(resources.Where(r => r.Type == "wood" && r.Amount == 2));
        }
Ejemplo n.º 32
0
        public override void InitLevel()
        {
            _mouseCapture = new MouseCapture(_playGrid);

            _xMaxBounds = (int)_playGrid.ActualWidth - 60;
            _xMinBounds = 10;

            _yMaxBounds = (int)_playGrid.ActualHeight - 60;
            _yMinBounds = 10;

            _unitsHit       = 0;
            _nonMovingUnits = new List <Unit>();
            _movingUnits    = new List <MovingUnit>();

            // set trees
            for (int t = 0; t < this.NonMovingUnitAmount; t++)
            {
                Application.Current.Dispatcher.Invoke(() =>
                {
                    // set location
                    // random based on x and y bounds
                    var xPos = (double)_random.Next(_xMinBounds, _xMaxBounds);
                    var yPos = (double)_random.Next(_yMinBounds, _yMaxBounds);

                    // Set tree on screen
                    Unit unit = UnitFactory.CreateUnit(UnitEnum.Tree, xPos, yPos);
                    _nonMovingUnits.Add(unit);
                });
            }

            // random amount MovingUnits
            int startAmountUnits = _random.Next(5);

            for (int x = 0; x < startAmountUnits; x++)
            {
                Application.Current.Dispatcher.Invoke(() =>
                {
                    MovingUnit unit = null;
                    bool collides   = true;
                    while (collides)
                    {
                        // set location
                        var xPos = _random.Next(_xMinBounds, _xMaxBounds);
                        var yPos = _random.Next(_yMinBounds, _yMaxBounds);

                        var unitType = (UnitEnum)_random.Next(2, 4);
                        unit         = (MovingUnit)UnitFactory.CreateUnit(unitType, xPos, yPos);

                        if (
                            !_nonMovingUnits.Any(
                                unit1 =>
                                xPos >= unit1.LeftPosition && xPos <= (unit1.LeftPosition + 50) &&
                                yPos >= unit1.TopPosition &&
                                yPos <= (unit1.TopPosition + 50)))
                        {
                            collides = false;
                        }
                    }

                    unit.SetSteps(this.MinSpeed, this.MaxSpeed);
                    _movingUnits.Add(unit);
                });
            }
        }
Ejemplo n.º 33
0
        public void LabTest()
        {
            Lab        lab        = new Lab(5, 2);
            Builder    builder    = (Builder)UnitFactory.CreateUnit(typeof(Builder));
            Researcher researcher = (Researcher)UnitFactory.CreateUnit(typeof(Researcher));

            Assert.False(lab.AbleToFunction);
            Assert.Equal(2, lab.BuildingTime);
            Assert.Equal(0, lab.BuildProgress);
            Assert.Equal(0, lab.CurrentCapacity);
            Assert.Equal(5, lab.MaxCapacity);
            Assert.Equal(0, lab.CurrentConstructionUnitCount);
            Assert.Single(lab.UnitTypes);
            Assert.Single(lab.UnitTypes.Where(u => u == typeof(Researcher)));

            lab.DoBuildProcess();
            Assert.Equal(0, lab.BuildProgress);

            lab.AddConstructionUnit(builder);
            Assert.Equal(1, lab.CurrentConstructionUnitCount);
            lab.DoBuildProcess();
            Assert.Equal(1, lab.BuildProgress);
            Assert.False(lab.AbleToFunction);

            lab.DoBuildProcess();
            Assert.Equal(2, lab.BuildProgress);
            Assert.True(lab.AbleToFunction);

            var resources = lab.DoWork();

            Assert.NotNull(resources);
            Assert.Empty(resources);

            lab.AssignUnit(researcher);
            Assert.Equal(1, lab.CurrentCapacity);
            resources = lab.DoWork();
            Assert.NotNull(resources);
            Assert.Single(resources);
            Assert.Single(resources.Where(r => r.Type == "researchpoint"));
            Assert.Single(resources.Where(r => r.Type == "researchpoint" && r.Amount == 1));

            //unlock
            researcher.UpgradeConverterOutputResource("ore");
            researcher.UpgradeConverterInputMapping("ore", new List <ResourceAmount>()
            {
                new ResourceAmount("ironore", 1)
            });
            resources = lab.DoWork();
            Assert.NotNull(resources);
            Assert.Single(resources);
            Assert.Single(resources.Where(r => r.Type == "researchpoint"));
            Assert.Single(resources.Where(r => r.Type == "researchpoint" && r.Amount == 1));

            //add input
            lab.AddInput(new ResourceAmount("ore", 2));
            resources = lab.DoWork();
            Assert.NotNull(resources);
            Assert.Equal(2, resources.Count);
            Assert.Single(resources.Where(r => r.Type == "researchpoint"));
            Assert.Single(resources.Where(r => r.Type == "researchpoint" && r.Amount == 1));
            Assert.Single(resources.Where(r => r.Type == "ironore"));
            Assert.Single(resources.Where(r => r.Type == "ironore" && r.Amount == 2));

            //unlock x2
            researcher.UpgradeConverterInputMapping("ore", new List <ResourceAmount>()
            {
                new ResourceAmount("goldore", 1)
            });
            lab.AddInput(new ResourceAmount("ore", 1));
            resources = lab.DoWork();
            Assert.NotNull(resources);
            Assert.Equal(3, resources.Count);
            Assert.Single(resources.Where(r => r.Type == "researchpoint"));
            Assert.Single(resources.Where(r => r.Type == "researchpoint" && r.Amount == 1));
            Assert.Single(resources.Where(r => r.Type == "ironore"));
            Assert.Single(resources.Where(r => r.Type == "ironore" && r.Amount == 1));
            Assert.Single(resources.Where(r => r.Type == "goldore"));
            Assert.Single(resources.Where(r => r.Type == "goldore" && r.Amount == 1));

            lab.AddInput(new ResourceAmount("ore", 3));
            lab.RemoveInput(new ResourceAmount("ore", 2));
            resources = lab.DoWork();
            Assert.NotNull(resources);
            Assert.Equal(3, resources.Count);
            Assert.Single(resources.Where(r => r.Type == "researchpoint"));
            Assert.Single(resources.Where(r => r.Type == "researchpoint" && r.Amount == 1));
            Assert.Single(resources.Where(r => r.Type == "ironore"));
            Assert.Single(resources.Where(r => r.Type == "ironore" && r.Amount == 1));
            Assert.Single(resources.Where(r => r.Type == "goldore"));
            Assert.Single(resources.Where(r => r.Type == "goldore" && r.Amount == 1));
        }
Ejemplo n.º 34
0
 private void InitializeValuesAndReferences() {
     _gameMgr = GameManager.Instance;
     _factory = UnitFactory.Instance;
 }
Ejemplo n.º 35
0
 public AddCommand(string[] data, UnitFactory unitFactory, IRepository unitRepository)
     : base(data, unitFactory, unitRepository)
 {
 }
Ejemplo n.º 36
0
 public UnitTemplate(UnitFactory unitFactory, uint cityId)
 {
     this.unitFactory = unitFactory;
     this.cityId      = cityId;
 }
Ejemplo n.º 37
0
 public EntityCreator(UnitFactory uFact, BuildingFactory bFact)
 {
     this.uFact = uFact;
     this.bFact = bFact;
 }
Ejemplo n.º 38
0
 public Dependencies(UnitRepository repository, UnitFactory unitFactory)
 {
     this.repository  = repository;
     this.unitFactory = unitFactory;
 }
Ejemplo n.º 39
0
 public SimpleStubGenerator(double[][] ratio, ushort[] type, UnitFactory unitFactory)
 {
     this.unitFactory = unitFactory;
     this.ratio       = ratio;
     this.type        = type;
 }
Ejemplo n.º 40
0
 public void ExitSpawnMode()
 {
     factory    = null;
     isBuilding = false;
 }
Ejemplo n.º 41
0
 public BattleFormulas(UnitModFactory unitModFactory, UnitFactory unitFactory, IObjectTypeFactory objectTypeFactory)
 {
     this.unitModFactory    = unitModFactory;
     this.unitFactory       = unitFactory;
     this.objectTypeFactory = objectTypeFactory;
 }
Ejemplo n.º 42
0
 public void EnterSpawnMode(UnitFactory factory)
 {
     this.factory = factory;
     isBuilding   = true;
 }