Ejemplo 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();
        }
Ejemplo n.º 2
0
        public void EnteredTile(IPlayer player)
        {
            if (!Visited)
            {
                Visited = true;
            }
            Console.WriteLine($"You entered a {GetType().Name}");
            var Victory = false;

            Action victory = () => Victory = true;
            Action defeat  = () => Victory = false;

            _battleManager.Battle(player, _enemy, victory, defeat);
            if (Victory)
            {
                player.ResetHealthMana();
            }
            StaticHelperClass.PrintException(null, 3);
        }
Ejemplo n.º 3
0
        private List <ITile> GetTiles(TileTypeEnum tileType, XmlNodeList tiles)
        {
            GetTileType(tileType, out List <ITile> list, out Type typeOfTile);
            try
            {
                //Follows schema of Location, RegionId, Visited, Cleared (Dungeon only)
                foreach (XmlNode tile in tiles)
                {
                    var locationNode = tile.FirstChild;
                    if (locationNode == null)
                    {
                        Console.WriteLine($"Invalid location node: {tile.ParentNode.Name}");
                        continue;
                    }
                    var    x        = Convert.ToInt32(locationNode.FirstChild.InnerXml);
                    var    y        = Convert.ToInt32(locationNode.LastChild.InnerXml);
                    IPoint location = new Point2D(x, y);

                    var regionNode = locationNode.NextSibling;
                    if (regionNode == null)
                    {
                        Console.WriteLine($"Invalid regionID node: {tile}");
                        continue;
                    }
                    var region = regionNode.InnerXml;

                    var visitedNode = regionNode.NextSibling;
                    var visited     = visitedNode != null?Convert.ToBoolean(visitedNode.InnerXml) : false;

                    var tileParams = new List <object>
                    {
                        location,
                        region,
                        visited
                    };

                    if (typeOfTile == typeof(DungeonTile))
                    {
                        var clearedNode = visitedNode.NextSibling;
                        if (clearedNode != null)
                        {
                            tileParams.Add(Convert.ToBoolean(clearedNode.InnerXml));
                        }
                        else
                        {
                            tileParams.Add(false);
                        }
                        //TODO: Add as field in xml doc
                        var numOfEnemies = 3;
                        tileParams.Add(numOfEnemies);
                    }
                    if (typeOfTile == typeof(EnemyTile) || typeOfTile == typeof(DungeonTile))
                    {
                        tileParams.Add(_battleManager);
                    }

                    var newTile = (ITile)Activator.CreateInstance(typeOfTile, tileParams.ToArray());
                    list.Add(newTile);
                }
                return(list);
            }
            catch (Exception e)
            {
                StaticHelperClass.PrintException(e, 3);
            }
            return(null);
        }
Ejemplo n.º 4
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);
                }
            }
        }
Ejemplo n.º 5
0
        public void PerformMovement()
        {
            while (true)
            {
                try
                {
                    Console.WriteLine("1. Move Up");
                    Console.WriteLine("2. Move Down");
                    Console.WriteLine("3. Move Left");
                    Console.WriteLine("4. Move Right");
                    int option = int.Parse(Console.ReadLine());
                    switch (option)
                    {
                    case 1:
                    {
                        if (CurrentLoc.Y < MaxHeight - 1)
                        {
                            CurrentLoc.Y++;
                        }
                    }
                    break;

                    case 2:
                    {
                        if (CurrentLoc.Y > 0)
                        {
                            CurrentLoc.Y--;
                        }
                    }
                    break;

                    case 3:
                    {
                        if (CurrentLoc.X > 0)
                        {
                            CurrentLoc.X--;
                        }
                    }
                    break;

                    case 4:
                    {
                        if (CurrentLoc.X < MaxWidth - 1)
                        {
                            CurrentLoc.X++;
                        }
                    }
                    break;

                    default:
                    {
                        Console.WriteLine("Invalid direction\r\n");
                        continue;
                    }
                    }
                    return;
                }
                catch (Exception e)
                {
                    StaticHelperClass.PrintException(e, 2);
                }
            }
        }