public CombatViewModel()
 {
     MainGameViewModel.SelectedWeapon = null;
     MainGameViewModel.SelectedItem = null;
     using (var db = new Project2NetContext())
     {
         _activeMonsterManager = new MonsterManager(MainGameViewModel.ActivePlayerManager.Player, db.Cells.FirstOrDefault(c => c.Id == MainGameViewModel.ActivePlayerManager.Player.CurrentCellId));
     }
 }
 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;
            }
        }
 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);
 }
        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);
            }
        }
        //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();
            }
        }
 //Génére potion d'attaque en fnct du lvl
 public void GenerateAttackPotion(int level)
 {
     ItemType type;
     using (var db = new Project2NetContext())
     {
         if ((type = db.ItemsTypess.SingleOrDefault(t => t.Type == 1 && t.Level == level)) == null)
         {
             type = new ItemType
             {
                 AttackStrenghtBonus = 5 + 5*level,
                 DefenseBoost = 0,
                 HpRestoreValue = 0,
                 Level = level,
                 Name = "Potion de force",
                 Type = 1
             };
             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);
            }
        }
        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;
            }
        }
        //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;
        }
 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;
 }
        //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;
        }
        public void ExecRefreshGrid()
        {
            _grid.Clear();
            ObservableCollection<Cell> tempGrid;
            using (var db = new Project2NetContext())
            {
                _playerM.Player.CurrentCell = db.Cells.FirstOrDefault(cell => cell.Id == (int)_playerM.Player.CurrentCellId);
                tempGrid = (from cell in db.Cells
                            where (cell.PosX >= _playerM.Player.CurrentCell.PosX - 2 && cell.PosX <= _playerM.Player.CurrentCell.PosX + 2)
                             && (cell.PosY >= _playerM.Player.CurrentCell.PosY - 2 && cell.PosY <= _playerM.Player.CurrentCell.PosY + 2)
                            select cell).ToObservableCollection();
            }
            for (var a = -2; a <= 2; a++)
            {
                for (var b = -2; b <= 2; b++)
                {
                    var temp = tempGrid.SingleOrDefault(
                        cell => (cell.PosX == _playerM.Player.CurrentCell.PosX + a) && (cell.PosY == _playerM.Player.CurrentCell.PosY + b));

                    if (temp == null)
                    {
                        temp = new Cell
                        {
                            PosX = _playerM.Player.CurrentCell.PosX + a,
                            PosY = _playerM.Player.CurrentCell.PosX + b,
                            Description = "Case Inexplorée",
                            MonsterGroup = -1,
                            ImageSource = "../Ressources/Images/ground_empty_cell.png",
                            CanMoveTo = "0000",
                            Id = 0,
                            MonsterRate = 0,
                            Visited = false
                        };
                    }
                    _grid.Add(temp);
                }
            }
            NotifyPropertyChanged("Grid");
        }
        //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();
        }
 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;
     }
 }
        //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;
                }
            }

        }
        //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;
        }
 //Cellule existante
 public CellManager(int id)
 {
     using (var db = new Project2NetContext())
     {
         Cell = db.Cells.SingleOrDefault(cell => cell.Id == id);
     }
 }
示例#19
0
        //Procédure de nouveau player
        public PlayerManager NewGame()
        {
            using (var db = new Project2NetContext())
            {
                //Création du joueur
                PlayerManager selected;
                do
                {
                    String name = "";
                    do
                    {
                        Console.Clear();
                        Console.WriteLine("Choisissez un nom pour votre personnage (1-15 caractéres)");
                        name = Console.ReadLine();
                    } while (name.Length >= 15 || name.Length < 1);
                    selected = new PlayerManager(name);
                } while (selected.Player == null);
                ShowPlot();
                Console.Clear();
                selected.ShowPlayerInfos();
                Console.WriteLine("Aprés avoir marché pendant quelques heures,");

                Console.WriteLine();
                return selected;
            }
        }
示例#20
0
 //Procédure de chargement d'un player
 public PlayerManager LoadGame()
 {
     using (var db = new Project2NetContext())
     {
         var players = from player in db.Players select player;
         PlayerManager selected;
         do
         {
             int gameId;
             do
             {
                 Console.Clear();
                 Console.ForegroundColor = ConsoleColor.White;
                 Console.WriteLine("Selectionnez l'ID de la partie que vous voulez jouer :");
                 foreach (var player in players)
                 {
                     Console.WriteLine("ID {0} - Nom : {1} - HP : {2} - Level : {3}", player.Id,
                                                     player.Name, player.Hp, (int)Math.Floor((double) player.Xp/100));
                 }
                 Console.ResetColor();
             } while (!int.TryParse(Console.ReadLine(), out gameId));
             
             selected = new PlayerManager(gameId);
         } while (selected.Player == null);
         Console.Clear();
         selected.ShowPlayerInfos();
         return selected;
     }
 }
