private void SetPlayers() { var mice = PlayerSettings.CountOnDesertPocket; var coyotes = PlayerSettings.CountOnDesertCoyot; int index; for (int i = 0; i < mice; i++) { index = _rnd.Next(0, Rows * Columns); while (Items[index].Color != "peru" || Items[index].Name != "") { index = _rnd.Next(0, Rows * Columns); } _miceIndexes.Add(index); Items[index] = new PocketMouse(); } for (int i = 0; i < coyotes; i++) { index = _rnd.Next(0, Rows * Columns); while (Items[index].Color != "peru" || Items[index].Name != "") { index = _rnd.Next(0, Rows * Columns); } _coyoteIndexes.Add(index); Items[index] = new Coyote(); } }
private void GiveBirthToAChild(int indexOfParent, ElementType et) { var adjacentSpots = GetAdjacentSpots(indexOfParent); var sands = adjacentSpots.Where(x => Items[x].ElementType == ElementType.Sand).ToList(); if (sands.Count == 0) { return; } Application.Current.Dispatcher.Invoke((Action) delegate { var randomIndex = sands[_rnd.Next(0, sands.Count)]; switch (et) { case ElementType.Coyote: Items[randomIndex] = new Coyote(); _coyoteIndexes.Add(randomIndex); break; case ElementType.PocketMouse: Items[randomIndex] = new PocketMouse(); _miceIndexes.Add(randomIndex); break; } }); }
static void Main(string[] args) { List <Animal> animalList = new List <Animal>(); /* ----------------------------- Create Animals ----------------------------- */ Animal myGiraf = new Giraf("G"); Animal myElefant = new Elefant("E"); Animal myCoyote = new Coyote("C"); Animal mySeal = new Seal("S"); Animal myBear = new Bear("B"); /* ------------------------- Add animals to the list ------------------------ */ animalList.Add(myGiraf); animalList.Add(myElefant); animalList.Add(myCoyote); animalList.Add(mySeal); animalList.Add(myBear); /* -------------------------------- Day loop -------------------------------- */ int day = 0; while (true) { day++; Console.WriteLine("Det är dag " + day + ":"); Console.WriteLine("-------"); for (int i = 0; i < animalList.Count; i++) { // Loop through the animalList Animal animal = animalList[i]; // Set animal variable for easier understanding animal.IncreaseHungerLevel(); if (animal.isHungry()) // Check if animal is hungry { animal.Eat(); // If hungry then eat animal.PrintEatSummaryToConsole(); // Print an summary on what the animal ate } else { Console.WriteLine("{0} {1} behövde inte äta", animal.animalType, animal.name); // If the animal isnt hungry } } Console.WriteLine(); // Wait for the next day Console.ReadKey(); } }
// Use this for initialization void Start() { camera = GameObject.FindGameObjectWithTag("MainCamera"); animHandler = GetComponent<AnimationHandler>(); coyote = GameObject.FindWithTag("coyote").GetComponent<Coyote>(); state = State.Moving; }