Example #1
0
        static void ProcessInput(ConsoleKeyInfo pressedKey)
        {
            if (pressedKey.Key.Equals(ConsoleKey.UpArrow))
            {
                if (!matrix[hero.Position.row - 1, hero.Position.col].isSolid)
                {
                    draw.DrawInConsole(matrix[hero.Position.row, hero.Position.col], hero.Position.row, hero.Position.col);
                    hero.Move(Direction.up);
                    CheckHeroPosition();
                }
            }
            else if (pressedKey.Key.Equals(ConsoleKey.DownArrow))
            {
                if (!matrix[hero.Position.row + 1, hero.Position.col].isSolid)
                {
                    draw.DrawInConsole(matrix[hero.Position.row, hero.Position.col], hero.Position.row, hero.Position.col);
                    hero.Move(Direction.down);
                    CheckHeroPosition();
                }
            }
            else if (pressedKey.Key.Equals(ConsoleKey.LeftArrow))
            {
                if (!matrix[hero.Position.row, hero.Position.col - 1].isSolid)
                {
                    draw.DrawInConsole(matrix[hero.Position.row, hero.Position.col], hero.Position.row, hero.Position.col);
                    hero.Move(Direction.left);
                    CheckHeroPosition();
                }
            }
            else if (pressedKey.Key.Equals(ConsoleKey.RightArrow))
            {
                if (!matrix[hero.Position.row, hero.Position.col + 1].isSolid)
                {
                    draw.DrawInConsole(matrix[hero.Position.row, hero.Position.col], hero.Position.row, hero.Position.col);
                    hero.Move(Direction.right);
                    CheckHeroPosition();
                }
            }
            else if (pressedKey.Key.Equals(ConsoleKey.Enter))
            {
                if (nearbyNPC)
                {
                    foreach (NPC npc in NPCsOfCurrentLevel)
                    {
                        if (Math.Abs(npc.Position.row - hero.Position.row) <= 1 &&
                            Math.Abs(npc.Position.col - hero.Position.col) <= 1)
                        {
                            Conversation conversation = new Conversation();
                            conversation.DrawConversation(hero, npc);
                            draw.DrawMatrixInConsole(matrix);
                        }
                    }
                }
            }
            else if (pressedKey.Key.Equals(ConsoleKey.Escape))
            {
                MenuInGame menuInGame = new MenuInGame();
                menuInGame.Menu(hero);
                if (menuInGame.GetChoice == 3)
                {
                    LoadSaveGame.Save(hero);
                }
                else if (menuInGame.GetChoice == 4)
                {
                    hero = LoadSaveGame.Load();
                }

                Console.ResetColor();
                Console.Clear();
                draw.DrawMatrixInConsole(matrix);
            }
        }
Example #2
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());
        }