00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 using System;
00020
00021 namespace SimImmuno
00022 {
00023 [Serializable]
00024 public class Phagocyte : Cellule
00025 {
00026 public Phagocyte(int x, int y) : base(x,y)
00027 {
00028 Life = 99999999;
00029 cell_plusproche = null;
00030 }
00031
00032 public Phagocyte(int x, int y, int life) : base(x,y)
00033 {
00034 Life = life;
00035 cell_plusproche = null;
00036 }
00037
00038 new public void Action()
00039 {
00040 Mouvement();
00041 ccol_copy = (CellulesCollection)frmMain.ccol.Clone();
00042 int tmp = 0;
00043 foreach(Cellule cell in ccol_copy)
00044 {
00045 double dst = DistTo(cell,this);
00046 if(dst < 450 && tmp == 0)
00047 {
00048 if(cell is CI)
00049 {
00050 Phagocytose(cell);
00051 frmMain.log.NewEvent("Phagocytose du CI n°" + cell.index.ToString());
00052 tmp++;
00053 }
00054 else if(cell is Debris)
00055 {
00056 Phagocytose(cell);
00057 frmMain.log.NewEvent("Phagocytose du débris n°" + cell.index.ToString());
00058 tmp++;
00059 }
00060 }
00061 }
00062 return;
00063 }
00064
00065 private void Phagocytose(Cellule ci)
00066 {
00067 frmMain.ccol.RemoveAt(ci.index);
00068 cell_plusproche = null;
00069 }
00070
00071 private void Mouvement()
00072 {
00073 ccol_copy = (CellulesCollection)frmMain.ccol.Clone();
00074 if(cell_plusproche != null)
00075 {
00076 if((TestIfAlive(cell_plusproche)))
00077 {
00078 if(cell_plusproche.Location.X < this.Location.X)
00079 this.Location.X = this.Location.X - 2;
00080 else
00081 this.Location.X = this.Location.X + 2;
00082 if(cell_plusproche.Location.Y < this.Location.Y)
00083 this.Location.Y = this.Location.Y - 2;
00084 else
00085 this.Location.Y = this.Location.Y + 2;
00086 }
00087 else
00088 cell_plusproche = null;
00089 }
00090 else
00091 {
00092 foreach(Cellule cell in ccol_copy)
00093 {
00094 if(DistTo(this,cell) < 80000)
00095 {
00096 if(cell is CI || cell is Debris)
00097 {
00098 if(!(TestIfDejaSelect(cell)))
00099 {
00100 if(cell_plusproche == null)
00101 cell_plusproche = cell;
00102 if(DistTo(this,cell_plusproche) > DistTo(this,cell))
00103 cell_plusproche = cell;
00104 }
00105 }
00106 }
00107 }
00108 int tmp2 = rnd.Next(2);
00109 int x,y;
00110 if(tmp2 == 0)
00111 {
00112 x = this.Location.X + rnd.Next(-2,2);
00113 y = this.Location.Y + rnd.Next(-2,2);
00114 }
00115 else
00116 {
00117 x = this.Location.X - rnd.Next(-2,2);
00118 y = this.Location.Y - rnd.Next(-2,2);
00119 }
00120 this.Location.X = x;
00121 this.Location.Y = y;
00122 }
00123 }
00124
00125 private bool TestIfAlive(Cellule cell)
00126 {
00127 ccol_copy = (CellulesCollection)frmMain.ccol.Clone();
00128 bool tmp = false;
00129 foreach(Cellule icell in ccol_copy)
00130 {
00131 if(icell.index == cell.index && tmp == false)
00132 {
00133 if(icell is Debris || icell is CI || icell is VIH)
00134 {
00135 double dst = DistTo(cell,icell);
00136 if(dst < 200)
00137 tmp = true;
00138 }
00139 }
00140 }
00141 return tmp;
00142 }
00143
00144 private bool TestIfDejaSelect(Cellule cell)
00145 {
00146 ccol_copy = (CellulesCollection)frmMain.ccol.Clone();
00147 bool tmp = false;
00148 foreach(Cellule icell in ccol_copy)
00149 {
00150 if(icell is Phagocyte && tmp == false)
00151 {
00152 if(icell.cell_plusproche == cell)
00153 tmp = true;
00154 else
00155 tmp = false;
00156 }
00157 }
00158 return tmp;
00159 }
00160 }
00161 }