Exemplo n.º 1
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;
                }
            }
        }
Exemplo n.º 2
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());
 }