Exemplo n.º 1
0
        public void Play()
        {
            var loc = Player.GetCurrentLocation();

            Map.OpenMap(loc);
            while (!VictoryCondition.VictoryConditionAchieved())
            {
                loc = Player.GetCurrentLocation();
                Player.PrintStats(true);
                try
                {
                    var option = StaticHelperClass.ReadWriteOptions(new List <string> {
                        "Move", "Rest/Fight again", "Save", "Quit"
                    });
                    Console.Clear();
                    switch (option)
                    {
                    case 1:
                    {
                        Move();
                    }
                    break;

                    case 2:
                    {
                        Rest();
                    }
                    break;

                    case 3:
                    {
                        Save();
                    }
                    break;

                    case 4:
                    {
                        Quit();
                    }
                    break;

                    default:
                    {
                        Console.WriteLine("Cannot perform action.\r\n");
                    }
                    break;
                    }
                    VictoryCondition.VictoryConditionAchieved();
                }
                catch (Exception e)
                {
                    StaticHelperClass.PrintException(e, 1);
                }
            }
            VictoryCondition.DisplayVictoryMessage();
            Quit();
        }
Exemplo n.º 2
0
        public void Battle(IPlayer player, IEnemy enemy, Action victory, Action defeat)
        {
            Victory = victory ?? throw new ArgumentNullException(nameof(victory));
            Defeat  = defeat ?? throw new ArgumentNullException(nameof(defeat));

            while (true)
            {
                try
                {
                    var  enemyAttackChance = Randomizer.Next(randomizeInt) + 1;
                    bool enemyCanAttack    = enemyAttackChance <= 90;

                    var name = (enemy.IsEnemyBoss() ? "Boss" : "") + enemy.GetType().Name;

                    Console.WriteLine($"You are battling {name}");
                    enemy.GetCurrentStats().DisplayStats(true);
                    Console.WriteLine();

                    player.PrintStats(true);

                    var option = StaticHelperClass.ReadWriteOptions(new List <string> {
                        "Attack w/out Magic", $"Attack w/ Magic({player.GetCostOfSpell()}MP)", "Charge Mana", "Retreat"
                    });

                    //The if conditional is if either side is defeated.
                    switch (option)
                    {
                    case 1:
                    {
                        if (Attack(player, enemy, false, enemyAttackChance, enemyCanAttack))
                        {
                            return;
                        }
                    }
                    break;

                    case 2:
                    {
                        if (Attack(player, enemy, true, enemyAttackChance, enemyCanAttack))
                        {
                            return;
                        }
                    }
                    break;

                    case 3:
                    {
                        if (ChargeMana(player, enemy, enemyAttackChance, enemyCanAttack))
                        {
                            return;
                        }
                    }
                    break;

                    case 4:
                    {
                        Console.WriteLine("WIMP");
                        Defeat();
                        return;
                    }

                    default:
                    {
                        Console.WriteLine("Cannot perform action.\r\n");
                    }
                    break;
                    }
                    Console.Clear();
                }
                catch (Exception e)
                {
                    StaticHelperClass.PrintException(e);
                }
            }
        }