Пример #1
0
 /// <summary>
 /// Gets the village production.
 /// </summary>
 /// <returns></returns>
 public Production GetProduction()
 {
     Production production = new Production();
     //<td id="l4" title="575">4675/14400</td>
     //<td id="l3" title="590">3343/14400</td>
     //<td id="l2" title="525">4463/14400</td>
     //<td id="l1" title="359">5236/11800</td>
     int perHourWood = 0, perHourClay = 0, perHourIron = 0, perHourCrop = 0;
     int totalWood = 0, totalClay = 0, totalIron = 0, totalCrop = 0;
     int wareHouse = 0;
     int granary = 0;
     HtmlNode htmlNode = htmlDocument.DocumentNode.SelectSingleNode("//td[@id='l4']");
     if (htmlNode != null)
     {
         perHourWood = Misc.String2Number(htmlNode.Attributes["title"].Value);
         string[] values = htmlNode.InnerText.Trim().Split('/');
         totalWood = Misc.String2Number(values[0]);
         wareHouse = Misc.String2Number(values[1]);
     }
     htmlNode = htmlDocument.DocumentNode.SelectSingleNode("//td[@id='l3']");
     if (htmlNode != null)
     {
         perHourClay = Misc.String2Number(htmlNode.Attributes["title"].Value);
         string[] values = htmlNode.InnerText.Trim().Split('/');
         totalClay = Misc.String2Number(values[0]);
         wareHouse = Misc.String2Number(values[1]);
     }
     htmlNode = htmlDocument.DocumentNode.SelectSingleNode("//td[@id='l2']");
     if (htmlNode != null)
     {
         perHourIron = Misc.String2Number(htmlNode.Attributes["title"].Value);
         string[] values = htmlNode.InnerText.Trim().Split('/');
         totalIron = Misc.String2Number(values[0]);
         wareHouse = Misc.String2Number(values[1]);
     }
     htmlNode = htmlDocument.DocumentNode.SelectSingleNode("//td[@id='l1']");
     if (htmlNode != null)
     {
         perHourCrop = Misc.String2Number(htmlNode.Attributes["title"].Value);
         string[] values = htmlNode.InnerText.Trim().Split('/');
         totalCrop = Misc.String2Number(values[0]);
         granary = Misc.String2Number(values[1]);
     }
     production
         .UpdatePerHour(perHourWood, perHourClay, perHourIron, perHourCrop)
         .UpdateTotals(totalWood, totalClay, totalIron, totalCrop)
         .UpdateWarehouse(wareHouse)
         .UpdateGranary(granary);
     return production;
 }
Пример #2
0
 /// <summary>
 /// Updates the production in village.
 /// </summary>
 /// <param name="villageProduction">The village production.</param>
 /// <returns></returns>
 public Village UpdateProduction(Production villageProduction)
 {
     production = villageProduction;
     return this;
 }
Пример #3
0
        public void VillageData()
        {
            Production production = new Production();
            const int warehouse = 3100;
            const int granary = 4000;
            production
                .UpdateWarehouse(warehouse)
                .UpdateGranary(granary)
                .UpdateTotals(132, 213, 11, 223)
                .UpdatePerHour(100, 200, 300, 400);
            Assert.IsNotNull(production, "Production is null!");

            TroopUnit phalanx = new TroopUnit();
            phalanx.AddName("Phalanx").AddHtmlClassName("unit u23").AddTroopCount(11);
            TroopUnit axeman = new TroopUnit();
            axeman.AddName("Axeman").AddHtmlClassName("unit u3").AddTroopCount(22);
            Troops troops = new Troops();
            troops.AddTroopUnit(phalanx).AddTroopUnit(axeman);
            Assert.IsNotNull(troops.TroopsList, "Troop list is null!");

            const int villageId = 0;
            const string villageName = "asds";
            const int coordinateX = 13;
            const int coordinateY = -131;
            Village village = new Village();
            village
                .AddId(villageId)
                .AddName(villageName)
                .UpdateCoordinates(coordinateX, coordinateY)
                .UpdateProduction(production)
                .UpdateTroopsInVillage(troops);

            Assert.IsNotNull(village.Production, "Production is null!");
            Assert.IsNotNull(village.TroopsAvailable, "TroopsAvailable is null!");
            Assert.AreEqual(production, village.Production, "Village production!");
            Assert.AreEqual(troops, village.TroopsAvailable, "Village troops!");
            Assert.AreEqual(warehouse, village.Production.Warehouse, "Warehouse!");
            Assert.AreEqual(granary, village.Production.Granary, "Granary!");
            Assert.AreEqual(coordinateX, village.CoordinateX, "CoordinateX!");
            Assert.AreEqual(coordinateY, village.CoordinateY, "CoordinateY!");
            village
                .AddTroopsMovement(new TroopMovement()
                                       .AddTroops(new Troops().AddTroopUnit(new TroopUnit("unit11", 12)))
                                       .AddTroops(new Troops().AddTroopUnit(new TroopUnit("unit12", 13)))
                                       .AddTroops(new Troops().AddTroopUnit(new TroopUnit("unit13", 14)))
                                       .AddTroops(new Troops().AddTroopUnit(new TroopUnit("unit14", 15)))
                                       .SetDate(new DateTime(2222, 12, 1, 1, 1, 1))
                                       .SetType(TroopMovementType.AttackIncomming))
                .AddTroopsMovement(new TroopMovement()
                                       .AddTroops(new Troops().AddTroopUnit(new TroopUnit("unit31", 1201)))
                                       .AddTroops(new Troops().AddTroopUnit(new TroopUnit("unit32", 1202)))
                                       .AddTroops(new Troops().AddTroopUnit(new TroopUnit("unit33", 1203)))
                                       .AddTroops(new Troops().AddTroopUnit(new TroopUnit("unit34", 1204)))
                                       .AddTroops(new Troops().AddTroopUnit(new TroopUnit("unit35", 1205)))
                                       .AddTroops(new Troops().AddTroopUnit(new TroopUnit("unit36", 1206)))
                                       .SetDate(new DateTime(2222, 10, 1, 1, 1, 1))
                                       .SetType(TroopMovementType.AttackOutgoing))
                .AddTroopsMovement(new TroopMovement()
                                       .AddTroops(new Troops().AddTroopUnit(new TroopUnit("unit21", 121)))
                                       .AddTroops(new Troops().AddTroopUnit(new TroopUnit("unit22", 122)))
                                       .AddTroops(new Troops().AddTroopUnit(new TroopUnit("unit23", 123)))
                                       .SetDate(new DateTime(2222, 11, 1, 1, 1, 1))
                                       .SetType(TroopMovementType.AttackOutgoing))
                .AddTroopsMovement(new TroopMovement()
                                       .AddTroops(new Troops().AddTroopUnit(new TroopUnit("unit4", 12000)))
                                       .SetDate(new DateTime(2222, 9, 1, 1, 1, 1))
                                       .SetType(TroopMovementType.ReinforcementIncomming))
                ;

            Assert.IsNotNull(village.TroopMovement, "Troop movement!");
            Assert.AreEqual(4, village.TroopMovementCount, "Troop movement count!");
            Assert.AreEqual(2, village.OwnAttacks, "Own attacks!");
            Assert.Sorted(village.TroopMovement, SortOrder.Increasing, new TroopMovementComparer());
            village.ClearTroopMovementsList();
            Assert.AreEqual(0, village.TroopMovementCount, "Troop movement count!");
        }
