public void Die(Tile tile, Person person)
        {
            //ReducePopulation (tile, numberOfPeople);
            tile.TotalDeaths += 1;

            var data = new DataManager ();
            data.Delete (person);

            var list = new List<Person> (tile.People);
            list.Remove (person);
            tile.People = list.ToArray ();
        }
示例#2
0
        public void Rain(Tile tile)
        {
            var probability = Random.Next (100);
            if (probability > 98)
            {
                var randomValue = Random.Next (10);
                var actualValue = (decimal)randomValue * RainRate;
                tile.WaterSources += actualValue;

                Context.Log.WriteLine ("It rained " + actualValue + "litres");
            }
        }
        public void IncreasePopulation(Tile tile, Person[] newPeople)
        {
            var people = new List<Person> (tile.People);
            people.AddRange (newPeople);

            tile.People = people.ToArray ();

            var data = new DataManager ();

            for (int i = 0; i < newPeople.Length; i++)
                data.Save (newPeople [i]);
        }
        public void Emigrate(Tile tile, int numberOfPeople)
        {
            ReducePopulation (tile, numberOfPeople);

            tile.TotalEmigrants += numberOfPeople;

            var peopleWord = "people";
            if (numberOfPeople == 1)
                peopleWord = "person";

            Context.Log.WriteLine (numberOfPeople + " " + peopleWord + " left tile.");
        }
        public void Immigrate(Tile tile, int numberOfPeople)
        {
            // TODO: Change this so instead of creating people it moves people from other tiles
            IncreasePopulation (tile, new PersonCreator().CreateAdults(numberOfPeople));

            tile.TotalImmigrants += numberOfPeople;

            var peopleWord = "people";
            if (numberOfPeople == 1)
                peopleWord = "person";

            Context.Log.WriteLine (numberOfPeople + " new " + peopleWord + " arrived in tile.");
        }
        // TODO: Overhaul and re-enable
        //[Test]
        public void Test_Update()
        {
            var tile = new Tile ();

            var instruction = new EditInstruction (tile.GetType (), tile.Id, "TreesToPlantPerDay", 5);

            new DataManager ().Save (instruction);

            var instructionEngine = new InstructionEngine ();

            instructionEngine.Update (tile);

            Assert.AreEqual (5, tile.TreesToPlantPerDay);
        }
        public void ReducePopulation(Tile tile, int numberOfPeople)
        {
            if (tile.Population > 0) {
                if (tile.Population < numberOfPeople)
                    numberOfPeople = tile.Population;

                var list = new List<Person> (tile.People);
                for (int i = 0; i < numberOfPeople; i++) {
                    if (list.Count > 0) {
                        list.RemoveAt (0);
                        var person = tile.People [i];
                        if (person != null)
                            Context.Data.Delete (person);
                    }
                }
                tile.People = list.ToArray ();
            }
        }
        public void Page_Load(object sender, EventArgs e)
        {
            //var id = new Guid(Request.QueryString["id"]);
            /*var reader = new TileReader();
            var id = Guid.Empty;
            throw new Exception(TileId);
            if (!String.IsNullOrEmpty(TileId))
            {
            id = Guid.Parse(TileId);

            Tile = reader.Read(id);
            }
            else
            Tile = new Tile();*/

            Tile = new DataManager().Get<Tile>()[0];
            //Tile = new Tile();
        }
示例#9
0
 public void Update(Tile tile)
 {
     Rain (tile);
 }
示例#10
0
 public void Die(Tile tile, int numberOfPeople)
 {
     ReducePopulation (tile, numberOfPeople);
     tile.TotalDeaths += numberOfPeople;
 }
示例#11
0
        public void UpdatePopulationMigration(Tile tile)
        {
            // Arriving
            var probability = new Random ().Next (100);
            if (probability < 2)
            {
                var value = new Random ().Next (3);
                if (value > 0)
                    Immigrate (tile, value);
            }

            // Leaving
            var leavingProbability = new Random ().Next (500);
            if (leavingProbability < tile.TotalHomelessPeople) {
                var value = new Random ().Next (1, 3);
                Emigrate (tile, value);
            }
        }
示例#12
0
 public void UpdatePopulationBirthRate(Tile tile)
 {
     var random = new Random ();
     for (int i = 0; i < tile.TotalCouples; i++) {
         var randomNumber = random.Next (1, Context.Settings.BirthOdds);
         if (randomNumber < 1) {
             IncreasePopulation (tile, new PersonCreator (Settings).CreateBabies (1));
             tile.TotalBirths++;
             Context.Log.WriteLine ("A baby was born.");
         }
     }
 }
示例#13
0
 public void UpdatePopulationAge(Tile tile)
 {
     foreach (var person in tile.People) {
         person.IncreaseAge (Context.Settings.AgingRate);
     }
 }
示例#14
0
 public void Update(Tile tile)
 {
     UpdatePopulationAge (tile);
     UpdatePopulationBirthRate (tile);
     UpdatePopulationMigration (tile);
 }