public void Job() { // Create game Game.Game game = new Game.Game(); var village = game.Villages[0]; var farm = new Farm(village, village.JobsList.Farmer); new Restaurant(village, village.JobsList.Cooker); foreach (Family f in village.FamiliesList) { foreach (Villager v in f.FamilyMembers) { if (v.Job!=null) { v.Job.RemovePerson2(v); } } } var v0 = village.FamiliesList[0].FamilyMembers[0]; var v1 = village.FamiliesList[0].FamilyMembers[1]; var v2 = village.FamiliesList[1].FamilyMembers[0]; var v3 = village.FamiliesList[1].FamilyMembers[1]; var v4 = village.FamiliesList[2].FamilyMembers[0]; var v5 = village.FamiliesList[2].FamilyMembers[1]; var cooker = village.JobsList.Cooker; // Jobs are created int i; for(i=0; i<8; i++) Assert.That(village.JobsList[i], Is.Not.Null); // Add new worker to job Assert.That(cooker.Workers.Count, Is.EqualTo(0)); cooker.AddPerson2(v0); Assert.That(cooker.Workers.Count, Is.EqualTo(1)); Assert.That(v0.Job==cooker); // Try add the same worker to Apothecary job //Assert.Throws<InvalidOperationException>(() => cooker.AddPerson(v0), "Add worker issue!"); Assert.That( cooker.AddPerson2(v0)==false); Assert.That(cooker.Workers.Count, Is.EqualTo(1)); game.NextStep(); // See gold generation Assert.AreEqual(130, cooker.GoldGenerated);// /!\ should never be called. //was 65 cooker.GenerateGold(); Assert.That(v0.ParentFamily.GoldStash, Is.EqualTo(278));//65+20 Assert.That(v1.ParentFamily.GoldStash, Is.EqualTo(278));//65+20 Assert.That(v2.ParentFamily.GoldStash, Is.EqualTo(18));//0+20 // Add other worker cooker.AddPerson2(v2); Assert.That(cooker.Workers.Count, Is.EqualTo(2)); // New Gold generation cooker.GenerateGold(); Assert.That(cooker.GoldGenerated, Is.EqualTo(65));//64 Assert.That(v0.ParentFamily.GoldStash, Is.EqualTo(343));//129+20 Assert.That(v2.ParentFamily.GoldStash, Is.EqualTo(83));//64+20 // Remove worker cooker.RemovePerson2(v0); Assert.That(cooker.Workers.Count, Is.EqualTo(1)); Assert.That(v0.Job==null); // Try remove the same worker //Assert.Throws<InvalidOperationException>(() => cooker.RemovePerson2(v0), "Remove worker issue!"); Assert.That(cooker.RemovePerson2(v0)==false); Assert.That(cooker.Workers.Count, Is.EqualTo(1)); // Gold generation up cooker.GenerateGold(); Assert.That(cooker.GoldGenerated, Is.EqualTo(130));//65 Assert.That(v2.ParentFamily.GoldStash, Is.EqualTo(213));//129+20 }
// NEW GAME public Game(double timeStep = 0) { // Created "windows values" _totalGold = new HistorizedValue<int, Game>(this, @"_totalGold", 20); _totalPop = new HistorizedValue<int, Game>(this, @"_totalPop", 20); _offerings = new HistorizedValue<int, Game>(this, @"_offerings", 20); // Created lists _items = new List<GameItem>(); _singleMenList = new List<Villager>(); _villagesList = new List<Village>(); _eventList = new List<IEvent>(); // FamilyNames Generator var namesPath = File.ReadAllLines(@"Extra\nameList.txt"); _nameGenerator = new NameGenerator(namesPath, 1, 1); var firstNamesPath = File.ReadAllLines(@"Extra\firstNameList.txt"); _firstNameGenerator = new NameGenerator(namesPath, 1, 1); // GodSpell Initialization _currentEpidemicList = new List<GodSpell.Epidemic>(); // BirthDates Initialisation _regularBirthDates = new double[5]; #region To Be CHANGED //_ageTickTime = 0.0834;//time(years) between each tick. _ageTickTime = 1; Rand = new Random();//to be moved elsewhere. int j = 216; // j = 18 for (int i = 0; i < 5; i++) // Must be kept orderly { _regularBirthDates[i] = j; j = j + 4 * 12; // j = j + 4 } #endregion // Create Village Village village = CreateVillage(@"Ragnar"); // Create Table new TablePlace(village); // Create default jobs buildings Farm farm = new Farm(village, village.JobsList.Farmer); village.JobsList.Farmer.Building = farm; Forge forge = new Forge(village, village.JobsList.Blacksmith); village.JobsList.Blacksmith.Building = forge; UnionOfCrafter uoc = new UnionOfCrafter(village, village.JobsList.Construction_Worker); village.JobsList.Construction_Worker.Building = uoc; // Create 5 families Family FamilyA = village.CreateFamilyFromScratch(village.JobsList.Farmer, village.JobsList.Blacksmith); Family FamilyB = village.CreateFamilyFromScratch(village.JobsList.Farmer, village.JobsList.Construction_Worker); Family FamilyC = village.CreateFamilyFromScratch(); Family FamilyD = village.CreateFamilyFromScratch(); Family FamilyE = village.CreateFamilyFromScratch(); // Set player's offerings _offerings.Current = 100; }