public void PerformMissionTest() { IArmy army = new Army(); army.AddSoldier(new Corporal("Pepo", 12, 23, 2)); army.AddSoldier(new Corporal("Ricky", 29, 29, 20)); IWareHouse wareHouse = new WareHouse(); wareHouse.AddAmmunitions("AutomaticMachine", 12); wareHouse.AddAmmunitions("Gun", 3); wareHouse.AddAmmunitions("Helmet", 5); wareHouse.AddAmmunitions("Knife", 12); wareHouse.AddAmmunitions("MachineGun", 3); wareHouse.AddAmmunitions("NightVision", 5); wareHouse.AddAmmunitions("RPG", 56); MissionController mc = new MissionController(army, wareHouse); mc.Missions.Enqueue(new Easy(12.5)); mc.Missions.Enqueue(new Hard(56)); mc.Missions.Enqueue(new Hard(5)); mc.Missions.Enqueue(new Hard(6)); string res = mc.PerformMission(new Easy(23)); int n = res.Length; Assert.AreEqual(229, n); }
public void InitialTest() { IArmy army = new Army(); army.AddSoldier(new Ranker("Ivan", 47, 23, 100)); army.AddSoldier(new Corporal("Ivaylo", 21, 78, 100)); IAmmunitionFactory ammunitionFactory = new AmmunitionFactory(); IWareHouse warehouse = new WareHouse(ammunitionFactory); warehouse.AddAmmunitions("Gun", 2); warehouse.AddAmmunitions("AutomaticMachine", 2); warehouse.AddAmmunitions("MachineGun", 1); warehouse.AddAmmunitions("Helmet", 2); warehouse.AddAmmunitions("Knife", 1); this.controller = new MissionController(army, warehouse); }
protected void TrySpawnUnit(string soldierType) { // Check if the player can afford this soldier int cost = SoldierRegistry.GetSoldierCost(soldierType); if (!owner.CanAfford(cost) || owner.Population <= 0) { return; } // Set this soldier in the world if possible Tile currentTile = ((GameWorld as Grid)[positionInGrid] as Tile); if (!currentTile.Occupied) { // Nothing here, just place it in this square Army army = new Army(positionInGrid.X, positionInGrid.Y, owner); army.AddSoldier(SoldierRegistry.GetSoldier(soldierType, owner)); currentTile.SetUnit(army); } else if (currentTile.Unit.Owner == owner && currentTile.Unit is Army) { // Our own army is here, just place it in there :) Army a = currentTile.Unit as Army; if (a.GetTotalUnitCount() >= 20) { return; } a.AddSoldier(SoldierRegistry.GetSoldier(soldierType, owner)); } else { // We can't place it, just stop this whole function return; } // Buy the soldier, as we placed it. owner.Buy(cost); owner.CalculatePopulation(); }
/// <summary> /// Called when a player wins a battle (because all enemies died). /// </summary> /// <param name="winningPlayer">The player that won the battle.</param> private void OnPlayerWinBattle(Player winningPlayer) { // Unset attacker and defender attackingPlayer = null; defendingPlayer = null; // Find what's left of our army Army remainingArmy = new Army(0, 0, winningPlayer); ForEach(obj => { Tile t = obj as Tile; // See if there's a Soldier belonging to the winning player here if (t.Occupied && t.Unit.Owner == winningPlayer) { remainingArmy.AddSoldier(t.Unit as Soldier); } }); // Tell economy grid what's left and go back to economy grid GameStateManager.OnPlayerWinBattle(remainingArmy); }