Exemplo n.º 1
0
        public static bool UseItem(string itemName, Inventory inventory, Hero hero, Monster monster)
        {
            bool flag;

            switch (itemName.ToUpper())
            {
                case "POTION":
                    if (ItemExceptions(inventory, itemName.ToUpper()))
                    {
                        UsePotion(inventory.InventoryList, itemName.ToUpper(), hero);
                        flag = true;
                    }
                    else
                        flag = false;
                    break;
                case "GRENADE":
                    if (ItemExceptions(inventory, itemName.ToUpper()))
                    {
                        UseGrenade(inventory.InventoryList, itemName.ToUpper(), monster);
                        flag = true;
                    }
                    else
                        flag = false;
                    break;
                default:
                    WriteLine("That item is not present in your inventory.");
                    flag = false;
                    break;
            }
            return flag;
        }
Exemplo n.º 2
0
        /*public override Position Move()
        {
            return Pos;
        }*/

        // Faire en sorte qu'on remplisse un tableau ou une liste de monstres choisis aléatoirement (avec le nombre de 'y')
        private void GetMonstersTab()
        {
            var r = new Random();
            //var i = 0;

            //var rand = new Monster[NumberOfMonsters];

            MonsterRand = Monsters[r.Next(Monsters.Count)];

            /*while (i < NumberOfMonsters)
            {
                LstRand.Add(Monsters[r.Next(Monsters.Count)]);
                i++;
            }*/
        }
Exemplo n.º 3
0
 private static bool Turn(Hero hero, Monster monster, Inventory inventory)
 {
     var flag = 0;
     var usedItem = true;
     var fled = true;
     WriteLine("What do you want to do ?\nAttack\nUse Item\nFlee");
     var choice = ReadLine();
     if (choice == null) return true;
     switch (choice.ToUpper())
     {
         case "ATTACK":
             hero.Attack(monster);
             if (monster.HitPoints > 0)
                 WriteLine(monster.Name + " has " + monster.HitPoints + " HP left !");
             flag = 0;
             break;
         case "USE ITEM":
             WriteLine("Which item do you want to use ?");
             inventory.DisplayInventory();
             var item = ReadLine();
             flag = 0;
             if (item != null)
                 usedItem = Hero.UseItem(item, inventory, hero, monster);
             break;
         case "FLEE":
             Hero.Flee();
             fled = false;
             break;
         default:
             WriteLine("Action unavailable... Please type it again...");
             flag = 1;
             break;
     }
     if (flag == 1 || !usedItem) return true;
     if (!fled) return false;
     if (monster.HitPoints <= 0) return true;
     monster.Attack(hero);
     WriteLine(monster.Name + " hits you for " + monster.Weapon.Damage +
                       " points of damage.\nYou have " +
                       hero.HitPoints + "HP left.");
     return true;
 }
Exemplo n.º 4
0
        private static void Main()
        {
            var board = new Board();
            var heroInstance = new Hero("Arkhana", 100, new Position(board), new Weapon("Excalibur", 500));
            //var monstersPopulateInstance = new Monster(positions, board);
            //var randomMonster = Monster.GetMonstersTab();

            var continueToPlay = true;

            // Console.WriteLine(randomMonster.Name + " " + randomMonster.HitPoints + " " + randomMonster.Weapon.Name);
            // var monsterInstance = new Monster("Bahamut", 2000, new Position(board), new Weapon());
            // board.MoveOnBoard(heroInstance.Pos, monsterInstance.Pos);
            // board.MoveOnBoard(heroInstance.Pos, randomMonster.Pos);
            while (continueToPlay)
            {
                // ReSharper disable once ObjectCreationAsStatement
                //var monsterInstance = new Monster(/*new Position(board), board*/);
                MonsterInstance = new Monster();
                //var randomMonster = Monster.GetMonstersTab();
                
                //var randomMonster = Monster.GetMonstersTab();
                var flee = true;
                board.MoveOnBoard(heroInstance.Pos);
                //var monstersPos = Position.MonsterPosTab;

                var inventoryInstance = new Inventory();
                // Console.WriteLine("You have encountered " + monsterInstance.Name + " !");

                /*
                    Pour déterminer quel Monstre correspond à quel 'y', il suffit d'établir une relation entre les indexes du tableau rand et ceux du tableau MonsterPosTab.
                    Ainsi, lors de l'appel du combat, on obtient bien le bon monstre qui correspond au bon 'y'.
                */

                WriteLine("You have encountered " + MonsterInstance.MonsterRand.Name + " !");
                /*while ((heroInstance.HitPoints > 0) && (monsterInstance.HitPoints > 0))
                {
                    Turn(heroInstance, monsterInstance, inventoryInstance);
                }*/
                while ((heroInstance.HitPoints > 0) && (MonsterInstance.MonsterRand.HitPoints > 0) && flee)
                {
                    flee = Turn(heroInstance, MonsterInstance.MonsterRand, inventoryInstance);
                }

                if (heroInstance.HitPoints == 0)
                {
                    continueToPlay = false;
                    heroInstance.Defeated();
                    Clear();
                }
                else if (heroInstance.HitPoints != 0 && flee)
                {
                    MonsterInstance.MonsterRand.Defeated();
                    board.NumberOfSteps = 0;
                    //monsterInstance.LstRand.RemoveAt(0);
                    Clear();
                    board.DisplayBoard();
                }
                else
                {
                    board.NumberOfSteps = 0;
                    Clear();
                    board.DisplayBoard();
                }
            }
        }