public void HandleInput(ConsoleKey input)
        {
            buyPotion = arrowPos < 5;
            heal      = Enumerable.Range(5, 3).Contains(arrowPos);

            arrowPos = Program.ArrowGUI(arrowPos, input, 1, 8, null);

            nextState = new PotionStoreGameState(arrows, arrowPos);

            switch (input)
            {
            case ConsoleKey.Enter:

                if (buyPotion)
                {
                    int cap = Program.potions.Count + 1;

                    nextState = new PotionStoreGameState(arrows, arrowPos);

                    for (int potion = 0; potion < cap; potion++)
                    {
                        if (Program.potions.Count == potion)
                        {
                            cap = potion;

                            switch (arrowPos)
                            {
                            case 1: potionSold = strengthPotion; break;

                            case 2: potionSold = toughnessPotion; break;

                            case 3: potionSold = defencePotion; break;

                            case 4: potionSold = luckPotion; break;
                            }

                            if (potionSold != null)
                            {
                                Program.potions[potion] = potionSold;
                            }

                            if (Program.potions[potion].price <= Program.Gold)
                            {
                                nextState     = new ExplorationGameState();
                                Program.Gold -= Program.potions[potion].price;
                            }
                            else
                            {
                                Program.potions.Remove(potion);
                            }
                        }
                    }
                }
                else if (heal)
                {
                    if (Program.Gold >= healingPrice)
                    {
                        nextState = new ExplorationGameState();

                        switch (arrowPos)
                        {
                        case 5: character = Program.ben; break;

                        case 6: character = Program.tim; break;

                        case 7: character = Program.ty; break;
                        }

                        if (character.alive)
                        {
                            character.Health += healAmount;
                            Program.Gold     -= 100;
                        }
                    }
                    else
                    {
                        nextState = new PotionStoreGameState(arrows, arrowPos);
                    }
                }
                else
                {
                    nextState = new ExplorationGameState();
                }

                break;
            }

            for (int arrow = 0; arrow < 8; arrow++)
            {
                arrows[arrow] = arrowPos == (arrow + 1) ? ">" : " ";
            }
        }
Example #2
0
        public void HandleInput(ConsoleKey input)
        {
            bool inputTaken = false;

            if (potionAction && !inputTaken)
            {
                int    key  = 0;
                string stat = "";

                inputTaken = true;

                potionArrowPos = Program.ArrowGUI(potionArrowPos, input, 2, 2, null);

                switch (input)
                {
                case ConsoleKey.R:
                    for (int potionName = 0; potionName < potionNames.Length; potionName++)
                    {
                        potionNames[potionName] = " ";
                    }

                    for (int potionArrow = 0; potionArrow < potionArrows.Length; potionArrow++)
                    {
                        potionArrows[potionArrow] = " ";
                    }

                    potionAction = false;

                    error = true;

                    SetUpNextState();
                    break;

                case ConsoleKey.Enter:
                    switch (potionArrowPos)
                    {
                    case 1: stat = "Strength"; break;

                    case 2: stat = "Toughness"; break;

                    case 3: stat = "Defence"; break;

                    case 4: stat = "Luck"; break;
                    }

                    for (int potionCount = 0; potionCount < Program.potions.Count; potionCount++)
                    {
                        if (Program.potions[potionCount].stat == stat)
                        {
                            key    = potionCount;
                            potion = Program.potions[potionCount];
                        }
                    }

                    if (potion != null)
                    {
                        if (character.hasFought)
                        {
                            error         = true;
                            notifications = $"{character.nickname} has already fought!!";
                        }
                        else
                        {
                            character.hasFought = true;
                        }

                        if (!error)
                        {
                            bool miss = character.LuckRoll(15);

                            if (miss)
                            {
                                notifications = $"{enemy.creatureName} missed!";
                            }

                            enemy.Combat(character, round, miss);

                            character.PotionWearOff();

                            Program.potions.Remove(key);

                            character.ConsumePotion(potion);

                            notifications = $"{character.nickname} used a {potion.name}";

                            for (int potionName = 0; potionName < potionNames.Length; potionName++)
                            {
                                potionNames[potionName] = " ";
                            }

                            for (int potionArrow = 0; potionArrow < potionArrows.Length; potionArrow++)
                            {
                                potionArrows[potionArrow] = " ";
                            }

                            potionAction = false;
                        }
                    }
                    else
                    {
                        error         = true;
                        notifications = "You do not have that kind of potion!";
                    }

                    SetUpNextState();
                    break;
                }

                if (potionAction)
                {
                    for (int potionArrow = 0; potionArrow < potionArrows.Length; potionArrow++)
                    {
                        potionArrows[potionArrow] = potionArrowPos == potionArrow + 1 ? ">" : " ";
                    }
                }
            }

            if (!characterSelected && !inputTaken)
            {
                inputTaken = true;

                charArrowPos = Program.ArrowGUI(charArrowPos, input, 3, 1, null);

                switch (input)
                {
                case ConsoleKey.R:
                    error = true;

                    SetUpNextState();
                    break;

                case ConsoleKey.Enter:
                    if (charArrows[0] == ">")
                    {
                        character = ben;
                    }
                    else if (charArrows[1] == ">")
                    {
                        character = tim;
                    }
                    else if (charArrows[2] == ">")
                    {
                        character = ty;
                    }

                    if (character.alive)
                    {
                        characterSelected = true;
                    }
                    else
                    {
                        error         = true;
                        notifications = $"{character.nickname} is dead!";
                    }
                    break;
                }

                for (int charArrow = 0; charArrow < charArrows.Length; charArrow++)
                {
                    charArrows[charArrow] = charArrowPos == charArrow + 1 ? ">" : " ";
                }
            }

            if (characterSelected && !inputTaken)
            {
                actionArrowPos = Program.ArrowGUI(actionArrowPos, input, 2, 2, null);

                switch (input)
                {
                case ConsoleKey.R:
                    error = true;

                    SetUpNextState();
                    break;

                case ConsoleKey.Enter:
                    ActionExecution();
                    break;
                }

                for (int actionArrow = 0; actionArrow < actionArrows.Length; actionArrow++)
                {
                    actionArrows[actionArrow] = actionArrowPos == actionArrow + 1 ? ">" : " ";
                }
            }
        }