Esempio n. 1
0
        public void Attack(BossMonster boss)
        {
            int att = ThrowDice(this.damage);

            Console.WriteLine("Hitting boss with {0}", att);
            boss.GotHit(att);
            Console.WriteLine("Boss is left with {0}", boss.GetLifePoint());
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            int    bossKilled          = 0;
            int    strongMonsterKilled = 0;
            int    weakMonsterKilled   = 0;
            int    i = 0;
            string name;

            //allow the user to create 4 warriors
            while (i < 4)
            {
                Console.WriteLine("Give the name of your Warrior {0} ", i);
                name = Console.ReadLine();
                Warrior war = new Warrior(name);
                warriorsAlive.Add(war);
                i++;
            }

            do //while the player has warriors alive
            {
                Warrior war = (Workshop.Warrior)warriorsAlive[0];
                while (war.IsAlive()) //as long as the current warrior is alive create monster to fight
                {
                    int number = Dice.ThrowDice(3);
                    switch (number)
                    {
                    case 1:      //create a weak monster
                        WeakMonster monsterW = new WeakMonster();
                        while (monsterW.IsAlive())
                        {
                            war.Attack(monsterW);
                            if (monsterW.IsAlive())
                            {
                                monsterW.Attack(war);
                                if (!war.IsAlive())
                                {
                                    break;
                                }
                            }
                        }
                        if (!monsterW.IsAlive())
                        {
                            score += monsterW.GetPoint();
                            weakMonsterKilled++;
                        }
                        break;

                    case 2:      //create a strong monster
                        StrongMonster monsterS = new StrongMonster();
                        while (monsterS.IsAlive())
                        {
                            war.Attack(monsterS);
                            if (monsterS.IsAlive())
                            {
                                monsterS.Attack(war);
                                if (!war.IsAlive())
                                {
                                    break;
                                }
                            }
                        }
                        if (!monsterS.IsAlive())
                        {
                            score += monsterS.GetPoint();
                            monsterS.DropItem(war);
                            strongMonsterKilled++;
                        }
                        break;

                    case 3:     //create a boss
                        BossMonster boss = new BossMonster();
                        while (boss.IsAlive())
                        {
                            war.Attack(boss);
                            if (boss.IsAlive())
                            {
                                boss.Attack(war);
                                if (!war.IsAlive())
                                {
                                    break;
                                }
                            }
                        }
                        if (!boss.IsAlive())
                        {
                            boss.DropItem(war);
                            score += boss.GetPoint();
                            bossKilled++;
                        }

                        break;
                    }
                }
                nbrOfDead++;
            } while (nbrOfDead != 4); //end of game

            Console.WriteLine("All your warriors are dead...");
            Console.WriteLine("You still manage to get a score of {0}", score);
            Console.WriteLine("You killed {0} weak monsters, \n{1} strong monsters, \n{2} boss.", weakMonsterKilled, strongMonsterKilled, bossKilled);
        }