public void Go(Random random) { Age++; switch (CurrentState) { case BeeState.Idle: if (Age > CareerSpan) CurrentState = BeeState.Retired; else if (world.Flowers.Count > 0 && hive.ConsumeHoney(HoneyConsumed)) { Flower flower = world.Flowers[random.Next(world.Flowers.Count)]; if (flower.Nectar >= MinimumFlowerNectar && flower.Alive) { destinationFlower = flower; CurrentState = BeeState.FlyingToFlower; } } break; case BeeState.FlyingToFlower: if (!world.Flowers.Contains(destinationFlower)) CurrentState = BeeState.ReturningToHive; else if (InsideHive) { if (MoveTowardsLocation(hive.GetLocation("Exit"))) { InsideHive = false; location = hive.GetLocation("Entrance"); } } else if (MoveTowardsLocation(destinationFlower.Location)) CurrentState = BeeState.GatheringNectar; break; case BeeState.GatheringNectar: double nectar = destinationFlower.HarvestNectar(); if (nectar > 0) NectarCollected += nectar; else CurrentState = BeeState.ReturningToHive; break; case BeeState.ReturningToHive: if (!InsideHive) { if(MoveTowardsLocation(hive.GetLocation("Entrance"))) { location = hive.GetLocation("Exit"); InsideHive = true; } } else { if (MoveTowardsLocation(hive.GetLocation("HoneyFactory"))) CurrentState = BeeState.MakingHoney; } break; case BeeState.MakingHoney: if (NectarCollected < 0.5) { NectarCollected = 0; CurrentState = BeeState.Idle; } else { if (hive.AddHoney(0.5)) NectarCollected -= 0.5; else NectarCollected = 0; } break; case BeeState.Retired: // отдыхаем break; } if (CurrentState != ExState&& MessageSender!=null) { MessageSender(this.ID, this.CurrentState.ToString()); this.ExState = CurrentState; } }
private void AddFlower(Random random) { Point location = new Point(random.Next(FieldMinX, FieldMaxX), random.Next(FieldMinY, FieldMaxY)); Flower flower = new Flower(location, random); Flowers.Add(flower); }
public void Go(Random random) { Age++; switch (CurrentState) { case BeeState.Idle: if (Age > CareerSpan) { CurrentState = BeeState.Retired; } else if (world.Flowers.Count > 0 && hive.ConsumeHoney(HoneyConsumed)) { Flower flower = world.Flowers[random.Next(world.Flowers.Count)]; if (flower.Nectar >= MinimumFlowerNectar && flower.Alive) { destinationFlower = flower; CurrentState = BeeState.FlyingToFlower; } } break; case BeeState.FlyingToFlower: if (!world.Flowers.Contains(destinationFlower)) { CurrentState = BeeState.ReturningToHive; } else if (InsideHive) { if (MoveTowardsLocation(hive.GetLocation("Exit"))) { InsideHive = false; location = hive.GetLocation("Entrance"); } } else if (MoveTowardsLocation(destinationFlower.Location)) { CurrentState = BeeState.GatheringNectar; } break; case BeeState.GatheringNectar: double nectar = destinationFlower.HarvestNectar(); if (nectar > 0) { NectarCollected += nectar; } else { CurrentState = BeeState.ReturningToHive; } break; case BeeState.ReturningToHive: if (!InsideHive) { if (MoveTowardsLocation(hive.GetLocation("Entrance"))) { location = hive.GetLocation("Exit"); InsideHive = true; } } else { if (MoveTowardsLocation(hive.GetLocation("HoneyFactory"))) { CurrentState = BeeState.MakingHoney; } } break; case BeeState.MakingHoney: if (NectarCollected < 0.5) { NectarCollected = 0; CurrentState = BeeState.Idle; } else { if (hive.AddHoney(0.5)) { NectarCollected -= 0.5; } else { NectarCollected = 0; } } break; case BeeState.Retired: // отдыхаем break; } if (CurrentState != ExState && MessageSender != null) { MessageSender(this.ID, this.CurrentState.ToString()); this.ExState = CurrentState; } }