Пример #4
0
        public void Account()
        {
            Account account = new Account();
            const string accountName = "kekec";
            const int accountId = 123;
            const TribeTypes accountTribe = TribeTypes.Gauls;
            account.AddName(accountName).AddId(accountId).AddTribe(accountTribe);
            Assert.IsNotNull(account, "Account is null!");
            Assert.AreEqual(accountName, account.Name);
            Assert.AreEqual(accountId, account.Id);
            Assert.AreEqual(accountTribe, account.TribeType);

            Village firstVillage = new Village();
            const int firstVillageId = 0;
            const string firstVillageName = "01";
            firstVillage.AddId(firstVillageId).AddName(firstVillageName);
            account.AddVillage(firstVillage);
            Assert.IsNotNull(account.Villages, "Village list!");
            Assert.AreEqual(1, account.Villages.Count, "Village list count!");
            Assert.AreEqual(firstVillageId, account.Villages[0].Id, "Village id!");
            Assert.AreEqual(firstVillageName, account.Villages[0].Name, "Village name!");

            Village secondVillage = new Village();
            const int secondVillageId = 1324;
            const string secondVillageName = "02";
            secondVillage.AddId(secondVillageId).AddName(secondVillageName);
            Production production = new Production();
            production
                .UpdateWarehouse(3100)
                .UpdateGranary(4000)
                .UpdateTotals(132, 213, 11, 223)
                .UpdatePerHour(100, 200, 300, 400);
            secondVillage.UpdateProduction(production);
            account.AddVillage(secondVillage);

            Assert.AreEqual(2, account.Villages.Count, "Village list count!");

            Village firstAccountVillage = account.GetVillage(firstVillageId);
            Assert.IsNotNull(firstAccountVillage, "Village not found!");
            Assert.AreEqual(firstVillageId, firstAccountVillage.Id, "Village id!");
            Assert.AreEqual(firstVillageName, firstAccountVillage.Name, "Village name!");
            Assert.IsNull(firstAccountVillage.Production, "Village production!");
            Assert.IsNull(firstAccountVillage.TroopsAvailable, "Village troops!");

            Village secondAccountVillage = account.GetVillage(secondVillageId);
            Assert.IsNotNull(secondAccountVillage, "Village not found!");
            Assert.AreEqual(secondVillageId, secondAccountVillage.Id, "Village id!");
            Assert.AreEqual(secondVillageName, secondAccountVillage.Name, "Village name!");
            Assert.AreEqual(production, secondAccountVillage.Production, "Village production!");
            Assert.IsNull(secondAccountVillage.TroopsAvailable, "Village troops!");

            Gauls gauls = new Gauls();
            TroopUnit phalanx = gauls.Phalanx.AddTroopCount(123);
            TroopUnit haeduan = gauls.Haeduan.AddTroopCount(13);
            Romans romans = new Romans();
            TroopUnit legionnaire = romans.Legionnaire.AddTroopCount(2222);
            TroopUnit praetorian = romans.Praetorian.AddTroopCount(45632);
            Teutons teutons = new Teutons();
            TroopUnit spearman = teutons.Spearman.AddTroopCount(5123);
            Troops troops = new Troops();
            troops
                .AddTroopUnit(phalanx).AddTroopUnit(haeduan)
                .AddTroopUnit(legionnaire).AddTroopUnit(praetorian)
                .AddTroopUnit(spearman);
            secondAccountVillage.UpdateTroopsInVillage(troops);
            Assert.IsNull(firstAccountVillage.TroopsAvailable, "Village troops!");
            Assert.IsNotNull(secondAccountVillage.TroopsAvailable, "Village troops!");
            Assert.AreEqual(13, secondAccountVillage.TroopsAvailable.GetTroopCount("unit u26"), "Haeduan count!");
        }