public static UiFish Born(Fish fish, UiFish parent1, UiFish parent2, AquariumProperties tank) { return(new UiFish( fish, parent1.Position.Midpoint(parent2.Position), tank)); }
public UiFish(Fish fish, PointF startingPosition, AquariumProperties tank) { this.Border = 100f; this.Sight = 300f; this.Space = 25f; this.behaviour = IocContainer.Get <IBehaviour>(); this.Predator = false; this.Boundary = new Size(tank.Width, tank.Height); this.aquariumProperties = tank; this.Fish = fish; this.Fish.Removed += () => { Active = false; }; this.Active = true; this.Leaving = false; this.Cleanliness = 100; using (var br = new BinaryReader(new MemoryStream(this.Fish.PayLoad.Reverse().ToArray()))) { FillColor = Color.FromArgb(br.ReadByte(), br.ReadByte(), br.ReadByte()); OutlineColor = Color.FromArgb(br.ReadByte(), br.ReadByte(), br.ReadByte()); BodySize = (br.ReadByte() % 10) + 1; Speed = (br.ReadByte() % 8) + 1; Predator = (br.ReadByte() % 10) <= 2 ? true : false; } this.Position = startingPosition; }
public static UiFish RandomPosition(Fish fish, AquariumProperties tank) { return(new UiFish( fish, new PointF( random.Next(tank.Width), random.Next(tank.Height)), tank)); }
private void CalculateHappiness(AquaObject me, AquariumProperties properties) { if (me.Ticks % 100 == 0 && me.Cleanliness <= 100 && me.Cleanliness >= 0) { if (properties.Algae < 25) { --me.Cleanliness; } if (properties.Algae > 100) { ++me.Cleanliness; } } }
public void Move(AquaObject me, IEnumerable <AquaObject> others, Point?cursor, AquariumProperties properties) { if (others.Any()) { this.Flocking(me, others, cursor); } else { this.Predation(me, others, cursor); } this.CalculateHappiness(me, properties); this.CheckBounds(me); this.CheckSpeed(me); me.Position = me.Position.Add(me.Direction); me.Ticks++; }