public override IEnumerable <Particle> Update() { if (this.timeToLay > 0) { this.timeToLay--; return(base.Update()); } List <Particle> produced = new List <Particle>(); if (this.layingTime > 0) { this.layingTime--; return(produced); } SetRandomLayingTimeAndTimeToLay(); Particle p = new ChickenParticle(this.Position, this.Speed, this.RandomGenerator, (uint)this.MaxSpeedCoord, ((ChickenParticle)this).MinMaxTickPerLay); produced.Add(p); var baseProduced = base.Update(); produced.AddRange(baseProduced); return(produced); }
static void GenerateInitialData(Engine engine) { var emitterPosition = new MatrixCoords(29, 0); var emitterSpeed = new MatrixCoords(0, 0); var emitter = new ParticleEmitter(emitterPosition, emitterSpeed, randGenerator, 5, 2, GenerateRandomParticle); engine.AddParticle(emitter); //check attractor var attractorPosition = new MatrixCoords(10, 10); var attractor = new ParticleAttractor(attractorPosition, new MatrixCoords(0, 0), 1); engine.AddParticle(attractor); // 02.Test the ChaoticParticle through the ParticleSystemMain class // Create chaotic particle and add it to the engine var chaoticParticle = new ChaoticParticle(new MatrixCoords(15, 15), new MatrixCoords(1, 1), randGenerator); engine.AddParticle(chaoticParticle); // 04.Test the ChickenParticle class through the ParcticleSystemMain class. var chickenParticle = new ChickenParticle(new MatrixCoords(10, 10), new MatrixCoords(-1, 2), randGenerator, 20); engine.AddParticle(chickenParticle); // 06.Test the ParticleRepeller class through the ParticleSystemMain class // create repeller with large radius and power to see the result // because in one moment there are too many new chicken particles created var particleRepeller = new ParticleRepeller(new MatrixCoords(20, 20), new MatrixCoords(0, 0), 10, 20.0); engine.AddParticle(particleRepeller); }
public override IEnumerable<Particle> Update() { tickCounter++; var newParticles = new List<Particle>(); double totalSpeed = Math.Sqrt(this.Speed.Row * this.Speed.Row + this.Speed.Col * this.Speed.Col); if (tickCounter > 4 * ChickenParticle.totalChickenParticles && totalSpeed < maxSpeed) { waitCounter++; if (waitCounter > ticksToWait) { ChickenParticle.totalChickenParticles++; MatrixCoords initialSpeed = new MatrixCoords(0, 0); var newParticle = new ChickenParticle(this.Position, initialSpeed, ChickenParticle.totalChickenParticles); newParticles.Add(newParticle); tickCounter = 0; waitCounter = 0; } } else { this.Move(); } return newParticles; }
static void Main(string[] args) { var renderer = new ConsoleRenderer(Rows, Cols); var particleOperator = new AdvancedParticleOperatorWithRepeller(); var engine = new Engine(renderer, particleOperator, null, 300); var chaoticParticle = new ChaoticParticle(new MatrixCoords(20, 20), new MatrixCoords(0, 0), RandomGenerator, 1); engine.AddParticle(chaoticParticle); var attractor = new ParticleAttractor(new MatrixCoords(15, 15), new MatrixCoords(0, 0), 2); engine.AddParticle(attractor); var repeller = new ParticleRepeller(new MatrixCoords(20, 15), new MatrixCoords(0, 0), 1, 5); engine.AddParticle(repeller); engine.AddParticle(new Particle(new MatrixCoords(20, 20), new MatrixCoords(0, 0))); var chickenParticle = new ChickenParticle(new MatrixCoords(15, 15), new MatrixCoords(0, 0), RandomGenerator, 3, new MatrixCoords(3, 6)); engine.AddParticle(chickenParticle); //GenerateInitialData(engine); engine.Run(); }
public override IEnumerable <Particle> Update() { List <Particle> result = new List <Particle>(); int randomStop = Rnd.Next(11); if (randomStop == 10) { var addedChickenParticle = new ChickenParticle(this.Position, this.Speed, this.Rnd, this.MaxSpeed); result.Add(addedChickenParticle); return(result); } else { return(base.Update()); } }
// Create a ChickenParticle class. // The ChickenParticle class moves like a ChaoticParticle, // but randomly stops at different positions for several simulation ticks and, // for each of those stops, creates (lays) a new ChickenParticle. static void Main() { IRenderer renderer = new ConsoleRenderer(MaxRows, MaxCols); IParticleOperator particleOperator = new ParticleUpdater(); int sleepTimeMs = 250; Engine engine = new Engine(renderer, particleOperator, sleepTimeMs); // Create a ChickenParticle (it will spawn other particles) MatrixCoords initialPosition = new MatrixCoords(MaxRows / 2, MaxCols / 2); MatrixCoords initialSpeed = new MatrixCoords(0, 0); Particle chickenParticle = new ChickenParticle(initialPosition, initialSpeed); engine.AddParticle(chickenParticle); SetConsole(); engine.Run(); }
// Chicken particle stops to lay egg, if currentRnadomNumber == 0 // Else update its position and generate new random number public override IEnumerable<Particle> Update() { // If we don't produce new chickens, just return the list of particles from the base class // If we produce, add the particles from the base class and add the new chicken if (currentRandomNumber != 0) { currentRandomNumber = GenRandomNumber(); return base.Update(); } // Chicken can be produced only if current number is 0 else { // On each iteration, decrement tick to lay particle this.currentTicksToLayParticle--; // If ticks count is 0, we create new chicken particle, with same position as its "mother" if (currentTicksToLayParticle == 0) { // Generate new random number, so the moving of the "mother" can continue this.currentRandomNumber = GenRandomNumber(); this.currentTicksToLayParticle = this.ticksToLayParticle; ChickenParticle currentlyProducedChickenParticle = new ChickenParticle(this.Position, new MatrixCoords(), this.MatrixSize, this.randomGenerator, this.ticksToLayParticle); List<Particle> producedParticles = new List<Particle>(); // Add the base update and the currently produced chicken producedParticles.AddRange(base.Update()); producedParticles.Add(currentlyProducedChickenParticle); return producedParticles; } else { // While the chicken is waiting to lay egg, it is not updated. Just return empy list return new List<Particle>(); } } }
// Chicken particle stops to lay egg, if currentRnadomNumber == 0 // Else update its position and generate new random number public override IEnumerable <Particle> Update() { // If we don't produce new chickens, just return the list of particles from the base class // If we produce, add the particles from the base class and add the new chicken if (currentRandomNumber != 0) { currentRandomNumber = GenRandomNumber(); return(base.Update()); } // Chicken can be produced only if current number is 0 else { // On each iteration, decrement tick to lay particle this.currentTicksToLayParticle--; // If ticks count is 0, we create new chicken particle, with same position as its "mother" if (currentTicksToLayParticle == 0) { // Generate new random number, so the moving of the "mother" can continue this.currentRandomNumber = GenRandomNumber(); this.currentTicksToLayParticle = this.ticksToLayParticle; ChickenParticle currentlyProducedChickenParticle = new ChickenParticle(this.Position, new MatrixCoords(), this.MatrixSize, this.randomGenerator, this.ticksToLayParticle); List <Particle> producedParticles = new List <Particle>(); // Add the base update and the currently produced chicken producedParticles.AddRange(base.Update()); producedParticles.Add(currentlyProducedChickenParticle); return(producedParticles); } else { // While the chicken is waiting to lay egg, it is not updated. Just return empy list return(new List <Particle>()); } } }
public override IEnumerable<Particle> Update() { if (layingEggs && counter == 0) { this.counter = 5; this.layingEggs = false; ChickenParticle littleChicken = new ChickenParticle( new MatrixCoords(this.Position.Row, this.Position.Col-1), new MatrixCoords(this.Speed.Row,this.Speed.Col)); return new List<Particle>(){littleChicken}; } if (this.randomSpeed.Next(0, 10) < 2) { this.layingEggs = true; return base.Update(); } else { return base.Update(); } }
public override IEnumerable<Particle> Update() { List<Particle> baseParticles = new List<Particle>(base.Update()); if (this.movingInterval > 0) { this.movingInterval--; } else { HandleBreaks(); if (!isSpawned) { int rowSpeed = this.randomGenerator.Next(-1, 2); int colSpeed = this.randomGenerator.Next(-1, 2); var speed = new MatrixCoords(rowSpeed, colSpeed); var layProduct = new ChickenParticle(this.Position, speed, this.randomGenerator); baseParticles.Add(layProduct); isSpawned = !isSpawned; } } return baseParticles; }
public override IEnumerable<Particle> Update() { if (this.timeToLay > 0) { this.timeToLay--; return base.Update(); } List<Particle> produced = new List<Particle>(); if (this.layingTime > 0) { this.layingTime--; return produced; } SetRandomLayingTimeAndTimeToLay(); Particle p = new ChickenParticle(this.Position, this.Speed, this.RandomGenerator, (uint)this.MaxSpeedCoord, ((ChickenParticle)this).MinMaxTickPerLay); produced.Add(p); var baseProduced = base.Update(); produced.AddRange(baseProduced); return produced; }
public override IEnumerable <Particle> Update() { List <Particle> baseParticles = new List <Particle>(base.Update()); if (this.movingInterval > 0) { this.movingInterval--; } else { HandleBreaks(); if (!isSpawned) { int rowSpeed = this.randomGenerator.Next(-1, 2); int colSpeed = this.randomGenerator.Next(-1, 2); var speed = new MatrixCoords(rowSpeed, colSpeed); var layProduct = new ChickenParticle(this.Position, speed, this.randomGenerator); baseParticles.Add(layProduct); isSpawned = !isSpawned; } } return(baseParticles); }
static Particle GenerateRandomParticle(ParticleEmitter emitterParameter) { MatrixCoords particlePos = emitterParameter.Position; int particleRowSpeed = emitterParameter.RandomGenerator.Next(emitterParameter.MinSpeedCoord, emitterParameter.MaxSpeedCoord + 1); int particleColSpeed = emitterParameter.RandomGenerator.Next(emitterParameter.MinSpeedCoord, emitterParameter.MaxSpeedCoord + 1); MatrixCoords particleSpeed = new MatrixCoords(particleRowSpeed, particleColSpeed); Particle generated = null; int particleTypeIndex = emitterParameter.RandomGenerator.Next(0, 3); switch (particleTypeIndex) { case 0: generated = new Particle(particlePos, particleSpeed); break; case 1: uint lifespan = (uint)emitterParameter.RandomGenerator.Next(8); generated = new DyingParticle(particlePos, particleSpeed, lifespan); break; case 2: generated = new ChaoticParticle(particlePos, particleSpeed,RandomGenerator); break; case 3: generated = new ChickenParticle(particlePos, particleSpeed, RandomGenerator); break; default: throw new Exception("No such particle for this particleTypeIndex"); } return generated; }
private static void GenerateInitialData(Engine engine) { /*engine.AddParticle( * new Particle( * new MatrixCoords(0, 8), * new MatrixCoords(-1, 0)) * ); * * engine.AddParticle( * new DyingParticle( * new MatrixCoords(20, 5), * new MatrixCoords(-1, 1), * 12) * );*/ // Test the ChaoticParticle. var chaoticParticle = new ChaoticParticle( new MatrixCoords(20, 25), new MatrixCoords(-1, 1), RandomGenerator); engine.AddParticle(chaoticParticle); // Test the ChickenParticle. var chickenParticle = new ChickenParticle( new MatrixCoords(25, 15), new MatrixCoords(0, 1), RandomGenerator); engine.AddParticle(chickenParticle); // Test the ParticleRepeller. var particleRepeller = new ParticleRepeller( new MatrixCoords(10, 13), new MatrixCoords(0, 0), 2, 10); engine.AddParticle(particleRepeller); var emitterPosition = new MatrixCoords(19, 15); var emitterSpeed = new MatrixCoords(0, 0); var emitter = new ParticleEmitter(emitterPosition, emitterSpeed, RandomGenerator, 5, 2, GenerateRandomParticle ); engine.AddParticle(emitter); var attractorPosition = new MatrixCoords(10, 3); var attractor = new ParticleAttractor( attractorPosition, new MatrixCoords(0, 0), 1); var attractorPosition2 = new MatrixCoords(10, 13); var attractor2 = new ParticleAttractor( attractorPosition2, new MatrixCoords(0, 0), 3); // engine.AddParticle(attractor); // engine.AddParticle(attractor2); }
private static void GenerateInitialData(Engine engine) { engine.AddParticle( new Particle( new MatrixCoords(0, 10), new MatrixCoords(1, 1)) ); var emitterPosition = new MatrixCoords(29, 0); var emitterSpeed = new MatrixCoords(0, 0); var emitter = new ParticleEmitter(emitterPosition, emitterSpeed, rand, 5, 2, GenerateRandomParticle ); engine.AddParticle(emitter); var emitterPosition2 = new MatrixCoords(2, 10); var emitterSpeed2 = new MatrixCoords(10, 5); var emitter2 = new ParticleEmitter(emitterPosition2, emitterSpeed2, rand, 5, 2, GenerateRandomParticle ); engine.AddParticle(emitter2); var emitterPosition3 = new MatrixCoords(15, 0); var emitterSpeed3 = new MatrixCoords(0, 0); var emitter3 = new ParticleEmitter(emitterPosition3, emitterSpeed3, rand, 5, 2, GenerateRandomParticle ); engine.AddParticle(emitter3); var attractorPosition = new MatrixCoords(10, 3); var attractor = new ParticleAttractor( attractorPosition, new MatrixCoords(0, 0), 1); var attractorPosition2 = new MatrixCoords(10, 13); var attractor2 = new ParticleAttractor( attractorPosition2, new MatrixCoords(0, 0), 3); engine.AddParticle(attractor); engine.AddParticle(attractor2); var chaoticParticle = new ChaoticParticle(new MatrixCoords(15, 15), new MatrixCoords(1, 1), rand, 50, 50); //engine.AddParticle(chaoticParticle); var chickenParticle = new ChickenParticle(new MatrixCoords(15, 15), new MatrixCoords(1, 1), rand, 50, 50, 20, 10); //engine.AddParticle(chickenParticle); var repellerParticle = new ParticleRepeller(new MatrixCoords(15, 15), new MatrixCoords(0, 0), 1, 8); //engine.AddParticle(repellerParticle); }
private static void GenerateInitialData(Engine engine) { /*engine.AddParticle( new Particle( new MatrixCoords(0, 8), new MatrixCoords(-1, 0)) ); engine.AddParticle( new DyingParticle( new MatrixCoords(20, 5), new MatrixCoords(-1, 1), 12) );*/ // Test the ChaoticParticle. var chaoticParticle = new ChaoticParticle( new MatrixCoords(20, 25), new MatrixCoords(-1, 1), RandomGenerator); engine.AddParticle(chaoticParticle); // Test the ChickenParticle. var chickenParticle = new ChickenParticle( new MatrixCoords(25, 15), new MatrixCoords(0, 1), RandomGenerator); engine.AddParticle(chickenParticle); // Test the ParticleRepeller. var particleRepeller = new ParticleRepeller( new MatrixCoords(10, 13), new MatrixCoords(0, 0), 2, 10); engine.AddParticle(particleRepeller); var emitterPosition = new MatrixCoords(19, 15); var emitterSpeed = new MatrixCoords(0, 0); var emitter = new ParticleEmitter(emitterPosition, emitterSpeed, RandomGenerator, 5, 2, GenerateRandomParticle ); engine.AddParticle(emitter); var attractorPosition = new MatrixCoords(10, 3); var attractor = new ParticleAttractor( attractorPosition, new MatrixCoords(0, 0), 1); var attractorPosition2 = new MatrixCoords(10, 13); var attractor2 = new ParticleAttractor( attractorPosition2, new MatrixCoords(0, 0), 3); // engine.AddParticle(attractor); // engine.AddParticle(attractor2); }
private static void GenerateInitialData(Engine engine) { engine.AddParticle( new Particle( new MatrixCoords(0, 10), new MatrixCoords(1, 1)) ); /*engine.AddParticle( * new DyingParticle( * new MatrixCoords(20, 5), * new MatrixCoords(-1, 1), * 12) * ); */ var emitterPosition = new MatrixCoords(29, 0); var emitterSpeed = new MatrixCoords(0, 0); var emitter = new ParticleEmitter(emitterPosition, emitterSpeed, RandomGenerator, 5, 2, GenerateRandomParticle ); engine.AddParticle(emitter); var emitterPosition2 = new MatrixCoords(0, 0); var emitterSpeed2 = new MatrixCoords(0, 0); var emitter2 = new ParticleEmitter(emitterPosition2, emitterSpeed2, RandomGenerator, 5, 2, GenerateRandomParticle ); engine.AddParticle(emitter2); var emitterPosition3 = new MatrixCoords(15, 0); var emitterSpeed3 = new MatrixCoords(0, 0); var emitter3 = new ParticleEmitter(emitterPosition3, emitterSpeed3, RandomGenerator, 5, 2, GenerateRandomParticle ); engine.AddParticle(emitter3); var attractorPosition = new MatrixCoords(10, 3); var attractor = new ParticleAttractor( attractorPosition, new MatrixCoords(0, 0), 1); var attractorPosition2 = new MatrixCoords(10, 13); var attractor2 = new ParticleAttractor( attractorPosition2, new MatrixCoords(0, 0), 3); //engine.AddParticle(attractor); //engine.AddParticle(attractor2); var chaoticParticle = new ChaoticParticle(new MatrixCoords(15, 15), new MatrixCoords(1, 1), RandomGenerator, 50, 50); //engine.AddParticle(chaoticParticle); var chickenParticle = new ChickenParticle(new MatrixCoords(15, 15), new MatrixCoords(1, 1), RandomGenerator, 50, 50, 20, 10); //engine.AddParticle(chickenParticle); var repellerParticle = new ParticleRepeller(new MatrixCoords(15, 15), new MatrixCoords(0, 0), 1, 8); engine.AddParticle(repellerParticle); }
private static void GenerateInitialData(Engine engine) { engine.AddParticle( new DyingParticle( new MatrixCoords(20, 5), new MatrixCoords(-1, 1), 12) ); ////Particle Emitter var emitterPosition = new MatrixCoords(29, 0); var emitterSpeed = new MatrixCoords(0, 0); var emitter = new ParticleEmitter(emitterPosition, emitterSpeed, RandomGenerator, 5, 2, GenerateRandomParticle ); //engine.AddParticle(emitter); //// Paritcle Attractor var attractorPosition = new MatrixCoords(15, 20); var attractor = new ParticleAttractor( attractorPosition, new MatrixCoords(0, 0), 3); //engine.AddParticle(attractor); //// IMPORTANT! //// Exercises 1 and 2 -> //// check classes: ChaoticParticle, AdvancedParticalUpdater var crazyPosition = new MatrixCoords(15, 12); var crazy = new ChaoticParticle(crazyPosition, new MatrixCoords(0, 0), RandomGenerator, 1); var crazyPositiontoo = new MatrixCoords(15, 15); var crazytoo = new ChaoticParticle(crazyPositiontoo, new MatrixCoords(0, 0), RandomGenerator, 1); var crazyPositionmore = new MatrixCoords(15, 19); var crazymore = new ChaoticParticle(crazyPositionmore, new MatrixCoords(0, 0), RandomGenerator, 1); engine.AddParticle(crazy); engine.AddParticle(crazytoo); engine.AddParticle(crazymore); //// IMPORTANT! //// Exercises 3 and 4 -> //// check classes: ChickenParticle, AdvancedParticalUpdater var chickenPosition = new MatrixCoords(15, 12); var chcken = new ChickenParticle(chickenPosition, new MatrixCoords(0, 0), RandomGenerator, 1, 4); engine.AddParticle(chcken); //// IMPORTANT! //// Exercises 5 and 6 -> //// check classes: ParticleEmitter, AdvancedParticalUpdater var reppelerPosition = new MatrixCoords(18, 28); var reppeler = new ParticleRepeller( reppelerPosition, new MatrixCoords(0, 0), 3); //engine.AddParticle(reppeler); }