//Initialize the matrix reading the type of ground from the file mapname and creating the ground elements
        public MapMatrix(int x, int y, string mapname)
        {
            _x = x;
            _y = y;
            Ramdom gui = new Ramdom();
            mapID = gui.RandomString(32);
            screen = Screen.Instance;
            _mapname = mapname;
            try
            {
                string[] lines = System.IO.File.ReadAllLines(mapname.ToString());
                int Index_x;
                int Limit = x - 1;
                int Index_y;
                int Limit_Y = y - 1;
                for (Index_x = 0; Index_x <= Limit; Index_x++)
                {
                    for (Index_y = 0; Index_y <= Limit_Y; Index_y++)
                    {
                        Ground NewGround = new Ground(this, lines[Index_x].Substring(Index_y, 1), new Point(Index_x, Index_y));

                        _mapM.Add(NewGround);
                        screen.paint(NewGround.coordn, NewGround.groundtype, NewGround.ListPlant.Count);
                    }
                }
            }
            catch (Exception e)
            {
                Console.Write("Error in MapMatrix constructor");
                Console.Write(e.Message);
            }
        }
 public Plant(DNA dna, Ground parent)
     : base(dna, parent)
 {
     _status = kindstatus.Seed;
     //Get the generation from the DNA
     Generation = dna.Generation;
 }
 public AbtractPlant(DNA dna, Ground parent)
 {
     Ramdom gui = new Ramdom();
     aliveID = gui.RandomString(32);
     _dna = new DNAPlant(dna, aliveID);
     _parent = parent;
 }
        //Main factory where all the beings will be created
        public override IAlive CreateLive(string AliveBeing,DNA dna, Ground parent)
        {
            switch (AliveBeing) {
                case "plant":
                    Plant newplant = new Plant(dna, parent);
                    return newplant;
                default:
                    throw new ApplicationException(string.Format("Being '{0}' cannot be created", AliveBeing));

            }
        }
 public static List<Ground> load_ground(MapMatrix parent)
 {
     var query = Context.DGROUND.Where(S => S.PARENT == parent.MapID);
     List<Ground> list = new List<Ground>();
     int index = 0;
     foreach (DGROUND item in query)
     {
         Ground newGround =
             new Ground(parent, item.GROUNDTYPE, new Point((int)item.X, (int)item.Y));
         newGround.GroundID = item.GROUND_ID;
         newGround.Damage = (int) item.DAMAGE;
         newGround.Absortion = (double)item.ABSORTION;
         list.Add(newGround);
         index++;
     }
     return list;
 }
        public static List<IPlant> load_plants(Ground parent,kindstatus status)
        {
            DPLANT dna = new DPLANT();
            List<IPlant> List = new List<IPlant>();
            List<DPLANT> query;
            if(status == kindstatus.Growup || status ==kindstatus.Reproduction){
            query = Context.DPLANT.Where(S => S.PARENT_ID == parent.GroundID &&
                !S.STATUS.Contains( kindstatus.Seed.ToString()) ).ToList();
            }
            else{
             query = Context.DPLANT.Where(S => S.PARENT_ID == parent.GroundID &&
                S.STATUS.Contains( kindstatus.Seed.ToString()) ).ToList();
            }
            foreach (DPLANT item in query)
            {

                Plant newplant = new Plant(parent, item.aliveID);
                newplant.CurrentLifeCycle = (int)item.CURRENTLIFECYCLE;
                newplant.Generation = (int)item.GENERATION;
                newplant.NextReproductionCycle = (int)item.NEXTREPRODUCTIONCYCLE;
                newplant.Size = (int)item.SIZE;
                newplant.Waterdeposit = (int)item.WATERDEPOSIT;

                switch (item.STATUS)
                {
                    case "Seed":
                        newplant.Status = kindstatus.Seed;
                        break;
                    case "Growup":
                        newplant.Status = kindstatus.Growup;
                        break;
                    case "Reproduction":
                        newplant.Status = kindstatus.Reproduction;
                        break;
                }

                List.Add(newplant);
            }
            return List;
        }
 public abstract IAlive CreateLive(string AliveBeing, DNA dna , Ground parent);
 public static void save_ground(Ground Ground)
 {
     DGROUND ground = new DGROUND();
     ground.GROUND_ID = Ground.GroundID;
     ground.PARENT = Ground.Parent;
     ground.X = Ground.coordn.positionx;
     ground.Y = Ground.coordn.positiony;
     ground.GROUNDTYPE = Ground.groundtype;
     ground.DAMAGE = Ground.Damage;
     ground.ABSORTION = Ground.Absortion;
     Context.AddToDGROUND(ground);
     Console.WriteLine(Context.SaveChanges());
 }
 public Plant(Ground parent,string ID)
     : base(parent)
 {
     Generation = dna.Generation;
 }
 public AbtractPlant(Ground parent)
 {
 }