Пример #1
0
        public async Task <string> Move(string input, Player player)
        {
            var response = "";
            //get direction, move player and return the player's new location
            var    words = input.ToLower().Split(" ").ToList();
            string word;

            if (IsDirection(words[0]))
            {
                word = words[0];
            }
            else
            {
                word = input.RemoveWordsFromString(0, 1);
            }
            var direction = DirectionEnum.None;

            switch (word)
            {
            case "north":
                direction = DirectionEnum.North;
                break;

            case "south":
                direction = DirectionEnum.South;
                break;

            case "west":
                direction = DirectionEnum.West;
                break;

            case "east":
                direction = DirectionEnum.East;
                break;

            case "up":
                direction = DirectionEnum.Up;
                break;

            case "down":
                direction = DirectionEnum.Down;
                break;
            }
            var currentCell = await _cellLogic.GetPlayerCell(player);

            var newCell = await _cellLogic.GetCellRelativeToCell(currentCell, direction);

            if (newCell != null)
            {
                response += $"You move {direction.ToString()}.\n";

                await Replicate($"{player.Name} moves {direction}", player);

                await _cellLogic.UpdateEntityCell(player, newCell);

                string oppDirectionString;

                switch (direction)
                {
                case DirectionEnum.North:
                    oppDirectionString = "the South";
                    break;

                case DirectionEnum.South:
                    oppDirectionString = "the North";
                    break;

                case DirectionEnum.West:
                    oppDirectionString = "the East";
                    break;

                case DirectionEnum.East:
                    oppDirectionString = "the West";
                    break;

                case DirectionEnum.Up:
                    oppDirectionString = "above";
                    break;

                case DirectionEnum.Down:
                    oppDirectionString = "below";
                    break;

                default:
                    oppDirectionString = "somewhere";
                    break;
                }

                await Replicate($"{player.Name} arrives from {oppDirectionString}", player);

                response += _cellLogic.CellDescriptionForPlayer(player);
            }
            else
            {
                response += "You cannot go any further in this direction.";
            }
            return(response);
        }