コード例 #1
0
ファイル: GameEngine.cs プロジェクト: Psykepro/Canrum-OOP
        private void EnterBattle(Npc enemy)
        {
            Renderer.WriteLine(string.Format("You encounter a {0}{1}!", enemy.Race, enemy.CharClass));
            Renderer.WriteLine(string.Format("I'm {0}! I will crush you!", enemy.Name));

            int round = 1;
            while (true)
            {
                Renderer.WriteLine(string.Format("Round {0}", round));
                Renderer.WriteLine("Attack or use skill!");
                string[] userInput = Regex.Split(Reader.ReadLine(), @"\s+");

                this.ExecuteBattleCommand(userInput, enemy);

                if (enemy.CurrentHealth <= 0)
                {
                    Renderer.WriteLine("Enemy killed!");
                    this.player.GetPlayerExperience(enemy.MaxHealth);
                    this.creepsList.Remove(enemy);
                    break;
                }

                enemy.Attack(this.player, Rand);

                if (this.player.CurrentHealth <= 0)
                {
                    this.IsRunning = false;
                    Renderer.WriteLine("You're dead!");
                    break;
                }

                round++;
            }
        }
コード例 #2
0
ファイル: GameEngine.cs プロジェクト: Psykepro/Canrum-OOP
        private Npc CreateEnemy()
        {
            int currentX = Rand.Next(1, MapWidth);
            int currentY = Rand.Next(1, MapHeight);

            bool containsEnemy = this.creepsList
                .Any(e => e.Position.X == currentX && e.Position.Y == currentY);

            while (containsEnemy)
            {
                currentX = Rand.Next(1, MapWidth);
                currentY = Rand.Next(1, MapHeight);

                containsEnemy = this.creepsList
                .Any(e => e.Position.X == currentX && e.Position.Y == currentY);
            }

            int nameIndex = Rand.Next(0, Resources.CharacterNames.Length);
            string name = Resources.CharacterNames[nameIndex];

            Npc creep = new Npc(new Position(currentX, currentY), name, (Race)Rand.Next(5), (CharClass)Rand.Next(4), Rand);

            return creep;
        }