Beispiel #1
0
        public void CreateImage(IEnumerable <string> args)
        {
            var settings      = GetSettings(args);
            var reader        = new FileTextReader();
            var words         = reader.ReadWords(settings.InputFilePath);
            var filter        = new Filter();
            var filteredWords = filter.FilterWords(words);
            IEnumerable <string> newFilteredWords = null;

            if (filteredWords.IsSuccess)
            {
                newFilteredWords = filteredWords.Value;
            }
            var converter       = new WordToSizeConverter();
            var wordsSizes      = converter.ConvertToSizes(newFilteredWords);
            var visualisator    = new Visualisator();
            var color           = settings.WordsColor;
            var font            = settings.WordsFont;
            var layouter        = new CircularCloudLayouter();
            var wordsRectangles = wordsSizes.Select(s => new Tuple <string, Rectangle>(s.Item1, layouter.PutNextRectangle(s.Item2)));
            var currentBitmap   = visualisator.Visualize(wordsRectangles, settings.ImageSize, color, font);
            var saver           = new Saver();

            saver.SaveImage(currentBitmap, settings.OutputFilePath);
        }
Beispiel #2
0
        private void ConsumePlaceGains(Position newPlayerPosition)
        {
            foreach (var place in allPlaces)
            {
                if (place.Position.Row == newPlayerPosition.Row &&
                    place.Position.Col == newPlayerPosition.Col)
                {
                    if (!place.IsVisited)
                    {
                        var    gain      = place.Gain;
                        var    gainType  = string.Empty;
                        double gainValue = place.Value;

                        switch (gain)
                        {
                        case Place.PlaceGain.Health:

                            if (this.player.Health + place.Value <= Player.MaxHealth)
                            {
                                this.player.Health += place.Value;
                            }
                            else
                            {
                                gainValue          = Player.MaxHealth - this.player.Health;
                                this.player.Health = Player.MaxHealth;
                            }

                            gainType = Enum.GetName(typeof(Place.PlaceGain), Place.PlaceGain.Health);
                            break;

                        case Place.PlaceGain.Armor:
                            this.player.Defense += place.Value;
                            gainType             = Enum.GetName(typeof(Place.PlaceGain), Place.PlaceGain.Armor);
                            break;

                        case Place.PlaceGain.Experience:
/*                                this.player.Experience += place.Value;*/
                            this.player.GainGoldAndExperience(place.Value, 0);
                            gainType = Enum.GetName(typeof(Place.PlaceGain), Place.PlaceGain.Experience);
                            break;

                        case Place.PlaceGain.Gold:
/*                                this.player.Gold += place.Value;*/
                            this.player.GainGoldAndExperience(0, place.Value);
                            gainType = Enum.GetName(typeof(Place.PlaceGain), Place.PlaceGain.Gold);
                            break;
                        }

                        Visualisator.PrintUnderTheBattleField(VisualisatorConstants.PlaceGainConsumed + place.Type + " " + gainValue + " " + gainType);
                        place.IsVisited = true;
                    }
                    else
                    {
                        Visualisator.PrintUnderTheBattleField(VisualisatorConstants.PlaceAlreadyVisited);
                    }
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Places the player on his new position.
        /// INVOKES a method which takes care of the symbol placement on the console.
        /// The invoked method swaps the old symbol position and the new symbol position.
        /// </summary>
        /// <param name="newPlayerPosition">The new position of the player.</param>
        private void PlaceThePlayerOnHisNewPosition(Position newPlayerPosition)
        {
            this.SwapSymbolsInDungeon(this.player.Position, newPlayerPosition);

            Visualisator.DeleteSymbolOnPositionAndPrintNewOne(' ', this.player.Position, PlayerConstants.Color);
            Visualisator.DeleteSymbolOnPositionAndPrintNewOne(PlayerConstants.Symbol, newPlayerPosition, PlayerConstants.Color);

            this.player.Position = newPlayerPosition;

            Visualisator.PrintPlayerStats(this.player);
        }
Beispiel #4
0
        /// <summary>
        /// Open door to the boss and goes to next level.
        /// </summary>
        /// <param name="newPlayerPosition"></param>
        private void TryOpenDoor(Position newPlayerPosition)
        {
            if (allEnemies.Count <= 1)
            {
                PlaceThePlayerOnHisNewPosition(newPlayerPosition);
            }
            else
            {
                Visualisator.PrintUnderTheBattleField(VisualisatorConstants.UnableToCompleteLevel);
            }

            //dinamichno vzemane na levela za zavurshvane na nivoto.

/*            if (player.Level >= 6)
 *          {
 *              PlaceThePlayerOnHisNewPosition(newPlayerPosition);
 *          }
 *          else
 *          {
 *              //print message why can't open the door.
 *          }*/
        }
Beispiel #5
0
        private void GenerateAndVisitSphinx(Position sphinxPosition)
        {
            if (sphinx == null)
            {
                this.sphinx = new Sphinx(sphinxPosition,
                                         SphinxConstants.BonusGold * levelGenerator.CurrentLevelNumber,
                                         SphinxConstants.MinusHealth * levelGenerator.CurrentLevelNumber);
            }
            if (sphinx.IsVisited)
            {
                Visualisator.PrintUnderTheBattleField(VisualisatorConstants.SphinxIsVisited);
                return;
            }
            var riddle = new Riddle();

            riddle.LoadQuestion();
            bool IsTheAnswerCorrect = riddle.IsItRight();

            sphinx.IsVisited = true;
            if (IsTheAnswerCorrect)
            {
                player.Gold += sphinx.BonusGold;
            }
            else
            {
                if (player.Health <= sphinx.MinusHealth)
                {
                    player.Health = 1;
                }
                else
                {
                    player.Health -= sphinx.MinusHealth;
                }
            }
            Visualisator.PrintAllMap(dungeon, player);
        }
Beispiel #6
0
        /// <summary>
        /// This method is executed everytime the player moves.
        /// </summary>
        /// <param name="sender">The publisher of the event. The player.</param>
        /// <param name="playerEventArgs">Holds the needed things that changed.</param>
        public void OnPlayerMoved(object sender, PlayerEventArgs playerEventArgs)
        {
            Position newPlayerPosition = playerEventArgs.NewPlayerPosition;

            if (PlayerFellOfTheDungeon(newPlayerPosition))
            {
                this.allEnemies = new List <Enemy>();
                this.allPlaces  = new List <Place>();

                this.dungeon = new List <char[]>();

                levelGenerator.GenerateFullLevelPath();
                levelGenerator.GenerateLevel(this.player, this.allEnemies, this.allPlaces, this.dungeon);

                return;
            }

            char newPositionCell = this.GetSymbolFromDungeon(newPlayerPosition);

            //Executes different method depending on the cell that the player wants to step on.
            //EVERYTIME THE PLAYER MOVES SUCCESSFULLY YOU MUST INVOKE THE SWAP SYMBOLS METHOD3
            //You must do it so the dungeon knows where the player is.
            switch (newPositionCell)
            {
            //If he wants to step on the ground we let him.
            case LevelConstants.Ground:
                PlaceThePlayerOnHisNewPosition(newPlayerPosition);
                break;

            case LevelConstants.Lava:
                Visualisator.PrintEndGameMessage(PlayerConstants.SteppedIntoLavaMessage);
                break;

            case LevelConstants.Wall:
                break;

            case LevelConstants.Door:
                TryOpenDoor(newPlayerPosition);
                break;

            case LevelConstants.SpellboundForest:
                Visualisator.PrintEndGameMessage(PlayerConstants.LostIntoSpellboundForest);
                break;

            case LevelConstants.RiverOfMercury:
                Visualisator.PrintEndGameMessage(PlayerConstants.EnterIntoRiverOfMercury);
                break;

            case ShopConstants.Symbol:
                BuyPotion();
                Visualisator.PrintAllMap(dungeon, player);
                ShopConstants.PrintLastShopAction();

                break;

            case SphinxConstants.Symbol:
                GenerateAndVisitSphinx(newPlayerPosition);

                break;

            //all the monsters are traversed here.
            default:

                bool isEnemy = false;
                var  enemy   = new Enemy();


                foreach (var thisEnemy in allEnemies)
                {
                    if ((thisEnemy.Position.Col == newPlayerPosition.Col) &&
                        (thisEnemy.Position.Row == newPlayerPosition.Row))
                    {
                        isEnemy = true;
                        enemy   = thisEnemy;
                        break;
                    }
                }

                if (isEnemy)
                {
                    EnterInBattle(enemy);
                    break;
                }

                else
                {
                    ConsumePlaceGains(newPlayerPosition);

                    break;
                }
            }
        }
Beispiel #7
0
 /// <summary>
 /// This method is executed when the player dies.
 /// </summary>
 /// <param name="sender">The publisher of the event. The player.</param>
 /// <param name="playerEventArgs">Holds the needed things that changed.</param>
 public void OnPlayerDied(object sender, PlayerEventArgs playerEventArgs)
 {
     BattleGround.BattleResult.AppendLine(PlayerConstants.PlayerDiedDueToAttack);
     Visualisator.PrintEndGameMessage(BattleGround.BattleResult.ToString());
 }
Beispiel #8
0
 /// <summary>
 /// GenerateStats battle screen and start battle.
 /// </summary>
 /// <param name="enemy"></param>
 private void EnterInBattle(Enemy enemy)
 {
     BattleGround.BattleResult.Clear();
     BattleGround.GenerateStats(player, enemy);
     Visualisator.PrintBattleGround(this.dungeon, this.player, BattleGround.BattleResult);
 }
        /// <summary>
        /// Processes the level and inializes the arguments.
        /// Finds the player position and the enemies positions.
        /// Fills the dungeon.
        /// </summary>
        /// <param name="player">The player in the game that you want to initialize.</param>
        /// <param name="allEnemies">The enemies in the game which you want to initialize.</param>
        /// <param name="dungeon">The dungeon that you want to create.</param>
        public void GenerateLevel(Player player, List <Enemy> allEnemies, List <Place> allPlaces, List <char[]> dungeon)
        {
            using (leverReader)
            {
                // Processes each line of the level txt file and either adds this line as char array to the dungeon list
                // or passes it to the GenerateEnemiesList method whenever the line hold technical info i.e. starts with /I/E for enemies or /I/O for obstacles
                string currentLine;
                int    currentRow = 0;

                var createNewEnemyList    = true;
                var createNewPlaceList    = true;
                var createNewObstacleList = true;

                while ((currentLine = leverReader.ReadLine()) != default(string))
                {
                    if (currentRow < Constants.Console.ConsoleConstants.FieldHeight)
                    {
                        dungeon.Add(currentLine.ToCharArray());
                    }
                    else
                    {
                        if (currentLine != string.Empty)
                        {
                            var objectTokens = currentLine.Split(LevelConstants.LegendSplitSymbols, StringSplitOptions.RemoveEmptyEntries);

                            switch (objectTokens[0])
                            {
                            case LevelConstants.EnemyInput:
                                GenerateEnemiesList(objectTokens, createNewEnemyList);

                                if (createNewEnemyList)
                                {
                                    createNewEnemyList = false;
                                }
                                break;

                            case LevelConstants.ObstacleInput:
                                GenerateObstaclesList(objectTokens, createNewObstacleList);
                                if (createNewObstacleList)
                                {
                                    createNewObstacleList = false;
                                }
                                break;

                            case LevelConstants.PlaceInput:
                                GeneratePlacesList(objectTokens, createNewPlaceList);
                                if (createNewPlaceList)
                                {
                                    createNewPlaceList = false;
                                }
                                break;

                            default:
                                break;
                            }
                        }
                    }

                    currentRow++;
                }

                //Processing every row element by element and finding the positions of all units.
                currentRow = 0;
                foreach (var line in dungeon)
                {
                    for (int currentCol = 0;
                         currentCol < Constants.Console.ConsoleConstants.FieldWidth;
                         currentCol++)
                    {
                        char symbol = line[currentCol];

                        switch (symbol)
                        {
                        case PlayerConstants.Symbol:

                            // if (loadGameExists)

                            // We could insert our load logic here ! But we need to pass the whole player class not only his possition property

                            //   player = new Player();

                            player.Position = new Position(currentRow, currentCol);
                            break;

                        case LevelConstants.Wall:
                        case LevelConstants.Ground:
                        case LevelConstants.Door:
                        case LevelConstants.SpellboundForest:
                        case LevelConstants.Lava:
                        case LevelConstants.RiverOfMercury:
                            break;

                        default:

                            if (levelEnemies.ContainsKey(symbol))
                            {
                                GenerateCurrentEnemy(symbol, allEnemies, new Position(currentRow, currentCol));
                                break;
                            }

                            else
                            {
                                GenerateCurrentPlace(symbol, allPlaces, new Position(currentRow, currentCol));
                                break;
                            }
                        }
                    }

                    currentRow++;
                }

                Visualisator.PrintDungeon(dungeon, player);
                CurrentMapLegend = Visualisator.PrintMapLegend(levelEnemies, levelObstacles, levelPlaces);
                Visualisator.PrintOnTheConsole(CurrentMapLegend);

                Console.SetWindowPosition(0, 0);
            }

            OnLevelGenerated(player);
        }