예제 #1
0
        static void CheckHeroPosition()
        {
            DiceRoller dice = new DiceRoller();
            int r = hero.Position.row;
            int c = hero.Position.col;
            nearbyNPC = false;

            foreach (NPC npc in NPCsOfCurrentLevel)
            {
                if (Math.Abs(npc.Position.row - hero.Position.row) <= 1 &&
                            Math.Abs(npc.Position.col - hero.Position.col) <= 1)
                {
                    nearbyNPC = true;
                    int top = height - 7;
                    int left = width / 2 - 20;
                    Console.SetCursorPosition(left, top);
                    Console.BackgroundColor = ConsoleColor.DarkGreen;
                    Console.Write("Press [Enter] to talk to " + npc.Name);
                }
            }
            if (!nearbyNPC)
            {
                int top = height - 7;
                int left = width / 2 - 20;
                Console.SetCursorPosition(left, top);
                Console.BackgroundColor = ConsoleColor.Black;
                Console.Write(new String(' ', 40));
            }

            if (matrix[r, c].content is DangerousTerritory)
            {
                if (dice.NewDice(matrix[r, c].content.Chance))
                {
                    Battle battle = new Battle();
                    battle.StartBattle
                        (
                        hero,
                        matrix[r, c].content.enemyToAppear,
                        matrix[r, c].content.Chance == 1,
                        matrix,
                        NPCsOfCurrentLevel
                        );
                    draw.DrawMatrixInConsole(matrix);
                }
            }
        }
예제 #2
0
        public void StartBattle(Hero TheHero,
                                Enemy TheEnemy, 
                                bool BossFight, 
                                VisualElement[,] matrix, 
                                List<NPC> NPCsOfCurrentLevel)
        {
            hero = TheHero;
            enemy = TheEnemy;

            totalHeroHP = hero.Statistics.HitPoints;
            currentHeroHP = totalHeroHP;
            totalEnemyHP = enemy.Statistics.HitPoints;
            currentEnemyHP = totalEnemyHP;
            DrawBattle(hero, enemy);

            while (currentHeroHP > 0 && currentEnemyHP > 0)
            {
                ProcessInput(Console.ReadKey());
                Thread.Sleep(1000);
                DrawBattle(hero, enemy);
                if (escapeSuccessful)
                {
                    break;
                }
                if (currentEnemyHP < 1)
                {
                    break;
                }
                EnemyAttack();
                Thread.Sleep(1000);
                DrawBattle(hero, enemy);

                enemyIsCrippled = false;
            }

            if (currentHeroHP < 1)
            {
                // game over
                TheHero.LevelUp();
                hero.Position = new Position(0, 0);
                Loader load = new Loader();
                NPCsOfCurrentLevel.Clear();
                matrix = load.LoadLevel(matrix, TheHero, NPCsOfCurrentLevel);
            }
            else
            {
                if (BossFight)
                {
                    TheHero.LevelUp();
                    hero.Position = new Position(0, 0);

                    if (TheHero.level > 3)
                    {
                        // Game compleated
                    }

                    MenuChangeWeapon newWeapon = new MenuChangeWeapon();
                    newWeapon.GetRandomWeapon(TheHero);

                    Loader load = new Loader();
                    NPCsOfCurrentLevel.Clear();

                    matrix = load.LoadLevel(matrix, TheHero, NPCsOfCurrentLevel);
                }
                else if (!escapeSuccessful)
                {
                    DiceRoller dice = new DiceRoller();
                    if (dice.NewDice(0.5))
                    {
                        MenuChangeWeapon newWeapon = new MenuChangeWeapon();
                        newWeapon.GetRandomWeapon(TheHero);
                    }
                }
            }
        }
예제 #3
0
        void ProcessInput(ConsoleKeyInfo pressedKey)
        {
            if (pressedKey.Key.Equals(ConsoleKey.Escape))
            {
                MenuInGame menuInGame = new MenuInGame();
                menuInGame.Menu(hero);
                Console.ResetColor();
                Console.Clear();
                DrawBattle(hero, enemy);
            }

            if (pressedKey.Key.Equals(ConsoleKey.A))
            {
                int damage = hero.Weapon.damage;
                damage = damage * hero.Statistics.Strength / 15;
                damage = (int)((double)damage / enemy.Statistics.Dexterity * 15);
                damage += damage * (hero.level - 1) / 3;

                currentEnemyHP -= damage;

                AddMessage(hero.Name + " used " + hero.Weapon.name + " (" + damage + ")");
                DrawBattle(hero, enemy);
                DrawDamage(true);
            }
            else if (pressedKey.Key.Equals(ConsoleKey.S))
            {
                DiceRoller dice = new DiceRoller();

                int damage = hero.Weapon.magic.damage;
                damage = damage * hero.Statistics.EillPower / 15;
                int damageOnSelf = hero.Weapon.magic.damageOnSelf;
                damageOnSelf = damageOnSelf * hero.Statistics.EillPower / 15;

                damage = (int)((double)damage / enemy.Statistics.Dexterity * 15);

                damage += damage * (hero.level - 1) / 3;
                damageOnSelf += damageOnSelf * (hero.level - 1) / 3;

                currentEnemyHP -= damage;
                currentHeroHP -= damageOnSelf;

                if (currentHeroHP > totalHeroHP)
                {
                    currentHeroHP = totalHeroHP;
                }
                enemyIsCrippled = dice.NewDice(hero.Weapon.magic.chanceToStun);

                AddMessage(hero.Name + " used " + hero.Weapon.magic.Name + " (" + damage + " / " + damageOnSelf + ")");
                DrawBattle(hero, enemy);
                DrawDamage(true);
            }
            else if (pressedKey.Key.Equals(ConsoleKey.E))
            {
                DiceRoller dice = new DiceRoller();
                if (dice.NewDice(enemy.ChanceToEscape))
                {
                    AddMessage(hero.Name + " has escaped");
                    DrawBattle(hero, enemy);
                    escapeSuccessful = true;
                }
                else
                {
                    AddMessage(hero.Name + " failed to escape");
                    DrawBattle(hero, enemy);
                }
            }
            else ProcessInput(Console.ReadKey());
        }