//New Player public PlayerManager(string name) { if (name != "") { var db = new Project2NetContext(); var rand = Program.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; } }
//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; }