Main Page | Packages | Class Hierarchy | Class List | Directories | File List | Class Members

Phagocyte.cs

Go to the documentation of this file.
00001 /*
00002 SimImmuno version 1.0
00003 Copyright (C) 2005 sebeuh.ajsinfo.net
00004 
00005 SimImmuno est libre, vous pouvez le redistribuer et/ou le modifier
00006 selon les termes de la Licence Publique Générale GNU publiée par la
00007 Free Software Foundation (version 2).
00008 
00009 SimImmuno est distribué car potentiellement utile, mais SANS AUCUNE GARANTIE,
00010 ni explicite ni implicite, y compris les garanties de commercialisation
00011 ou d'adaptation dans un but spécifique. Reportez-vous à la
00012 Licence Publique Générale GNU pour plus de détails.
00013 
00014 Texte de la license officielle (anglais) :
00015 http://simimmuno.ajsinfo.net/text.aspx?code=no&txt_file=GPL.txt
00016 Traduction francaise (non-officielle) :
00017 http://simimmuno.ajsinfo.net/text.aspx?code=no&txt_file=GPL-fr.txt
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 }

Generated on Sat Jun 4 15:03:42 2005 for SimImmuno by  doxygen 1.4.2