Exemple #1
0
        private void PlacePlayer(GameLogic.RLMap map, RLPlayerAction action)
        {
            int playerDestinationX, playerDestinationY;

            playerDestinationX = hero.locationX;
            playerDestinationY = hero.locationY;

            var messageToAdd = new Tuple<ConsoleColor, string>(ConsoleColor.White, "");

            switch (action)
            {
                case RLPlayerAction.EmptyAction:
                    break;
                case RLPlayerAction.MoveUp:
                    playerDestinationY = hero.locationY - 1;
                    messageToAdd = new Tuple<ConsoleColor, string>(ConsoleColor.Green, "You step north");
                    break;
                case RLPlayerAction.MoveDown:
                    playerDestinationY = hero.locationY + 1;
                    messageToAdd = new Tuple<ConsoleColor, string>(ConsoleColor.Green, "You step south");
                    break;
                case RLPlayerAction.MoveLeft:
                    playerDestinationX = hero.locationX - 1;
                    messageToAdd = new Tuple<ConsoleColor, string>(ConsoleColor.Green, "You step west");
                    break;
                case RLPlayerAction.MoveRight:
                    playerDestinationX = hero.locationX + 1;
                    messageToAdd = new Tuple<ConsoleColor, string>(ConsoleColor.Green, "You step east");
                    break;
                case RLPlayerAction.Wait:
                    messageToAdd = new Tuple<ConsoleColor, string>(ConsoleColor.Cyan, "You wait");
                    break;
                case RLPlayerAction.Save:
                    SaveGame();
                    break;
                case RLPlayerAction.Load:
                    LoadGame();
                    playerDestinationX = hero.locationX;
                    playerDestinationY = hero.locationY;
                    renderer.DrawAgent(map, hero, hero.locationX, hero.locationY);
                    break;
                default:
                    break;
            }

            var destinationAgent = monsters
                                    .Where(a => a.locationX == playerDestinationX && a.locationY == playerDestinationY)
                                    .Where(a => a.GetType() != typeof(RLHero))
                                    .FirstOrDefault();

            if (map.isLocationPassable(playerDestinationX, playerDestinationY)
                || (hero.locationY == playerDestinationY && hero.locationX == playerDestinationX))
            {

                renderer.DrawAgent(map, hero, playerDestinationX, playerDestinationY);
                hero.locationX = playerDestinationX;
                hero.locationY = playerDestinationY;
            }
            else if (destinationAgent != null)
            {
                var attackResults = destinationAgent.attackedBy(hero, dice);
                foreach (var attackMessage in attackResults)
                {
                    messages.Push(new Tuple<ConsoleColor, string>(ConsoleColor.Red, attackMessage));
                }
                renderer.DrawAgent(map, hero, hero.locationX, hero.locationY);
            }
            else
            {
                messageToAdd = new Tuple<ConsoleColor, string>(ConsoleColor.Red, DESTINATION_IMPASSABLE);
                renderer.DrawAgent(map, hero, hero.locationX, hero.locationY);
            }
            messages.Push(messageToAdd);
        }