public static void EnemyAction(Random random, Enemy enemy, Player player)
        {
            try
            {
                if (!enemy.IsDead && !player.IsDead)
                {
                    int enemyAction = random.Next(1, 5);

                    ConsoleMessageColor.SetMessageColorEnemy();
                    switch (enemyAction)
                    {
                    //Defend
                    case 1:
                        enemy.IsDefending = true;
                        Print.PrintMessage(Messages.IsDefending, enemy.Name);

                        break;

                    //Heal
                    case 2:
                        enemy.Heal(random.Next(enemy.MinHealAmount, enemy.MaxHealAmount));
                        break;

                    default:
                        player.GetHit(random.Next(enemy.MinAttackPower, enemy.MaxAttackPower));
                        break;
                    }
                }
            }
            catch (Exception e)
            {
                Print.PrintMessage(Messages.EnemyMovesError, e);
            }
        }
Beispiel #2
0
        /// <summary>
        /// The main game loop thats allow the player to attack the enemy.
        /// </summary>
        /// <param name="random">Random number value that we are using for the player and enemy actions.</param>
        /// <param name="enemy">The current enemy.</param>
        /// <param name="player">The player that we are playing as.</param>
        /// <param name="tools">Player restriction area - counters for the hheal and three strike attack usages.</param>
        private static void GameLoop(Random random, Enemy enemy, Player player, Tools tools)
        {
            Print.PrintMessage(Messages.EnemyEncounter, player.Name, enemy.Name);

            try
            {
                while (!enemy.IsDead && !player.IsDead)
                {
                    PlayerMoves.PlayerAction(random, enemy, player, tools);
                    EnemyMoves.EnemyAction(random, enemy, player);

                    ConsoleMessageColor.ResetMessageColor();
                }
            }
            catch (Exception e)
            {
                Print.PrintMessage(Messages.GameLoopError, e);
            }
        }
Beispiel #3
0
        public static void PlayerAction(Random random, Enemy enemy, Player player, Tools tools)
        {
            try
            {
                //Set here so the "Cannot Use Now Message to be actual - if set down the message has 1 point difference
                DecreaseTheCounters(tools);

                #region Inform the player that heal, three strike attack or defence is ready
                CheckIfHealAvailable(tools, player);
                CheckIfThreeStrikeAttackAvailable(tools);
                CheckIfDefenceAvailable(tools);
                #endregion

                MessagesBundles.ActionPrompt();

                string playerAction = Console.ReadLine();

                ConsoleMessageColor.SetMessageColorPlayer();

                switch (playerAction)
                {
                //Single attack
                case "1":
                    Print.PrintMessage(Messages.Action1);
                    enemy.GetHit(random.Next(player.MinAttackPower, player.MaxAttackPower));

                    break;

                //Three strike attack
                case "2":
                    Print.PrintMessage(Messages.Action2);

                    if (tools.NextThreeStrikeAttackIn == 0)
                    {
                        for (int i = 0; i < 3; i++)
                        {
                            enemy.GetHit(random.Next(player.MinAttackPower, player.MaxAttackPower));

                            if (enemy.IsDead)
                            {
                                break;
                            }
                        }

                        tools.NextThreeStrikeAttackIn = 6;
                        tools.ChangedNow = true;
                    }
                    else
                    {
                        Print.PrintMessage(Messages.CannotUseThreeStrikeAttackNow, tools.NextThreeStrikeAttackIn);
                    }

                    break;

                //Defend
                case "3":
                    Print.PrintMessage(Messages.Action3);


                    if (tools.NextDefenceIn == 0)
                    {
                        player.IsDefending = true;
                        tools.ChangedNow   = true;

                        Print.PrintMessage(Messages.IsDefending, player.Name);

                        tools.NextDefenceIn = 2;
                    }
                    else
                    {
                        Print.PrintMessage(Messages.CannotDefendNow, tools.NextDefenceIn);
                    }

                    break;

                //Heal
                case "4":
                    Print.PrintMessage(Messages.Action4);

                    if (tools.NextHealIn == 0)
                    {
                        player.Heal(random.Next(player.MinHealAmount, player.MaxHealAmount));
                        tools.NextHealIn = 4;
                        tools.ChangedNow = true;
                    }
                    else
                    {
                        Print.PrintMessage(Messages.CannotHealNow, tools.NextHealIn);
                    }

                    break;

                default:
                    Print.PrintMessage(Messages.ActionOther);
                    break;
                }

                //To set changeNow to false in - this round, after the three strike attack or heal was used.
                if (tools.ChangedNow == true)
                {
                    tools.ChangedNow = false;
                }
            }
            catch (Exception e)
            {
                Print.PrintMessage(Messages.PlayerMovesError, e);
            }
        }