コード例 #1
0
        //attack on monsters
        public void Attack(WeakMonster monster)
        {
            int att = ThrowDice(this.damage);

            Console.WriteLine("Hitting monster with {0}", att);
            monster.GotHit(att);
            Console.WriteLine("Monster is left with {0}", monster.GetLifePoint());
        }
コード例 #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);
        }