示例#21
0
        //Introduction (menu, toussa toussa)
        public PlayerManager Intro()
        {
            using (var db = new Project2NetContext())
            {
                PlayerManager selectedPlayer = null;

                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("███████████████████████████████████████████████████████████████████████████████");
                Console.WriteLine("███████████████████████████████████████████████████████████████████████████████");
                Console.BackgroundColor = ConsoleColor.DarkGreen;
                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("████                      © 2012 - HEAVENSTAR STUDIOS                      ████");
                Console.WriteLine("████                                                                       ████");
                Console.WriteLine("████                                                                       ████");
                Console.WriteLine("████                                                                       ████");
                Console.WriteLine("████                                                                       ████");
                Console.WriteLine("████                  Appuyez sur un bouton pour commencer.                ████");
                Console.WriteLine("████                  (Le chargement peut être un peu long)                ████");
                Console.WriteLine("████                                                                       ████");
                Console.WriteLine("███████████████████████████████████████████████████████████████████████████████");
                Console.WriteLine("███████████████████████████████████████████████████████████████████████████████");
                Console.ResetColor();

                Console.ReadKey();
                var atLeastOneGame = (from players in db.Players select players).Any();
                do
                {
                    Console.Clear();
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.WriteLine("███████████████████████████████████████████████████████████████████████████████");
                    Console.WriteLine("███████████████████████████████████████████████████████████████████████████████");
                    Console.BackgroundColor = ConsoleColor.DarkGreen;
                    Console.WriteLine("████                                                                       ████");
                    Console.WriteLine("████ ██████  ██████  █      █  ███████  ██████  ██      █  ███████  ██████ ████");
                    Console.WriteLine("████ █    █  █       █      █     █     █       █ █     █     █     █    █ ████");
                    Console.WriteLine("████ █    █  █       █      █     █     █       █  █    █     █     █    █ ████");
                    Console.WriteLine("████ ██████  ██████  ████████     █     ██████  █   █   █     █     ██████ ████");
                    Console.WriteLine("████ █    █       █  █      █     █     █       █    █  █     █     █    █ ████");
                    Console.WriteLine("████ █    █       █  █      █     █     █       █     █ █     █     █    █ ████");
                    Console.WriteLine("████ █    █  ██████  █      █     █     ██████  █      ██  ███████  █    █ ████");
                    Console.WriteLine("████_______________________________________________________________________████");
                    Console.WriteLine("████                                                                       ████");
                    Console.WriteLine("████ MAIN MENU                                                             ████");
                    Console.WriteLine("████                                                                       ████");
                    Console.WriteLine("████   1- Créer un nouveau personnage                                      ████");
                    if (atLeastOneGame)
                    {
                        Console.WriteLine(
                            "████   2- Charger un personnage                                            ████");
                        Console.WriteLine(
                            "████   3- A Propos                                                         ████");
                        Console.WriteLine(
                            "████   4- Quitter                                                          ████");
                    }
                    else
                    {

                        Console.WriteLine(
                            "████   2- A Propos                                                         ████");
                        Console.WriteLine(
                            "████   3- Quitter                                                          ████");
                        Console.WriteLine(
                            "████                                                                       ████");
                    }


                    Console.WriteLine("████                                                                       ████");
                    Console.WriteLine("████                         Choisissez une option                         ████");
                    Console.WriteLine("████                                                                       ████");
                    Console.WriteLine("████                                                                       ████");
                    Console.WriteLine("███████████████████████████████████████████████████████████████████████████████");
                    Console.WriteLine("███████████████████████████████████████████████████████████████████████████████");
                    Console.ResetColor();

                    var choice = Console.ReadLine();

                    switch (choice)
                    {
                        case "1":
                            selectedPlayer = NewGame();
                            break;
                        case "2":
                            if (atLeastOneGame)
                            {
                                selectedPlayer = LoadGame();
                            }
                            else
                            {
                                ShowAbout();
                            }
                            break;
                        case "3":
                            if (atLeastOneGame)
                            {
                                ShowAbout();
                            }
                            else
                            {
                                Environment.Exit(0);
                            }
                            break;
                        case "4":
                            if (atLeastOneGame)
                            {
                                Environment.Exit(0);
                            }
                            break;
                    }
                } while (selectedPlayer == null);

                return selectedPlayer;
            }
        }
 //Existing Player
 public PlayerManager(int id)
 {
     var db = new Project2NetContext();
     Player = db.Players.SingleOrDefault(player => player.Id == id);
 }
示例#23
0
        //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);
                }
            }
        }
 //Return CellManager
 public CellManager GetCellManager()
 {
     using (var db = new Project2NetContext())
     {
         return new CellManager(db.Cells.SingleOrDefault(cell => cell.Id == Player.CurrentCellId));
     }
 }
示例#25
0
        //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;
        }
        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 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;
 }
        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;
            }
        }
 //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();
         }
         Item.ObjectType = type;
     }
 }
        //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;
        }