예제 #1
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);
        }
예제 #2
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;
                }
            }
        }