//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; } }
private void StayAlive_Click(object sender, RoutedEventArgs e) { var db = new Project2NetContext(); var playerM = MainWindow.SelectedPlayerViewModel.ActivePlayerManager; if (playerM.Player != null) { playerM.Player.Xp = playerM.Player.Xp - 300; if (playerM.Player.Xp <= 0) playerM.Player.Xp = 0; playerM.Player.MaxHp = 500 + ((int)Math.Floor((double)playerM.Player.Xp / 100)) * 150; playerM.Player.Hp = playerM.Player.MaxHp; var itemList = playerM.Player.ObjectInventory.ToList(); foreach (var item in itemList) { playerM.Player.ObjectInventory.Remove(item); var itemD = (from i in db.Items where i.Id == item.Id select i).FirstOrDefault(); db.Items.Remove(itemD); } var weaponList = playerM.Player.WeaponInventory.ToList(); foreach (var weapon in weaponList) { playerM.Player.WeaponInventory.Remove(weapon); var weaponD = (from i in db.Weapons where i.Id == weapon.Id select i).FirstOrDefault(); db.Weapons.Remove(weaponD); } db.SaveChanges(); var weaponM = new WeaponManager(playerM.Player.Xp, true); playerM.Player.WeaponInventory.Add(weaponM.Weapon); MainWindow.SelectedPlayerViewModel.ActivePlayerManager.Player = playerM.Player; MainWindow.SelectedPlayerViewModel.ActivePlayerManager.Save(); MainWindow.SelectedPlayerViewModel.Weapons.Clear(); MainWindow.SelectedPlayerViewModel.Items.Clear(); var weaponAdded = MainWindow.SelectedPlayerViewModel.ActivePlayerManager.AddWeapon(); MainWindow.SelectedPlayerViewModel.Weapons.Add(weaponAdded); MessageBox.Show("Vous vous sentez Renaitre !"); MainWindow.SelectedPlayerViewModel.RefreshMainUi(); SoundHelper.PlayFromCategory(SoundHelper.Categories.Normal); NavigationHelper.MoveToPage(MainWindow.SelectedPlayerView); } }
//génére potion de soin en fonction du lvl public void GenerateHealthPotion(int level) { ItemType type; using (var db = new Project2NetContext()) { if ((type = db.ItemsTypess.SingleOrDefault(t => t.Type == 0 && t.Level == level)) == null) { type = new ItemType { AttackStrenghtBonus = 0, DefenseBoost = 0, HpRestoreValue = 80 + level * 80, Level = level, Name = "Potion de soins", Type = 0 }; db.ItemsTypess.Add(type); db.SaveChanges(); } } Name = type.Name; PlayerM.AddItem(type.Id); }
public String UseItem(Item item) { if (item.ObjectType.Type != 0) return "Vous ne pouvez utiliser que des potions de soins hors combat !"; //Soin var hp = Player.Hp; Player.Hp += item.ObjectType.HpRestoreValue; if (Player.Hp > Player.MaxHp) Player.Hp = Player.MaxHp; hp = Player.Hp - hp; //Suppression using (var db = new Project2NetContext()) { var player = (from p in db.Players where p.Id == Player.Id select p).FirstOrDefault(); string itemName = ""; if (player != null) { player.Hp = Player.Hp; player.MaxHp = Player.MaxHp; player.Xp = Player.Xp; player.CurrentCellId = Player.CurrentCellId; player.ObjectInventory.Remove(item); //Copie en local Player.ObjectInventory = player.ObjectInventory; itemName = item.ObjectType.Name; item = (from i in db.Items where i.Id == item.Id select i).FirstOrDefault(); db.Items.Remove(item); } db.SaveChanges(); return string.Format("L'item {0} vous à soigné pour {1} Hp !", itemName, hp); } }
//Save player to db public void Save() { using (var db = new Project2NetContext()) { var player = (from p in db.Players where p.Id == Player.Id select p).FirstOrDefault(); if (player != null) { player.Hp = Player.Hp; player.MaxHp = Player.MaxHp; player.Xp = Player.Xp; player.CurrentCellId = Player.CurrentCellId; } db.SaveChanges(); } }
public void ExecUseItem() { var rand = MainWindow.Random; if (MainGameViewModel.SelectedItem.ObjectType.Type == 0) //Health Potion { //Soin var hp = MainGameViewModel.ActivePlayerManager.Player.Hp; MainGameViewModel.ActivePlayerManager.Player.Hp += MainGameViewModel.SelectedItem.ObjectType.HpRestoreValue; if (MainGameViewModel.ActivePlayerManager.Player.Hp > MainGameViewModel.ActivePlayerManager.Player.MaxHp) MainGameViewModel.ActivePlayerManager.Player.Hp = MainGameViewModel.ActivePlayerManager.Player.MaxHp; hp = MainGameViewModel.ActivePlayerManager.Player.Hp - hp; MessageList.Insert(0,String.Format("L'item {0} vous à soigné pour {1} Hp !", MainGameViewModel.SelectedItem.ObjectType.Name, hp)); } else { if (MainGameViewModel.SelectedItem.ObjectType.AttackStrenghtBonus != 0) { MessageList.Insert(0,String.Format("L'item {0} vous à rendu plus fort de {1} Points !", MainGameViewModel.SelectedItem.ObjectType.Name, MainGameViewModel.SelectedItem.ObjectType.AttackStrenghtBonus)); _playerAttackBonus += MainGameViewModel.SelectedItem.ObjectType.AttackStrenghtBonus; } if (MainGameViewModel.SelectedItem.ObjectType.DefenseBoost != 0) { MessageList.Insert(0,String.Format("L'item {0} vous à rendu plus résistant de {1} Points !", MainGameViewModel.SelectedItem.ObjectType.Name, MainGameViewModel.SelectedItem.ObjectType.DefenseBoost)); _playerDefenseBonus += MainGameViewModel.SelectedItem.ObjectType.DefenseBoost; } } //Suppression using (var db = new Project2NetContext()) { var player = (from p in db.Players where p.Id == MainGameViewModel.ActivePlayerManager.Player.Id select p).FirstOrDefault(); if (player != null) { player.Hp = MainGameViewModel.ActivePlayerManager.Player.Hp; player.MaxHp = MainGameViewModel.ActivePlayerManager.Player.MaxHp; player.Xp = MainGameViewModel.ActivePlayerManager.Player.Xp; player.CurrentCellId = MainGameViewModel.ActivePlayerManager.Player.CurrentCellId; player.ObjectInventory.Remove(MainGameViewModel.SelectedItem); //Copie en local MainGameViewModel.ActivePlayerManager.Player.ObjectInventory = player.ObjectInventory; var item = (from i in db.Items where i.Id == MainGameViewModel.SelectedItem.Id select i).FirstOrDefault(); if (item != null) db.Items.Remove(item); } db.SaveChanges(); MainGameViewModel.Items.Remove(MainGameViewModel.SelectedItem); PerformAttackPlayer(); NotifyPropertyChanged("Items"); NotifyPropertyChanged("ActivePlayerManager"); NotifyPropertyChanged("MainGameViewModel"); if (CheckCombatEnd()) return; //Le monstre est-il assez rapide ? if (!_playerWon && !_playerLoose) { if (rand.Next(100) > 80) //On est sympa on diminue la chance de frappe x) {//Oui, le monstre peut frapper une deuxiéme fois MessageList.Insert(0, "Le monstre à été suffisement rapide pour donner un second coup !"); PerformAttackPlayer(); if (CheckCombatEnd()) return; } } } }
public Item DropItem(int id) { using (var db = new Project2NetContext()) { var player = (from p in db.Players where p.Id == Player.Id select p).FirstOrDefault(); if (player == null) return null; var itemM = new ItemManager((from i in player.ObjectInventory where i.Id == id select i).FirstOrDefault()); player.Hp = Player.Hp; player.MaxHp = Player.MaxHp; player.Xp = Player.Xp; player.CurrentCellId = Player.CurrentCellId; player.ObjectInventory.Remove(itemM.Item); var item = (from w in db.Items where w.Id == itemM.Item.Id select w).FirstOrDefault(); db.Items.Remove(item); db.SaveChanges(); return item; } }
public Weapon DropWeapon(int id) { using (var db = new Project2NetContext()) { var player = (from p in db.Players where p.Id == Player.Id select p).FirstOrDefault(); if (player == null) return null; var weaponM = new WeaponManager((from w in player.WeaponInventory where w.Id == id select w).FirstOrDefault()); player.Hp = Player.Hp; player.MaxHp = Player.MaxHp; player.Xp = Player.Xp; player.CurrentCellId = Player.CurrentCellId; player.WeaponInventory.Remove(weaponM.Weapon); var weapon = (from w in db.Weapons where w.Id == weaponM.Weapon.Id select w).FirstOrDefault(); db.Weapons.Remove(weapon); db.SaveChanges(); return weapon; } }
public Item AddItem(int type = -1) { var db = new Project2NetContext(); var player = (from p in db.Players where p.Id == Player.Id select p).FirstOrDefault(); var itemM = new ItemManager((int)Math.Floor((double)Player.Xp / 100), type); itemM.Item = new Item { ObjectType = db.ItemsTypess.Find(itemM.Item.ObjectType.Id) }; if (player != null) { player.Hp = Player.Hp; player.MaxHp = Player.MaxHp; player.Xp = Player.Xp; player.CurrentCellId = Player.CurrentCellId; player.ObjectInventory.Add(itemM.Item); Player.ObjectInventory = player.ObjectInventory; } db.SaveChanges(); return itemM.Item; }
//Effectué si perdu public void PlayerLost() { Console.Clear(); Console.WriteLine(" "); Console.WriteLine(" IT'S NOT A LIE "); Console.WriteLine(" "); Console.WriteLine(" █ YOU LOOSE (noob) ! "); Console.WriteLine(" █ "); Console.WriteLine(" █ "); Console.WriteLine(" █ "); Console.WriteLine(" █ ████ ██ █████████ "); Console.WriteLine(" █ █████ ███ ██████ ██ "); Console.WriteLine(" █████ █ ███████ █ ██ ██ "); Console.WriteLine(" ██ █ █████ █ ██ ██████ "); Console.WriteLine(" █ ██ █ █ ██ ██████████ "); Console.WriteLine(" █ ██ █ ██ ██████████ ██ "); Console.WriteLine(" █ ████ ██████████ ██████ "); Console.WriteLine(" █ █████████ ██████ ██ "); Console.WriteLine(" █ █████ ██████ ██████ "); Console.WriteLine(" █ █ ██████ ██████████ "); Console.WriteLine(" █ █████ ██████████ "); Console.WriteLine(" ██ █ ██████████ "); Console.WriteLine(" ██ █████████ "); Console.WriteLine(" ███ █████ "); Console.WriteLine(" ██ "); Console.WriteLine(" "); Console.WriteLine(" APPUYEZ SUR ENTREE POUR CONTINUER "); Console.ReadLine(); Console.Clear(); string response; while (true) { Console.WriteLine("Vous avez décédé."); Console.WriteLine("Dans un extrême élan de bonté, le gardien des tombeaux vous propose de repartir "); Console.WriteLine("vers le monde afin de poursuivre votre glorieuse quête."); Console.WriteLine(); Console.WriteLine("Mais ceci a un prix, il vous propose donc deux choix :"); Console.WriteLine("1 - Vous gardez votre personnage, mais perdez 3 niveaux et tous ses objets/armes"); Console.WriteLine("2 - Vous supprimez ce personnage"); response = Console.ReadLine(); var db = new Project2NetContext(); var player = (from p in db.Players where p.Id == PlayerM.Player.Id select p).FirstOrDefault(); if (response == "1") { if (player != null) { player.Xp = player.Xp - 300; if (player.Xp <= 0) player.Xp = 0; player.MaxHp = 500 + ((int) Math.Floor((double) player.Xp/100))*150; player.Hp = player.MaxHp; var itemList = player.ObjectInventory.ToList(); foreach (var item in itemList) { player.ObjectInventory.Remove(item); var itemD = (from i in db.Items where i.Id == item.Id select i).FirstOrDefault(); db.Items.Remove(itemD); } var weaponList = player.WeaponInventory.ToList(); foreach (var weapon in weaponList) { player.WeaponInventory.Remove(weapon); var weaponD = (from i in db.Weapons where i.Id == weapon.Id select i).FirstOrDefault(); db.Weapons.Remove(weaponD); } var weaponM = new WeaponManager(player.Xp, true); player.WeaponInventory.Add(weaponM.Weapon); db.SaveChanges(); PlayerM.Player = player; Console.Clear(); Console.WriteLine("Vous vous sentez renaître !"); Console.WriteLine(); Console.WriteLine("Appuyez sur une touche pour continuer."); Console.ReadKey(); Console.Clear(); } break; } else if (response == "2") { db.Players.Remove(player); db.SaveChanges(); Console.WriteLine("*Pouf*, Le personnage à été détruit ! Appuyez sur une touche pour quitter."); Console.ReadKey(); Environment.Exit(0); } } }
//Génére potion de defense en fnct du lvl public void GenerateDefensePotion(int level) { ItemType type; using (var db = new Project2NetContext()) { if ((type = db.ItemsTypess.SingleOrDefault(t => t.Type == 2 && t.Level == level)) == null) { type = new ItemType { AttackStrenghtBonus = 0, DefenseBoost = 5 + 5 * level, HpRestoreValue = 0, Level = level, Name = "Potion de protection", Type = 2 }; db.ItemsTypess.Add(type); db.SaveChanges(); } Item.ObjectType = type; } }
//Nouvelle Cellule public CellManager(int x, int y, int direction = -1) { using (var db = new Project2NetContext()) { //Random Generator var random = MainWindow.Random; //Nouvelles positions var newX = new int(); var newY = new int(); //Initialisation d'une chaine de chars var canMoveTo = new char[4]; //nord;est;sud;ouest //Index du tableau qui sera fixé var index = new int(); //Case possiblement bloquée var randomCell = new int(); switch (direction) { case -1: //Départ newX = x; newY = y; index = random.Next(0, 4); canMoveTo[index] = '1'; //Case forcément ouverte break; case 0: //nord newX = x; newY = y + 1; index = 2; canMoveTo[index] = '1'; //Case forcément ouverte break; case 1: //est newX = x + 1; newY = y; index = 3; canMoveTo[index] = '1'; //Case forcément ouverte break; case 2: //sud newX = x; newY = y - 1; index = 0; canMoveTo[index] = '1'; //Case forcément ouverte break; case 3: //ouest newX = x - 1; newY = y; index = 1; canMoveTo[index] = '1'; //Case forcément ouverte break; } var existingCell = db.Cells.SingleOrDefault(cell => cell.PosX == newX && cell.PosY == newY); if (existingCell == null) { //Choix d'une case possiblement bloquée do { randomCell = random.Next(0, 4); } while (randomCell == index); //remplissage de l'array de possibilités for (var a = 0; a < 4; a++) { if (a == randomCell) //Si c'est la case possiblement bloquée { if (random.Next(0, 2) == 1) { canMoveTo[a] = '1'; } else { canMoveTo[a] = '0'; } } else if (a != index) //Si c'est pas la case forcément ouverte { canMoveTo[a] = '1'; } } //Min 30 Max 50% de mob rate var monsterRate = random.Next(0, 51); Biome biome = null; biome = GetRandomBiome(); Cell = new Cell { Description = biome.Description, ImageSource = biome.ImageSource, CanMoveTo = ToStringCanMoveTo(canMoveTo), MonsterGroup = biome.MonsterGroup, MonsterRate = monsterRate, PosX = newX, PosY = newY }; db.Cells.Add(Cell); db.SaveChanges(); } else { Cell = existingCell; } } }
public bool Delete() { using (var db = new Project2NetContext()) { var player = (from p in db.Players where p.Id == Player.Id select p).FirstOrDefault(); if (player != null) { db.Players.Remove(player); db.SaveChanges(); return true; } return false; } }
//Marque la cellule comme fouillée public void IsVisited() { using (var db = new Project2NetContext()) { var cell = (from c in db.Cells where c.Id == Cell.Id select c).FirstOrDefault(); if (cell != null) { cell.Visited = true; } db.SaveChanges(); } Cell.Visited = true; }
//Add item then save it public void AddItem(int item) { var db = new Project2NetContext(); var player = (from p in db.Players where p.Id == Player.Id select p).FirstOrDefault(); if (player != null) { player.Hp = Player.Hp; player.MaxHp = Player.MaxHp; player.Xp = Player.Xp; player.CurrentCellId = Player.CurrentCellId; player.ObjectInventory.Add(new Item {ObjectType = db.ItemsTypess.Find(item)}); //Copie en local Player.ObjectInventory = player.ObjectInventory; } db.SaveChanges(); }
//Use item out of fight public bool UseItem() { Item item; do { string stringId; int id; do { Console.Clear(); Console.WriteLine("Saisissez l'ID de l'item que vous voulez utiliser (esc pour quitter)"); var usableItems = from p in Player.ObjectInventory where p.ObjectType.Type == 0 select p; if (!usableItems.Any()) { Console.WriteLine("Vous n'avez aucun objet utilisable hors combat."); return false; } else { foreach (var usableItem in usableItems) { Console.ForegroundColor = ConsoleColor.White; Console.BackgroundColor = ConsoleColor.DarkCyan; Console.WriteLine("ID : {0} NOM : {1} | NIVEAU {2}", usableItem.Id, usableItem.ObjectType.Name, usableItem.ObjectType.Level); Console.BackgroundColor = ConsoleColor.DarkBlue; Console.WriteLine(" -> [+HP : {0}]", usableItem.ObjectType.HpRestoreValue); Console.WriteLine(); Console.ResetColor(); } } stringId = Console.ReadLine(); if (stringId == "esc") { Console.Clear(); ShowPlayerInfos(); return false; } } while (!int.TryParse(stringId, out id)); item = Player.ObjectInventory.SingleOrDefault(i => i.Id == id); } while (item == null); //Soin var hp = Player.Hp; Player.Hp += item.ObjectType.HpRestoreValue; if (Player.Hp > Player.MaxHp) Player.Hp = Player.MaxHp; hp = Player.Hp - hp; //Suppression using (var db = new Project2NetContext()) { var player = (from p in db.Players where p.Id == Player.Id select p).FirstOrDefault(); string itemName = ""; if (player != null) { player.Hp = Player.Hp; player.MaxHp = Player.MaxHp; player.Xp = Player.Xp; player.CurrentCellId = Player.CurrentCellId; player.ObjectInventory.Remove(item); //Copie en local Player.ObjectInventory = player.ObjectInventory; itemName = item.ObjectType.Name; item = (from i in db.Items where i.Id == item.Id select i).FirstOrDefault(); db.Items.Remove(item); } db.SaveChanges(); Console.WriteLine("L'item {0} vous à soigné pour {1} Hp !", itemName,hp ); Console.WriteLine(); Console.WriteLine("Appuyez sur entrée pour continuer"); Console.ReadLine(); Console.Clear(); ShowPlayerInfos(); } return true; }
//Drop Item public bool DropItem() { Item item; do { string stringId; int id; do { Console.Clear(); Console.WriteLine("Saisissez l'ID de l'item que vous voulez jeter (esc pour quitter)"); ShowInventory(); stringId = Console.ReadLine(); if (stringId == "esc") { Console.Clear(); ShowPlayerInfos(); return false; } } while (!int.TryParse(stringId, out id)); item = Player.ObjectInventory.SingleOrDefault(i => i.Id == id); } while (item == null); using (var db = new Project2NetContext()) { var player = (from p in db.Players where p.Id == Player.Id select p).FirstOrDefault(); string itemName = ""; if (player != null) { player.Hp = Player.Hp; player.MaxHp = Player.MaxHp; player.Xp = Player.Xp; player.CurrentCellId = Player.CurrentCellId; player.ObjectInventory.Remove(item); //Copie en local Player.ObjectInventory = player.ObjectInventory; itemName = item.ObjectType.Name; item = (from i in db.Items where i.Id == item.Id select i).FirstOrDefault(); db.Items.Remove(item); } db.SaveChanges(); Console.WriteLine("L'item {0} à été supprimé", itemName); Console.WriteLine(); Console.WriteLine("Appuyez sur entrée pour continuer"); Console.ReadLine(); Console.Clear(); ShowPlayerInfos(); } return true; }
//Drop Weapon public bool DropWeapon() { if (Player.WeaponInventory.Count <= 1) { Console.WriteLine("Vous devez garder au moins une arme !"); return false; } Weapon weapon; do { string stringId; int id; do { Console.Clear(); Console.WriteLine("Saisissez l'ID de l'arme que vous voulez jeter (esc pour quitter)"); ShowWeapons(); stringId = Console.ReadLine(); if (stringId == "esc") { Console.Clear(); ShowPlayerInfos(); return false; } } while (!int.TryParse(stringId, out id)); weapon = Player.WeaponInventory.SingleOrDefault(w => w.Id == id); } while (weapon == null); using (var db = new Project2NetContext()) { var player = (from p in db.Players where p.Id == Player.Id select p).FirstOrDefault(); var weaponM = new WeaponManager(weapon); if (player != null) { player.Hp = Player.Hp; player.MaxHp = Player.MaxHp; player.Xp = Player.Xp; player.CurrentCellId = Player.CurrentCellId; player.WeaponInventory.Remove(weaponM.Weapon); //Copie en local Player.WeaponInventory = player.WeaponInventory; weapon = (from w in db.Weapons where w.Id == weaponM.Weapon.Id select w).FirstOrDefault(); db.Weapons.Remove(weapon); } db.SaveChanges(); Console.WriteLine("L'arme {0} à été supprimée", weapon.Name); Console.WriteLine(); Console.WriteLine("Appuyez sur entrée pour continuer"); Console.ReadLine(); Console.Clear(); ShowPlayerInfos(); } return true; }
//Affiche les actions liées aux objets public bool ObjectAction() { Item selectedItem; do { string objetId; int id; do { Console.Clear(); ShowCombatInfoLine(0); Console.WriteLine("Saisissez l'ID de l'objet que vous voulez utiliser (esc pour annuler) : "); Console.WriteLine(); PlayerM.ShowInventory(); Console.WriteLine(); objetId = Console.ReadLine(); if (objetId == "esc") return false; } while (!int.TryParse(objetId, out id)); selectedItem = PlayerM.Player.ObjectInventory.SingleOrDefault(objet => objet.Id == id); } while (selectedItem == null); if (selectedItem.ObjectType.Type == 0) //Health Potion { //Soin var hp = PlayerM.Player.Hp; PlayerM.Player.Hp += selectedItem.ObjectType.HpRestoreValue; if (PlayerM.Player.Hp > PlayerM.Player.MaxHp) PlayerM.Player.Hp = PlayerM.Player.MaxHp; hp = PlayerM.Player.Hp - hp; Console.WriteLine("L'item {0} vous à soigné pour {1} Hp !", selectedItem.ObjectType.Name, hp ); } else { if (selectedItem.ObjectType.AttackStrenghtBonus != 0) { Console.WriteLine("L'item {0} vous à rendu plus fort de {1} Points !", selectedItem.ObjectType.Name, selectedItem.ObjectType.AttackStrenghtBonus); PlayerBonusAttaque += selectedItem.ObjectType.AttackStrenghtBonus; } if (selectedItem.ObjectType.DefenseBoost != 0) { Console.WriteLine("L'item {0} vous à rendu plus résistant de {1} Points !", selectedItem.ObjectType.Name, selectedItem.ObjectType.DefenseBoost); PlayerBonusDefense += selectedItem.ObjectType.DefenseBoost; } } //Suppression var db = new Project2NetContext(); var player = (from p in db.Players where p.Id == PlayerM.Player.Id select p).FirstOrDefault(); if (player != null) { player.Hp = PlayerM.Player.Hp; player.ObjectInventory.Remove(selectedItem); //Copie en local PlayerM.Player.ObjectInventory = player.ObjectInventory; var item = (from i in db.Items where i.Id == selectedItem.Id select i).FirstOrDefault(); db.Items.Remove(item); } Console.WriteLine(); Console.WriteLine("Appuyez sur entrée pour continuer"); Console.ReadLine(); Console.Clear(); db.SaveChanges(); return true; }
private void Die_Click(object sender, RoutedEventArgs e) { using (var db = new Project2NetContext()) { var player = (from p in db.Players where p.Id == MainWindow.SelectedPlayerViewModel.ActivePlayerManager.Player.Id select p).FirstOrDefault(); if (player != null) { db.Players.Remove(player); db.SaveChanges(); } } MessageBox.Show("Vous sentez votre force vous abandonner..."); Environment.Exit(0); }
public Weapon AddWeapon() { var db = new Project2NetContext(); var player = (from p in db.Players where p.Id == Player.Id select p).FirstOrDefault(); var weaponM = new WeaponManager(Player.Xp); if (player != null) { player.Hp = Player.Hp; player.MaxHp = Player.MaxHp; player.Xp = Player.Xp; player.CurrentCellId = Player.CurrentCellId; player.WeaponInventory.Add(weaponM.Weapon); //Copie en local Player.WeaponInventory = player.WeaponInventory; } db.SaveChanges(); return weaponM.Weapon; }
//Interpreteur de commandes //Permet d'effectuer les actions en fonction de la commande utilisée public bool CheckCommand(string command, PlayerManager activePlayerM) { Console.Clear(); activePlayerM.ShowPlayerInfos(); command = command.ToLower(); var returnVal = true; switch (command) { //Inventaire case "afficher l'inventaire": activePlayerM.ShowInventory(); break; case "jeter un objet": activePlayerM.DropItem(); break; case "utiliser un objet": activePlayerM.UseItem(); break; case "afficher les armes": activePlayerM.ShowWeapons(); break; case "jeter une arme": activePlayerM.DropWeapon(); break; case "fouiller la zone": activePlayerM.SearchCellForItems(); break; //Déplacements case "aller au nord": Console.WriteLine("Vous vous déplacez vers le nord"); Console.WriteLine(); activePlayerM.Move("nord"); break; case "aller au sud": Console.WriteLine("Vous vous déplacez vers le sud"); Console.WriteLine(); activePlayerM.Move("sud"); break; case "aller a l'ouest": Console.WriteLine("Vous vous déplacez vers l'ouest"); Console.WriteLine(); activePlayerM.Move("ouest"); break; case "aller a l'est": Console.WriteLine("Vous vous déplacez vers l'est"); Console.WriteLine(); activePlayerM.Move("nord"); break; case "ou suis-je": Console.WriteLine(activePlayerM.GetCellManager().Cell.Description); break; //Options systéme case "quitter": returnVal = false; Console.ForegroundColor = ConsoleColor.Black; Console.BackgroundColor = ConsoleColor.Red; Console.WriteLine("Arrêt du programme !"); break; case "aide": GetAvailableCommands(); break; /* * Les easter eggs sont cachés un peu de partout, ainsi que les fonctionnalités ajoutées, ici se trouvent * deux petits cheats amusants */ //CHEATS case "all your base are belong to us": using (var db = new Project2NetContext()) { var player = (from p in db.Players where p.Id == activePlayerM.Player.Id select p).FirstOrDefault(); if (player != null) { player.MaxHp = 150 + 150*1000000; player.Hp = player.MaxHp; player.Xp = 100000000; var weaponM = new WeaponManager("2"); player.WeaponInventory.Add(weaponM.Weapon); } activePlayerM.Player = player; db.SaveChanges(); Console.WriteLine("Tel l'alpha et l'omega, vous devenez grand et puissant."); } break; case "mac rules the world": using (var db = new Project2NetContext()) { var player = (from p in db.Players where p.Id == activePlayerM.Player.Id select p).FirstOrDefault(); if (player != null) { var weaponM = new WeaponManager("1"); player.WeaponInventory.Add(weaponM.Weapon); } activePlayerM.Player = player; db.SaveChanges(); Console.WriteLine("Mais, qu'est ce que c'est que cette grosse chose dans votre fourreau ?"); } break; default: Console.ForegroundColor = ConsoleColor.Black; Console.BackgroundColor = ConsoleColor.Red; Console.WriteLine("Vous ne pouvez pas faire ceci !"); break; } Console.ResetColor(); return returnVal; }