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 Anticorp : Cellule
00025 {
00026 public Anticorp(int x, int y, int spe) : base(x,y)
00027 {
00028 Life = 1000;
00029 specificite = spe;
00030 cell_plusproche = null;
00031 }
00032
00033 public Anticorp(int x, int y, int spe, int life) : base(x,y)
00034 {
00035 Life = life;
00036 specificite = spe;
00037 cell_plusproche = null;
00038 }
00039
00040 new public void Action()
00041 {
00042 Mouvement();
00043 ccol_copy = (CellulesCollection)frmMain.ccol.Clone();
00044 int tmp = 0;
00045 foreach(Cellule cell in ccol_copy)
00046 {
00047 double dst = DistTo(cell,this);
00048 if(dst < 200 && tmp == 0)
00049 {
00050 if(cell is Antigen)
00051 {
00052 if(specificite == cell.specificite)
00053 {
00054 CreatedCI(this,cell);
00055 frmMain.log.NewEvent("Creation d'un CI sur l'Ag de spéficité " + cell.specificite.ToString());
00056 tmp++;
00057 }
00058 }
00059 else if(cell is VIH)
00060 {
00061 if(specificite == cell.specificite)
00062 {
00063 CreatedCI(this,cell);
00064 frmMain.log.NewEvent("Creation d'un CI sur le VIH n°" + cell.index.ToString());
00065 tmp++;
00066 }
00067 }
00068 }
00069 }
00070 return;
00071 }
00072
00073 private void CreatedCI(Cellule ac,Cellule ag)
00074 {
00075 int x = ag.Location.X;
00076 int y = ag.Location.Y;
00077 frmMain.ccol.RemoveAt(ac.index);
00078 frmMain.ccol.RemoveAt(ag.index);
00079 CI ci1 = new CI(x,y);
00080 frmMain.ccol.Add(ci1);
00081 }
00082
00083 private void Mouvement()
00084 {
00085 ccol_copy = (CellulesCollection)frmMain.ccol.Clone();
00086 if(cell_plusproche != null)
00087 {
00088 if((TestIfAlive(cell_plusproche)))
00089 {
00090 if(cell_plusproche.Location.X < this.Location.X)
00091 this.Location.X = this.Location.X - 5;
00092 else
00093 this.Location.X = this.Location.X + 5;
00094 if(cell_plusproche.Location.Y < this.Location.Y)
00095 this.Location.Y = this.Location.Y - 5;
00096 else
00097 this.Location.Y = this.Location.Y + 5;
00098 }
00099 else
00100 cell_plusproche = null;
00101 }
00102 else
00103 {
00104 foreach(Cellule cell in ccol_copy)
00105 {
00106 if(DistTo(this,cell) < 20000)
00107 {
00108 if(cell is Antigen)
00109 {
00110 if(cell.specificite == this.specificite)
00111 {
00112 if(!(TestIfDejaSelect(cell)))
00113 {
00114 if(cell_plusproche == null)
00115 cell_plusproche = cell;
00116 if(DistTo(this,cell_plusproche) > DistTo(this,cell))
00117 cell_plusproche = cell;
00118 }
00119 }
00120 }
00121 }
00122 }
00123 int tmp2 = rnd.Next(2);
00124 int x,y;
00125 if(tmp2 == 0)
00126 {
00127 x = this.Location.X + rnd.Next(-5,5);
00128 y = this.Location.Y + rnd.Next(-5,5);
00129 }
00130 else
00131 {
00132 x = this.Location.X - rnd.Next(-5,5);
00133 y = this.Location.Y - rnd.Next(-5,5);
00134 }
00135 this.Location.X = x;
00136 this.Location.Y = y;
00137 }
00138 }
00139
00140 private bool TestIfAlive(Cellule cell)
00141 {
00142 ccol_copy = (CellulesCollection)frmMain.ccol.Clone();
00143 bool tmp = false;
00144 foreach(Cellule icell in ccol_copy)
00145 {
00146 if(icell.index == cell.index && icell.specificite == cell.specificite && tmp == false)
00147 {
00148 if(icell is Antigen)
00149 {
00150 double dst = DistTo(cell,icell);
00151 if(dst < 200)
00152 tmp = true;
00153 }
00154 }
00155 }
00156 return tmp;
00157 }
00158
00159 private bool TestIfDejaSelect(Cellule cell)
00160 {
00161 ccol_copy = (CellulesCollection)frmMain.ccol.Clone();
00162 bool tmp = false;
00163 foreach(Cellule icell in ccol_copy)
00164 {
00165 if(icell is Anticorp && tmp == false)
00166 {
00167 if(icell.cell_plusproche == cell)
00168 tmp = true;
00169 else
00170 tmp = false;
00171 }
00172 }
00173 return tmp;
00174 }
00175 }
00176 }