//New Player
        public PlayerManager(string name)
        {
            if (name != "")
            {
                var db = new Project2NetContext();
                var rand = MainWindow.Random;
                //Randomisation du point de départ
                var x = rand.Next(-500, 500);
                var y = rand.Next(-500, 500);
                var temp = db.Cells.FirstOrDefault(cell => cell.PosX == x && cell.PosY == y);

                if (temp != null)
                {
                    Player = new Player
                        {
                            Name = name, 
                            MaxHp = 500, 
                            Hp = 500, 
                            Xp = 0, 
                            CurrentCellId = temp.Id
                        };
                }
                else
                {
                    var cellM = new CellManager(x, y);
                    Player = new Player
                        {
                            Name = name,
                            MaxHp = 500,
                            Hp = 500,
                            Xp = 0,
                            CurrentCellId = cellM.Cell.Id
                        };
                }
                var weaponM = new WeaponManager(0, true);

                Player.WeaponInventory = new Collection<Weapon>
                    {
                        weaponM.Weapon
                    };
                Player.ObjectInventory = new Collection<Item>();

                db.Players.Add(Player);
                db.SaveChanges();
            }
            else
            {
                Player = null;
            }
        }
        public void ExecMoveTo(string direction)
        {
            var cellM = new CellManager((int)_playerM.Player.CurrentCellId);
            var canMoveTo = cellM.ToArrayCanMoveTo();
            var index = -1;
            switch (direction)
            {
                case "nord":
                    index = 3;
                    break;
                case "est":
                    index = 0;
                    break;
                case "sud":
                    index = 1;
                    break;
                case "ouest":
                    index = 2;
                    break;
                default:
                    return;
            }
            if (canMoveTo[index] == '1')
            {
                cellM = new CellManager(cellM.Cell.PosX, cellM.Cell.PosY, index);
                /* Va-t-il y avoir un combat ?*/
                var rand = MainWindow.Random;


                if (rand.Next(0, 101) < cellM.Cell.MonsterRate) //YEAAAAAAH CA VA CHAUFFER A DONF 
                {
                    _playerM.Player.CurrentCellId = cellM.Cell.Id;
                    MessageList.Insert(0, cellM.Cell.Description);
                    _playerM.Save();
                    ExecRefreshGrid();
                    SoundHelper.PlayFromCategory(SoundHelper.Categories.Fight);
                    MessageBox.Show("Vous avez rencontré un monstre, le combat va commencer !");

                    NavigationHelper.MoveToPage(new CombatPage());
                }
                else
                {
                    _playerM.Player.CurrentCellId = cellM.Cell.Id;
                    MessageList.Insert(0, cellM.Cell.Description);
                    _playerM.Save();
                    ExecRefreshGrid();
                }
            }
            else
            {
                MessageList.Insert(0,"Vous ne trouvez pas de chemin pour aller ici !");
            }
        }
 public void ExecSearchInZone()
 {
     
     var cellM = new CellManager((int)_playerM.Player.CurrentCellId);
     if (cellM.HadBeenVisited())
     {
         MessageBox.Show("Vous avez déja fouillé cette case, voyons !");
     }
     else
     {
         cellM.IsVisited();
         var rand = MainWindow.Random;
         if (rand.Next(0, 101) > 90) //10 % de chances de trouver un item
         {
             var item = ActivePlayerManager.AddItem();
             MessageList.Insert(0, String.Format("=> {0} - Niveau {1}", item.ObjectType.Name, item.ObjectType.Level));
             MessageList.Insert(0, "Quelle chance ! Vous avez trouvé un objet !");
             Items.Add(item);
         }
         else if (rand.Next(0, 101) > 95) //5% de trouver une arme
         {
             var weapon = ActivePlayerManager.AddWeapon();
             MessageList.Insert(0, String.Format("=> {0} - Niveau {1}", weapon.Name, weapon.Level));
             MessageList.Insert(0, "Petit veinard ! Vous avez trouvé une arme !");
             Weapons.Add(weapon);
         }
         else
         {
             MessageList.Insert(0,"Vous n'avez rien trouvé !");
         }
     }
 }
 public bool CanSearchInZone(object o)
 {
     var cellM = new CellManager((int)_playerM.Player.CurrentCellId);
     return !cellM.HadBeenVisited();
 }