//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;
            }
        }
        //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);
                }
            }
        }
        //Add Weapon then save it

        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;
        }
        //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;
        }
Beispiel #5
0
        //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;
        }