public PlayerSelectionViewModel()
 {
     Player = new Player();
     Players = new ObservableCollection<Player>();
     using (var db = new Project2NetContext())
     {
         Players = (from player in db.Players select player).ToObservableCollection();
     }
 }
        //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;
            }
        }
 //Existing Player
 public PlayerManager(int id)
 {
     var db = new Project2NetContext();
     Player = db.Players.SingleOrDefault(player => player.Id == id);
 }
        //Déplacements
        public bool Move(string direction)
        {
            var cellM = new CellManager((int)Player.CurrentCellId);
            var canMoveTo = cellM.ToArrayCanMoveTo();
            var index = -1;
            switch (direction)
            {
                case "nord":
                    index = 0;
                break;
                case "est":
                    index = 1;
                break;
                case "sud":
                    index = 2;
                break;
                case "ouest":
                    index = 3;
                break;
                default:
                return false;
            }
            if (canMoveTo[index] == '1')
            {
                cellM = new CellManager(cellM.Cell.PosX, cellM.Cell.PosY, index);
                /* Va-t-il y avoir un combat ?*/
                var rand = Program.Random;

                
                if(rand.Next(0, 101) < cellM.Cell.MonsterRate) //YEAAAAAAH CA VA CHAUFFER A DONF 
                {
                    var fight = new Combat(Player.Id, cellM.Cell);
                    var newPlayer = fight.Start();
                    Player = newPlayer;
                    Player.CurrentCellId = cellM.Cell.Id;
                    ShowPlayerInfos();
                    Console.WriteLine(GetCellManager().Cell.Description);
                    Save();

                }
                else
                {
                    Player.CurrentCellId = cellM.Cell.Id;
                    Console.WriteLine(GetCellManager().Cell.Description);
                    Save(); 
                }
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Black;
                Console.BackgroundColor = ConsoleColor.Yellow;
                Console.WriteLine("Le chemin est bloqué !");
                return false;
            }
            return true;
        }
 //Recherche des items dans la zone
 public bool SearchCellForItems()
 {
     if (GetCellManager().HadBeenVisited())
     {
         Console.WriteLine("Cette zone à déja été fouillée.");
         Console.WriteLine();
     }
     else
     {
         GetCellManager().IsVisited();
         var rand = Program.Random;
         if (rand.Next(0, 101) > 90) //10 % de chances de trouver un item
         {
             var itemM = new ItemManager((int)Math.Floor((double)Player.Xp / 100), this);
             Player = itemM.PlayerM.Player;
             Console.WriteLine("Quelle chance ! Vous avez trouvé un objet !");
             Console.WriteLine("         -> {0} - Niveau {1}", itemM.Name, itemM.Level);
         }
         else if (rand.Next(0, 101) > 95) //5% de trouver une arme
         {
             var weaponAdded = AddWeapon();
             Console.WriteLine("Petit veinard ! Vous avez trouvé une arme !");
             Console.WriteLine("         -> {0} - Niveau {1}", weaponAdded.Name, weaponAdded.Level);
             Console.WriteLine();
         }
         else
         {
             Console.WriteLine("Vous n'avez rien trouvé !");
             Console.WriteLine();
         }
     }
     return true;
 }
        //Crée un monstre en fonction du joueur et de la case(donc du biome)
        public MonsterManager(Player player, Cell cell)
        {
            var monsterLibrary1 = new List<string>()
                {
                   "Loup enragé",
                   "Ours furieux",
                   "Araignée verte",
                   "Faucon sauvage",
                   "Taureau en rut",
                   "Vipére sournoise",
                   "Bandit de grand chemin",
                   "Chat de chasse",//Utilise ses griffes comme arme de destruction massive
                };
            var monsterLibrary2 = new List<string>()
                {
                  "Rejeton de magie",
                   "Bête de mana",
                   "Sorcier fou",
                   "Mage noir",
                   "Mage des arcanes",
                   "Sorciére sadique",
                   "Playmobil vivant", //Glauque
                };
            var monsterLibrary3 = new List<string>()
                {
                   "Nécromancien",
                   "Cerbére",
                   "Essence de chaos",
                   "Satyre lubrique",
                   "Flamme hurlante",                   
                   "Caniche d'attaque", //Attention, il bave
                };
            var monsterLibrary4 = new List<string>()
                {
                   "Bandit de la ville basse",
                   "Marchand en colére",
                   "Paysan révolté",
                   "Pillard",
                   "Bête des égouts",
                   "Rick Astley", //NEVER GONNA GIVE YOU UP
                };
            var monsterLibrary5 = new List<string>()
                {
                   "Guerrier en décomposition",
                   "Squelette",
                   "Liche",
                   "Zombie purulent",
                   "Monstre de chair", 
                   "Ballmer Sauvage", //lol
                };

            var random = MainWindow.Random;
            string selectedMonster;
            switch (cell.MonsterGroup)
            {
                case 1:
                    selectedMonster = monsterLibrary1[random.Next(0, monsterLibrary1.Count)];
                    break;
                case 2:
                    selectedMonster = monsterLibrary2[random.Next(0, monsterLibrary2.Count)];
                    break;
                case 3:
                    selectedMonster = monsterLibrary3[random.Next(0, monsterLibrary3.Count)];
                    break;
                case 4:
                    selectedMonster = monsterLibrary4[random.Next(0, monsterLibrary4.Count)];
                    break;
                case 5:
                    selectedMonster = monsterLibrary5[random.Next(0, monsterLibrary5.Count)];
                    break;
                default:
                    selectedMonster = monsterLibrary1[random.Next(0, monsterLibrary1.Count)];
                    break;
            }

            var attackRate = 40;
            var missRate = 30;
            var health = 60;
            var damage = 15;
            var level = (int)Math.Floor((double)player.Xp / 100);
            var levelBlocked = level > 10 ? 10 : level;
            MonsterLevel = level;

            attackRate = random.Next((attackRate + (levelBlocked - 1) * 6), (attackRate + levelBlocked * 6));

            missRate = random.Next((missRate - levelBlocked * 3), (missRate - (levelBlocked - 1) * 3));

            health = random.Next((health + (level - 1) * 60), (health + level * 60));
            MonsterMaxHp = health;

            damage = damage + level * 15;

            Monster = new Monster { AttackRate = attackRate, MissRate = missRate, Group = cell.MonsterGroup, Hp = health, Name = selectedMonster, Damage = damage };
        }