private void Button_Click(object sender, RoutedEventArgs e) { for (int i = 0; i < aquarium.aquariumSizeRow; i++) { for (int j = 0; j < aquarium.aquariumSizeColumn; j++) { var obj = aquarium.cells[i, j]; if (obj != null) { var type = obj.GetType(); if (type == typeof(Predator)) { Predator currentObj = (Predator)obj; currentObj.isChecked = false; } else if (type == typeof(Herbivore)) { Herbivore currentObj = (Herbivore)obj; currentObj.isChecked = false; } } } } for (int i = 0; i < aquarium.aquariumSizeRow; i++) { for (int j = 0; j < aquarium.aquariumSizeColumn; j++) { var obj = aquarium.cells[i, j]; if (obj != null) { var type = obj.GetType(); if (type == typeof(Predator)) { Predator currentObj = (Predator)obj; currentObj.checkFish(i, j, aquarium.cells, aquarium, DynamicGrid); } else if (type == typeof(Herbivore)) { Herbivore currentObj = (Herbivore)obj; currentObj.checkFish(i, j, aquarium.cells, aquarium, DynamicGrid); } else if (type == typeof(Seaweed)) { Seaweed currentObj = (Seaweed)obj; currentObj.checkStatus(); } else if (type == typeof(Rock)) { Console.WriteLine("Rock"); } } } } mainWindow = Application.Current.Windows.OfType <MainWindow>().FirstOrDefault(); mainWindow.Content = DynamicGrid; }
private void UpdateStatus() { List <Seaweed> seaweeds = new List <Seaweed>(Seaweeds); for (int i = 0; i < Fishes.Count; i++) { Fishes[i].RemovePV(1); Fishes[i].AddAge(1); } for (int i = 0; i < seaweeds.Count; i++) { Seaweed Seaweed = Seaweeds[i]; Seaweed.AddPV(1); Seaweed.AddAge(1); if (Seaweed.PV >= 10) { Seaweed MiniSeaweed = Seaweed.Repoduction(); Seaweeds.Add(MiniSeaweed); } } }
private void ToClean(List <Fish> fishes) { for (int i = fishes.Count - 1; i >= 0; i--) { Fish fish = fishes[i]; if (fish.PV == 0 || fish.Age > 20) { Console.ForegroundColor = ConsoleColor.DarkRed; Console.WriteLine($"{fish.Name} is dead !"); fishes.Remove(fish); } } for (int i = Seaweeds.Count - 1; i >= 0; i--) { Seaweed seaweed = Seaweeds[i]; if (seaweed.PV == 0 || seaweed.Age > 20) { Console.ForegroundColor = ConsoleColor.DarkRed; Console.WriteLine("A seaweed is dead !"); Seaweeds.Remove(seaweed); } } }
private static void HarvestBonusEffect(Mobile harvester, Item tool) { if (Utility.Random(70) >= 5) { return; } if (Utility.Random(100) < 2 && harvester.ShilCheckSkill(SkillName.Fishing, 110, 200)) { var sosBottle = new MessageInABottle(); harvester.AddToBackpack(sosBottle); return; } var chance = Utility.Random(1, 10); Item item = null; var message = ""; switch (chance) { case 1: { item = new SpecialFishingNet(); message = "You just found a special fishing net."; break; } case 2: { if (Utility.Random(10) < 4 && !Region.Find(harvester.Location, harvester.Map) .GetRegion <GuardedRegion>()?.IsDisabled() == false) { SpawnCreature(harvester, typeof(WaterElemental)); message = "You attract the attention of a water elemental"; } break; } case 3: { if (Utility.Random(10) < 4) { SpawnCreature(harvester, typeof(Walrus)); message = "A walrus comes by to see what you're doing"; } break; } case 4: { item = new TreasureMap(2, Map.Felucca); message = "You find a tattered old map!"; break; } case 5: { item = new Backpack(); item.AddItem(new Gold(Utility.Random(300) + 100)); message = "You find an old backpack!"; break; } case 6: { item = new Seaweed(); message = "You find some seaweed!"; break; } case 8: { item = GetRandomShell(harvester); message = "You find something valuable!"; break; } } if (item != null) { var cont = harvester.Backpack; if (cont.TryDropItem(harvester, item, false)) { if (message.Length > 0) { harvester.SendSuccessMessage(message); } } else if (message.Length > 0) { harvester.SendFailureMessage(message); } } else if (message.Length > 0) { harvester.SendSuccessMessage(message); } }
static void Main(string[] args) { Aquarium aquarium = new Aquarium(); aquarium.cells[3, 1] = new Predator(5, false); aquarium.cells[2, 2] = new Predator(9, true); aquarium.cells[3, 3] = new Predator(7, true); aquarium.cells[4, 2] = new Predator(3, true); aquarium.cells[1, 1] = new Predator(4, true); aquarium.cells[2, 0] = new Predator(3, true); aquarium.cells[5, 1] = new Predator(10, true); aquarium.cells[4, 0] = new Predator(3, true); for (int i = 0; i < aquarium.aquariumSizeRow; i++) { for (int j = 0; j < aquarium.aquariumSizeColumn; j++) { Aquarium obj = aquarium.cells[i, j]; if (obj != null) { var type = obj.GetType(); if (type == typeof(Predator)) { Predator currentObj = (Predator)obj; currentObj.checkFish(i, j, aquarium.cells); } else if (type == typeof(Herbivore)) { Herbivore currentObj = (Herbivore)obj; currentObj.checkFish(i, j, aquarium.cells); } else if (type == typeof(Seaweed)) { Seaweed currentObj = (Seaweed)obj; currentObj.checkStatus(); } else if (type == typeof(Rock)) { Console.WriteLine("Rock"); } } } } for (int i = 0; i < aquarium.aquariumSizeRow; i++) { for (int j = 0; j < aquarium.aquariumSizeColumn; j++) { Aquarium obj = aquarium.cells[i, j]; if (obj != null) { var type = obj.GetType(); if (type == typeof(Predator)) { Predator currentObj = (Predator)obj; currentObj.lifeCycle(i, j, aquarium.cells); } else if (type == typeof(Herbivore)) { Herbivore currentObj = (Herbivore)obj; currentObj.lifeCycle(i, j, aquarium.cells); } else if (type == typeof(Seaweed)) { Console.WriteLine("Seaweed"); } else if (type == typeof(Rock)) { Console.WriteLine("Rock"); } } } } Console.WriteLine("......."); Console.ReadLine(); }
private void LoveAndDinerTime() { List <Fish> HungryFishes = new List <Fish>(Fishes); List <Fish> FishesInLove = new List <Fish>(Fishes); if (Fishes.Count > 1) { for (int i = 0; i < Fishes.Count; i++) { Fish CurrentFish = Fishes[i]; Random Rng = new Random(); int Target = Rng.Next(HungryFishes.Count); Fish TargetFish = HungryFishes[Target]; while (CurrentFish == TargetFish) { Target = Rng.Next(HungryFishes.Count); TargetFish = HungryFishes[Target]; } if (CurrentFish.PV > 5 && FishesInLove.Contains(CurrentFish) && FishesInLove.Contains(TargetFish) && CurrentFish.GetType() == TargetFish.GetType()) { if (CurrentFish is IOpportunistic && CurrentFish.Sex == TargetFish.Sex) { ((IOpportunistic)CurrentFish).ChangeSex(); } if (CurrentFish.Sex != TargetFish.Sex) { Fish Child = CurrentFish.MakeLove(CurrentFish.GetType(), CurrentFish.Name, TargetFish.Name); HungryFishes.Add(Child); Console.ForegroundColor = ConsoleColor.Magenta; Console.WriteLine($"{CurrentFish.Name} and {TargetFish.Name} had a baby ({Child.Name}) !"); FishesInLove.Remove(CurrentFish); FishesInLove.Remove(TargetFish); } } if (CurrentFish.PV <= 5 && HungryFishes.Contains(CurrentFish)) { if (CurrentFish is CarnivorousFish) { if (CurrentFish.GetType() != TargetFish.GetType()) { ((CarnivorousFish)CurrentFish).Eat(TargetFish); Console.ForegroundColor = ConsoleColor.DarkYellow; Console.WriteLine($"{CurrentFish.Name} ate {TargetFish.Name} !"); } } else if (Seaweeds.Count > 0) { Seaweed seaweed = Seaweeds[Rng.Next(Seaweeds.Count)]; ((HerbivorousFish)CurrentFish).Eat(seaweed); Console.ForegroundColor = ConsoleColor.DarkYellow; Console.WriteLine($"{CurrentFish.Name} ate {TargetFish.Name} !"); } } ToClean(HungryFishes); } Fishes = HungryFishes; } }
public void AddSeaweed(Seaweed seaweed) { Seaweeds.Add(seaweed); }
public void Launch() { Fish fish = new Fish(20, 8); Seaweed[] sw = new Seaweed[6]; for (int i = 0; i < 6; i++) { if (i % 2 == 0) { sw[i] = new SeaweedLong((13 * i + 5), 16); } else { sw[i] = new SeaweedShort((13 * i + 5), 21); } } Bubble bubbleFish = new Bubble(fish.X, fish.Y); Bubble[] bubbleBackground = new Bubble[5]; for (int i = 0; i < 5; i++) { bubbleBackground[i] = new Bubble(20, 24); } Settings.RealSpeed = 10; Settings.ConsoleSpeed = 100; while (true) { Settings.UpdateScreenAndTimer(); //********* Background bubbles ************ if (Settings.Timer % 5 == 0) { launchBubble[amountBubble] = true; if (amountBubble < 4) { amountBubble++; } else { amountBubble = 0; } } int r = new Random().Next(0, 70); for (int i = 0; i < 5; i++) { if (launchBubble[i]) { bubbleBackground[i].MoveUp(r, 24, ConsoleColor.Blue); } } //**************** Fish ******************* fish.Draw(fish.X, fish.Y); fish.Move(); if (fish.X <= borderLeft || fish.X >= borderRight - 13) { fish.SpeedX = -fish.SpeedX; fish.TurnFish = fish.TurnFish ? fish.TurnFish = false : fish.TurnFish = true; } if (fish.Y <= borderTop + 4 || fish.Y >= borderBottom - 16) { fish.SpeedY = -fish.SpeedY; } if (!fish.TurnFish) { bubbleFish.MoveUp(fish.X, fish.Y + 3, ConsoleColor.Cyan); } else { bubbleFish.MoveUp(fish.X + 12, fish.Y + 3, ConsoleColor.Cyan); } if (Settings.Timer % 5 == 0) { fish.eyeClosed = fish.eyeClosed ? fish.eyeClosed = false : fish.eyeClosed = true; } //*************** Seaweeds ***************** foreach (Seaweed seaweed in sw) { seaweed.Draw(seaweed.X, seaweed.Y); } Thread.Sleep(Settings.ConsoleSpeed); } }
public void Eat(Seaweed seaweed) { seaweed.RemovePV(3); this.AddPV(2); }