Advertisement
d_brezoev

ChickenParticle

Feb 25th, 2014
138
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 = 2;                
  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.                 int r = this.rand.Next(-1, 2);
  38.                 if (!this.ProducedEggs)
  39.                 {
  40.                    
  41.                     for (int i = 0; i <= ChickenParticle.maxEggsToProducePerTick; i++)
  42.                     {
  43.                         int dir = this.rand.Next(-1, 2);
  44.                         int dir2 = this.rand.Next(-1, 2);
  45.                         Particle p = new Particle(this.Position, new MatrixCoords(dir,dir2));
  46.                         produced.Add(p);                      
  47.                     }
  48.                     var baseProduced = base.Update();
  49.                     produced.AddRange(baseProduced);
  50.                     this.ProducedEggs = true;
  51.                     return produced;
  52.                 }                  
  53.             }
  54.  
  55.             this.framesMovingCount++;
  56.             if (this.framesMovingCount == this.FreezeAfter)
  57.             {
  58.                 this.Freezed = true;
  59.                 this.framesMovingCount = 0;
  60.             }
  61.             return base.Update();
  62.         }
  63.  
  64.         protected override void Move()
  65.         {
  66.             if (!this.Freezed)
  67.             {
  68.                 int row = this.rand.Next(-1, 2);
  69.                 int col = this.rand.Next(-1, 2);
  70.                 this.Position += new MatrixCoords(row, col);
  71.             }
  72.             else
  73.             {
  74.                 this.Position += new MatrixCoords(0, 0);
  75.             }
  76.  
  77.         }
  78.         public override char[,] GetImage()
  79.         {
  80.             return new char[,] { { '9' } };
  81.         }
  82.     }    
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement