Advertisement
d_brezoev

ChickenParticle

Feb 25th, 2014
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading;
  4.  
  5. namespace ParticleSystem
  6. {
  7.     public class ChickenParticle : ChaoticParticle
  8.     {
  9.         private const int maxEggsToProducePerTick = 10;                
  10.         private int framesFreezedCount;
  11.         private int framesMovingCount;        
  12.  
  13.         public ChickenParticle(MatrixCoords position, MatrixCoords speed, int freezeAfter, int freezeTime)
  14.             : base(position, speed)
  15.         {
  16.             this.FreezeTime = freezeTime;
  17.             this.FreezeAfter = freezeAfter;
  18.             this.Freezed = false;
  19.         }
  20.         public int FreezeTime { get; private set; }
  21.         public int FreezeAfter { get; private set; }
  22.         public bool Freezed { get; private set; }
  23.         public bool ProducedEggs { get; private set; }
  24.         public override IEnumerable<Particle> Update()
  25.         {
  26.             if (this.Freezed)
  27.             {
  28.                 this.framesFreezedCount++;
  29.                 if (this.framesFreezedCount == this.FreezeTime)
  30.                 {
  31.                     this.Freezed = false;
  32.                     this.framesFreezedCount = 0;
  33.                     this.ProducedEggs = false;
  34.                 }
  35.  
  36.                 List<Particle> produced = new List<Particle>();
  37.                
  38.                 if (!this.ProducedEggs)
  39.                 {                    
  40.                     for (int i = 0; i <= ChickenParticle.maxEggsToProducePerTick; i++)
  41.                     {
  42.                         Particle p = new Particle(this.Position, new MatrixCoords(1,0));
  43.                         produced.Add(p);
  44.                     }
  45.                     var baseProduced = base.Update();
  46.                     produced.AddRange(baseProduced);
  47.                     this.ProducedEggs = true;
  48.                     return produced;
  49.                 }                  
  50.             }
  51.  
  52.             this.framesMovingCount++;
  53.             if (this.framesMovingCount == this.FreezeAfter)
  54.             {
  55.                 this.Freezed = true;
  56.                 this.framesMovingCount = 0;
  57.             }
  58.             return base.Update();
  59.         }
  60.  
  61.         protected override void Move()
  62.         {
  63.             if (!this.Freezed)
  64.             {
  65.                 int row = this.rand.Next(-1, 2);
  66.                 int col = this.rand.Next(-1, 2);
  67.                 this.Position += new MatrixCoords(row, col);
  68.             }
  69.             else
  70.             {
  71.                 this.Position += new MatrixCoords(0, 0);
  72.             }
  73.  
  74.         }
  75.         public override char[,] GetImage()
  76.         {
  77.             return new char[,] { { '9' } };
  78.         }
  79.     }    
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement