static private CreateUnit ( string prefab, string category, int lvl ) : Unit, | ||
prefab | string | |
category | string | |
lvl | int | |
return | Unit, |
public override string Execute() { IUnit unit = UnitFactory.CreateUnit(Data[1]); Repository.AddUnit(unit); return($"{this.Data[1]} added!"); }
public void FarmBuildingTest() { Farm farm = new Farm(5, 2); Builder builder = (Builder)UnitFactory.CreateUnit(typeof(Builder)); Assert.False(farm.AbleToFunction); Assert.Equal(2, farm.BuildingTime); Assert.Equal(0, farm.BuildProgress); Assert.Equal(0, farm.CurrentCapacity); Assert.Equal(5, farm.MaxCapacity); Assert.Equal(0, farm.CurrentConstructionUnitCount); Assert.Single(farm.UnitTypes); Assert.Single(farm.UnitTypes.Where(u => u == typeof(Farmer))); Assert.Empty(farm.DoWork()); 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); }
public void LabBuildingTest() { Lab lab = new Lab(5, 2); Builder builder = (Builder)UnitFactory.CreateUnit(typeof(Builder)); 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))); Assert.Empty(lab.DoWork()); 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); }
public void ForestCampBuildTest2() { ForestCamp forestCamp = new ForestCamp(5, 3); Builder builder = (Builder)UnitFactory.CreateUnit(typeof(Builder)); Assert.False(forestCamp.AbleToFunction); Assert.Equal(3, 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.DoBuildProcess(); Assert.Equal(0, forestCamp.BuildProgress); forestCamp.AddConstructionUnit(builder); Assert.Equal(1, forestCamp.CurrentConstructionUnitCount); forestCamp.DoBuildProcess(); Assert.Equal(1, forestCamp.BuildProgress); Assert.False(forestCamp.AbleToFunction); forestCamp.DoBuildProcess(); Assert.Equal(2, forestCamp.BuildProgress); Assert.False(forestCamp.AbleToFunction); forestCamp.DoBuildProcess(); Assert.Equal(3, forestCamp.BuildProgress); Assert.True(forestCamp.AbleToFunction); }
public void Start() { var unitFactory = new UnitFactory(Context, new MockFactory(Context)); var unit = unitFactory.CreateUnit(); UnitManager.Instance.AddUnit(unit); }
/// <summary> /// Calls the UnitFactory class to create units. /// </summary> /// <returns>Returns requared unit.</returns> public IUnit ProduceUnit() { UnitFactory unitFactory = new UnitFactory(); var unit = unitFactory.CreateUnit(this.UnitType); return(unit); }
public void Start() { var unitFactory = new UnitFactory(Context, new MockFactory(Context)); var unit = unitFactory.CreateUnit(); Context.VirtualCamera.Follow = unit.transform; Context.VirtualCamera.LookAt = unit.transform; }
// Update is called once per frame public Unit GetUnit() { if (m_SleepUnitList.Count == 0) { return(UnitFactory.CreateUnit(m_unitName)); } return(m_SleepUnitList.Pop()); }
public override string Execute() { string unitType = Data[1]; var unit = UnitFactory.CreateUnit(unitType); Repository.AddUnit(unit); return($"{unitType} added!"); }
public override string Execute() { string unitType = Data[1]; IUnit unitToAdd = UnitFactory.CreateUnit(unitType); Repository.AddUnit(unitToAdd); string output = unitType + " added!"; return(output); }
// Update is called once per frame void Update() { if (!_texture) { _texture = videoRenderer.getWebCamTexture(); // Debug.Log(_texture.width); } if (Input.GetMouseButtonDown(1)) { RaycastHit hit; MeshCollider collie = videoRenderer.gameObject.GetComponentInChildren <MeshCollider>(); if (!collie.Raycast(Camera.main.ScreenPointToRay(new Vector3(Input.mousePosition.x, Input.mousePosition.y, Input.mousePosition.z)), out hit, 2000f)) { return; } Renderer rend = hit.transform.GetComponent <Renderer>(); MeshCollider meshCollider = hit.collider as MeshCollider; if (rend == null || meshCollider == null) { return; } Vector2 pixelUV = hit.textureCoord; pixelUV.x *= 1280f; pixelUV.y *= 720f; Color32 color = (Color32)_texture.GetPixel((int)pixelUV.x, (int)pixelUV.y); ctp.colorTargets.Add(new Vexpot.ColorTarget(color, tolerance)); ctp.StopColorTracker(); ctp.UpdateColorTargets(); ctp.StartColorTracker(); _factory.CreateUnit(color); _constructor.ColorSelected(color); } if (Input.GetMouseButtonDown(0)) { UnitGroup ug = null; if (_gManager.GetGridUnit(_gManager.GetGridPos(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0))) != null) { ug = _gManager.GetGridUnit(_gManager.GetGridPos(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0))); } if (ug != null) { _constructor.SetActiveUnit(ug.gameObject, true); _logController.updateStats(ug.info); } } }
public void Start() { playerStage = PlayerStage.Level1; // Realign the spawnpoint so it's on the terrain spawnPoint.transform.position = VectorUtil.sitOnTerrain(spawnPoint); AddBuilding(UnitType.CommandCenter, BuildingFactory.CreateBuilding(this, UnitType.CommandCenter, spawnPoint.transform.position, spawnPoint.transform.rotation)); AddUnit(UnitType.Rover, UnitFactory.CreateUnit(this, UnitType.Rover, VectorUtil.sitOnTerrain(spawnPoint.transform.position + (Vector3.forward * 10) - (Vector3.left * 2)))); AddUnit(UnitType.Rover, UnitFactory.CreateUnit(this, UnitType.Rover, VectorUtil.sitOnTerrain(spawnPoint.transform.position + (Vector3.forward * 10) + (Vector3.left * 2)))); }
public void SpawnUnit(ScriptableUnitConfig unit_config, M_Math.R_Range range, int group, bool hide_player) { Unit u = UnitFactory.CreateUnit(unit_config, group, range, hide_player); if (u != null) { UnitFactory.SpawnUnit(u, GetComponent <Tile>()); } else { Debug.LogWarning("Could not spawn unit"); } }
public void CreateBuilderTest() { Assert.Throws <Exception>(() => UnitFactory.CreateUnit(typeof(Builder))); BuilderUnitRegister visitor = new BuilderUnitRegister(); UnitFactory.AddFactory(visitor); var unit = UnitFactory.CreateUnit(typeof(Builder)); Assert.IsType <Builder>(unit); var builder = unit as Builder; Assert.Equal(1, builder.FoodNeeded); Assert.Equal(Satisfaction.Ok, builder.Satisfaction); Assert.Equal(1, builder.ProgressAmount); }
public static void CreateHelloWorld(this UnitFactory factory) { var requiredModuleGroup = WorldManager.Instance.Module .TagToModuleGroupType(GameConstant.HELLO_WORLD_GROUP_TYPE); var unit = factory.CreateUnit(requiredModuleGroup); var helloWorldData = new HelloWorldData(); helloWorldData.helloWorld = "Hello World!"; unit.AddData(helloWorldData); var unitData = unit.GetData <UnitData>(); unitData.stateTypeProperty.Value = UnitStateType.Init; }
public override void OnStart() { Unit unit = UnitFactory.CreateUnit(m_Res, m_ID, m_UnitType); unit.gameObject.name = "Unit_" + m_Name; unit.SetName(m_Name); unit.EulerAngles = m_EulerAngles; unit.Position = m_Position; unit.SetAttr(AttrType.Hp, m_Hp); unit.SetAttr(AttrType.HpMax, m_HpMax); HudComponent hudComponent = unit.gameObject.AddComponent <HudComponent>(); hudComponent.SetOwner(unit); Node.Status = ENodeStatus.Succeed; }
public void CreateGathererTest() { Assert.Throws <Exception>(() => UnitFactory.CreateUnit(typeof(Gatherer))); GathererUnitRegister visitor = new GathererUnitRegister(); UnitFactory.AddFactory(visitor); var unit = UnitFactory.CreateUnit(typeof(Gatherer)); Assert.IsType <Gatherer>(unit); var gatherer = unit as Gatherer; Assert.Equal(1, gatherer.FoodNeeded); Assert.Equal(Satisfaction.Ok, gatherer.Satisfaction); Assert.Equal(2, gatherer.Products.Count); Assert.Single(gatherer.Products.Where(p => p.Type == "wood" && p.Amount == 1)); Assert.Single(gatherer.Products.Where(p => p.Type == "rock" && p.Amount == 1)); }
void SpawnTestUnits() // DEMO METHOD { // don't spawn on top of obstacles List <Tile> baseLocations = new List <Tile>(board.tiles.Values); List <Tile> locations = new List <Tile>(); foreach (Tile t in baseLocations) { if (t.content == null) { locations.Add(t); } } // spawn AI units for (int j = 0; j < owner.enemies.Length; j++) { GameObject instance = UnitFactory.CreateUnit(owner.enemies[j]); int random = UnityEngine.Random.Range(locations.Count * 3 / 4, 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); } PartyEntry[] party = GameObject.FindObjectsOfType <PartyEntry>(); // spawn player units for (int i = 0; i < party.Length; ++i) { GameObject instance = UnitFactory.CreateUnit(party[i].UnitInfo[0], party[i].UnitInfo[1], party[i].UnitInfo[2], party[i].PerkDict, party[i].UnitInfo[3], "Hero"); int random = UnityEngine.Random.Range(0, locations.Count / 3); 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); Destroy(party[i].gameObject); } SelectTile(units[0].tile.pos); }
public void CreateResearcherTest() { Assert.Throws <Exception>(() => UnitFactory.CreateUnit(typeof(Researcher))); ResearcherUnitRegister visitor = new ResearcherUnitRegister(); UnitFactory.AddFactory(visitor); var unit = UnitFactory.CreateUnit(typeof(Researcher)); Assert.IsType <Researcher>(unit); var researcher = unit as Researcher; Assert.Equal(1, researcher.FoodNeeded); Assert.Equal(Satisfaction.Ok, researcher.Satisfaction); Assert.Equal(int.MaxValue, researcher.MaxInput); Assert.Empty(researcher.InputOutputMapping); Assert.Single(researcher.Products); Assert.Single(researcher.Products.Where(r => r.Type == "researchpoint" && r.Amount == 1)); }
public void MiningVillageBuildTest() { MiningVillage miningVillage = new MiningVillage(5, 4); Builder builder = (Builder)UnitFactory.CreateUnit(typeof(Builder)); Assert.False(miningVillage.AbleToFunction); Assert.Equal(4, miningVillage.BuildingTime); Assert.Equal(0, miningVillage.BuildProgress); Assert.Equal(0, miningVillage.CurrentCapacity); Assert.Equal(5, miningVillage.MaxCapacity); Assert.Equal(0, miningVillage.CurrentConstructionUnitCount); Assert.Single(miningVillage.UnitTypes); Assert.Single(miningVillage.UnitTypes.Where(u => u == typeof(Gatherer))); Assert.Empty(miningVillage.DoWork()); miningVillage.DoBuildProcess(); Assert.Equal(0, miningVillage.BuildProgress); miningVillage.AddConstructionUnit(builder); Assert.Equal(1, miningVillage.CurrentConstructionUnitCount); miningVillage.DoBuildProcess(); Assert.Equal(1, miningVillage.BuildProgress); Assert.False(miningVillage.AbleToFunction); miningVillage.DoBuildProcess(); Assert.Equal(2, miningVillage.BuildProgress); Assert.False(miningVillage.AbleToFunction); miningVillage.DoBuildProcess(); Assert.Equal(3, miningVillage.BuildProgress); Assert.False(miningVillage.AbleToFunction); miningVillage.DoBuildProcess(); Assert.Equal(4, miningVillage.BuildProgress); Assert.True(miningVillage.AbleToFunction); miningVillage.DoBuildProcess(); Assert.Equal(4, miningVillage.BuildProgress); Assert.True(miningVillage.AbleToFunction); }
private void InitializeGrid(char[,] charGrid) { spotGrid = new Spot[Rows, Cols]; Units = new List <Unit>(); for (var row = 0; row < Rows; row++) { for (var col = 0; col < Cols; col++) { var spot = GetSpotFromChar(charGrid[row, col]); spotGrid[row, col] = spot; if (spot == Spot.Goblin || spot == Spot.Elf) { var unitToAdd = unitFactory.CreateUnit(spot); unitToAdd.Row = row; unitToAdd.Col = col; Units.Add(unitToAdd); } } } }
private static void StoremammalsInList(List <Mammal> mammals) { while (true) { string[] input = Console.ReadLine().Split(); if (input[0] == "End") { break; } if (input[0] == "Robot") { continue; } var currentUnit = UnitFactory.CreateUnit(input); mammals.Add(currentUnit); } }
public void MiningVillageTest() { MiningVillage miningVillage = new MiningVillage(5, 2); Builder builder = (Builder)UnitFactory.CreateUnit(typeof(Builder)); Gatherer gatherer = (Gatherer)UnitFactory.CreateUnit(typeof(Gatherer)); Assert.False(miningVillage.AbleToFunction); Assert.Equal(2, miningVillage.BuildingTime); Assert.Equal(0, miningVillage.BuildProgress); Assert.Equal(0, miningVillage.CurrentCapacity); Assert.Equal(5, miningVillage.MaxCapacity); Assert.Equal(0, miningVillage.CurrentConstructionUnitCount); Assert.Single(miningVillage.UnitTypes); Assert.Single(miningVillage.UnitTypes.Where(u => u == typeof(Gatherer))); miningVillage.DoBuildProcess(); Assert.Equal(0, miningVillage.BuildProgress); miningVillage.AddConstructionUnit(builder); Assert.Equal(1, miningVillage.CurrentConstructionUnitCount); miningVillage.DoBuildProcess(); Assert.Equal(1, miningVillage.BuildProgress); Assert.False(miningVillage.AbleToFunction); miningVillage.DoBuildProcess(); Assert.Equal(2, miningVillage.BuildProgress); Assert.True(miningVillage.AbleToFunction); miningVillage.AssignUnit(gatherer); Assert.Equal(1, miningVillage.CurrentCapacity); var resources = miningVillage.DoWork(); Assert.NotNull(resources); Assert.NotEmpty(resources); Assert.Single(resources); Assert.Single(resources.Where(r => r.Type == "rock")); Assert.Single(resources.Where(r => r.Type == "rock" && r.Amount == 1)); }
public void ForestCampTest() { ForestCamp forestCamp = new ForestCamp(5, 1); Builder builder = (Builder)UnitFactory.CreateUnit(typeof(Builder)); Gatherer gatherer = (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)); }
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)); }
void Start() { Unit u = UnitFactory.CreateUnit(UnitConfig, group, new M_Math.R_Range(2, 5), true); UnitFactory.SpawnUnit(u, (GetComponent <Tile>())); }
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)); }
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)); }
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); }); } }
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); } }