Пример #1
0
        string HandleDebugGiveCommand(Command debugGiveCommand, Game game)
        {
            string objectString = debugGiveCommand.GetParameter("object");

            game.mInventory.AddItem(Emoji.GetID(objectString));
            return("");
        }
Пример #2
0
        string HandleTalkCommand(Command talkCommand, Game game)
        {
            string personString  = talkCommand.GetParameter("person");
            string subjectString = talkCommand.GetParameter("subject");

            Objects.ID personType = Emoji.GetID(personString);
            if (personType == Objects.ID.Unknown)
            {
                mStatus = Status.Frustrated;
                return("You can't even figure out who you're trying to talk to.");
            }

            Objects.ID subjectType = Objects.ID.Unknown;
            // Only try to parse if it's not empty
            if (subjectString != "")
            {
                subjectType = Emoji.GetID(subjectString);
                if (subjectType == Objects.ID.Unknown)
                {
                    mStatus = Status.Frustrated;
                    return("You can't even figure out what you're trying to talk about.");
                }
            }

            GridObject person = game.mRoom.FindObjectAdjacentTo(mPosition, personType);

            if (person == null)
            {
                mStatus = Status.Frustrated;
                return("They aren't close enough to talk to.");
            }

            return(person.TalkTo(subjectType, game));
        }
Пример #3
0
        string HandleGiveCommand(Command giveCommand, Game game)
        {
            string objectString = giveCommand.GetParameter("object");
            string personString = giveCommand.GetParameter("person");

            Objects.ID objectType = Emoji.GetID(objectString);

            if (objectType == Objects.ID.Unknown)
            {
                return("You can't even figure out what you're trying to give.");
            }

            if (!game.mInventory.Contains(objectType))
            {
                return("You don't have " + objectString);
            }

            Objects.ID personType = Emoji.GetID(personString);
            if (personType == Objects.ID.Unknown)
            {
                mStatus = Status.Frustrated;
                return("You can't even figure out who you're trying to talk to.");
            }

            GridObject person = game.mRoom.FindObjectAdjacentTo(mPosition, personType);

            if (person == null)
            {
                mStatus = Status.Frustrated;
                return("They aren't close enough to talk to.");
            }

            return(person.GiveObject(objectType, game));
        }
Пример #4
0
        string LookAtObjectCommand(Command lookAtCommand, Game game)
        {
            string objectString = lookAtCommand.GetParameter("object");

            Objects.ID objectType = Emoji.GetID(objectString);

            if (objectType == Objects.ID.Unknown)
            {
                mStatus = Status.Frustrated;
                return("You can't even figure out what that is.");
            }

            GridObject targetObject = game.mRoom.GetNearestObject(objectType, mPosition);

            if (targetObject == null)
            {
                if (game.mInventory.Contains(objectType))
                {
                    mStatus = Status.Thinking;
                    return(ObjectTraits.GetObjectTraits(objectType).GetDescription(game));
                }
                else
                {
                    mStatus = Status.Frustrated;
                    return("You don't see that here.");
                }
            }
            else
            {
                mStatus = Status.Thinking;
                return(targetObject.GetDescriptionText(game));
            }
        }
Пример #5
0
        string HandleUseWithoutTargetCommand(Command useCommand, Game game)
        {
            string actorString = useCommand.GetParameter("actor");

            Objects.ID actorType = Emoji.GetID(actorString);

            if (actorType == Objects.ID.Unknown)
            {
                mStatus = Status.Frustrated;
                return("You don't have that in your inventory.");
            }

            GridObject actorObject = game.mRoom.FindObjectAdjacentTo(mPosition, actorType);

            if (actorObject == null)
            {
                mStatus = Status.Frustrated;
                return("You couldn't find that nearby.");
            }

            ActionResult result = actorObject.UseWithoutTarget(game);

            if (!result.mSuccess)
            {
                mStatus = Status.Frustrated;
            }

            return(result.mOutput);
        }
Пример #6
0
        private string HandleTakeCommand(Command takeCommand, Game game)
        {
            string objectString = takeCommand.GetParameter("object");

            Objects.ID objectTypeToPickUp = Emoji.GetID(objectString);

            if (objectTypeToPickUp == Objects.ID.Unknown)
            {
                return("You couldn't find that nearby");
            }

            StaticObject staticObjectToPickup = game.mRoom.FindStaticObjectAdjacentTo(mPosition, objectTypeToPickUp);

            if (staticObjectToPickup != null)
            {
                return(objectString + " can't be picked up");
            }

            DynamicObject objectToPickUp = game.mRoom.FindDynamicObjectAdjacentTo(mPosition, objectTypeToPickUp);

            if (objectToPickUp == null)
            {
                return("There isn't " + objectString + " nearby");
            }

            if (!objectToPickUp.CanBePickedUp())
            {
                return(objectString + " can't be picked up");
            }

            game.mRoom.MarkObjectForDeletion(objectToPickUp);
            game.mInventory.AddItem(objectToPickUp);

            return("You picked up " + objectToPickUp.Render());
        }
Пример #7
0
        string HandleThrowCommand(Command throwCommand, Game game)
        {
            string objectString    = throwCommand.GetParameter("object");
            string directionString = throwCommand.GetParameter("direction");

            Objects.ID objectTypeToThrow = Emoji.GetID(objectString);

            if (objectTypeToThrow == Objects.ID.Unknown)
            {
                return("You don't have that");
            }

            if (!game.mInventory.Contains(objectTypeToThrow))
            {
                return("You don't have " + objectString);
            }

            Direction direction = Room.GetDirection(directionString);

            if (direction == Direction.Unknown)
            {
                return("Invalid direction");
            }

            Point throwVector = MathUtils.GetVector(direction);

            Point?furthestLandingPoint = null;

            for (int distanceThrown = 1; distanceThrown <= 3; distanceThrown++)
            {
                Point testPoint = mPosition + throwVector * distanceThrown;

                if (game.mRoom.CanSpaceBeMovedTo(testPoint))
                {
                    furthestLandingPoint = testPoint;
                }

                if (!game.mRoom.CanSpaceBeThrownThrough(testPoint))
                {
                    break;
                }
            }

            if (furthestLandingPoint == null)
            {
                return("No space to throw to the " + direction);
            }

            game.mInventory.RemoveItem(objectTypeToThrow);
            game.mRoom.SpawnObject(objectTypeToThrow, furthestLandingPoint.Value);

            return("You threw " + objectString);
        }
Пример #8
0
        string HandleEatCommand(Command eatCommand, Game game)
        {
            string objectString = eatCommand.GetParameter("object");

            Objects.ID objectType = Emoji.GetID(objectString);

            if (objectType == Objects.ID.Unknown)
            {
                mStatus = Status.Frustrated;
                return("You don't have that");
            }

            if (!game.mInventory.Contains(objectType))
            {
                mStatus = Status.Frustrated;
                return("You don't have " + objectString + " in your inventory.");
            }

            game.mInventory.RemoveItem(objectType);

            if (ObjectTraits.GetObjectTraits(objectType).mIsEdible)
            {
                if (ObjectTraits.GetObjectTraits(objectType).mCausesHallucinations)
                {
                    mStatus = Status.Tripping;
                    game.mRoom.mIsRenderingHallucination = true;
                    return(Emoji.Symbols.Dizzy + " Whoa " + Emoji.Symbols.Dizzy);
                }
                else if (ObjectTraits.GetObjectTraits(objectType).mIsHealthyToEat)
                {
                    mStatus = Status.SavoringFood;
                    return("That was delicious! You feel a renewed sense of determination.");
                }
                else
                {
                    Point?spaceToDropObject = game.mRoom.FindOpenSpaceAdjacentTo(mPosition);

                    if (spaceToDropObject != null)
                    {
                        game.mRoom.SpawnObject(objectType, spaceToDropObject.Value);
                    }

                    mStatus = Status.Vomiting;
                    return("Oh, that was a terrible idea.");
                }
            }
            else
            {
                mStatus = Status.Frustrated;
                return("You can't eat that!");
            }
        }
Пример #9
0
        public Room(string description, ICollection <string> roomLines, IEnumerable <GridObjectSetup> gridObjectSetups)
        {
            mDescription = description;

            Debug.Assert(roomLines.Count == Game.numRoomRows);

            int lineIndex = 0;

            foreach (string line in roomLines)
            {
                List <string> splitLine = StringUtils.SplitEmojiString(line);

                Debug.Assert(splitLine.Count == Game.numRoomColumns);

                for (int columnIndex = 0; columnIndex < splitLine.Count; columnIndex++)
                {
                    GridObject staticObject = GridObject.Create(Emoji.GetID(splitLine[columnIndex]), new Point(lineIndex, columnIndex));
                    mStaticRoomGrid[lineIndex, columnIndex] = (StaticObject)staticObject;
                }

                lineIndex++;
            }

            foreach (GridObjectSetup setup in gridObjectSetups)
            {
                GridObject gridObject = setup.CreateObject();

                if (gridObject as DynamicObject != null)
                {
                    mDynamicObjects.Add((DynamicObject)gridObject);
                }
                else
                {
                    Point position = gridObject.GetPosition();
                    mStaticRoomGrid[position.mRow, position.mColumn] = (StaticObject)gridObject;
                }
            }
        }
Пример #10
0
        private string HandleDropCommand(Command dropCommand, Game game)
        {
            string objectString    = dropCommand.GetParameter("object");
            string directionString = dropCommand.GetParameter("direction");

            Objects.ID objectTypeToDrop = Emoji.GetID(objectString);

            if (objectTypeToDrop == Objects.ID.Unknown)
            {
                return("You don't have that");
            }

            if (!game.mInventory.Contains(objectTypeToDrop))
            {
                return("You don't have " + objectString);
            }

            Direction direction = Room.GetDirection(directionString);

            if (direction == Direction.Unknown)
            {
                return("Invalid direction");
            }

            Point prospectiveDropPosition = MathUtils.GetAdjacentPoint(mPosition, direction);

            if (!game.mRoom.CanSpaceBeMovedTo(prospectiveDropPosition))
            {
                return("Space to the " + direction + " isn't open");
            }

            game.mInventory.RemoveItem(objectTypeToDrop);
            game.mRoom.SpawnObject(objectTypeToDrop, prospectiveDropPosition);

            return("You dropped " + objectString);
        }
Пример #11
0
        string HandleUseOnTargetCommand(Command useCommand, Game game)
        {
            string actorString  = useCommand.GetParameter("actor");
            string targetString = useCommand.GetParameter("target");

            Objects.ID actorType = Emoji.GetID(actorString);

            if (actorType == Objects.ID.Unknown)
            {
                mStatus = Status.Frustrated;
                return("You don't have that in your inventory.");
            }

            if (!game.mInventory.Contains(actorType))
            {
                mStatus = Status.Frustrated;
                return("You don't have " + actorString);
            }

            Objects.ID targetType = Emoji.GetID(targetString);

            if (targetType == Objects.ID.Unknown)
            {
                mStatus = Status.Frustrated;
                return("You can't find that");
            }

            GridObject targetObject = game.mRoom.FindObjectAdjacentTo(mPosition, targetType);

            if (targetObject == null)
            {
                mStatus = Status.Frustrated;
                return("There isn't " + targetString + " nearby");
            }

            string outText = "";

            if (targetType == Objects.ID.Lock)
            {
                Lock lockObject = targetObject as Lock;
                if (lockObject.CanBeUnlockedBy(actorType))
                {
                    lockObject.Unlock();
                    outText = "You unlocked the door with the " + actorString;
                }
            }
            else if (targetType == Objects.ID.Clamp)
            {
                Objects.ID crushingResult = ObjectTraits.GetObjectTraits(actorType).mCrushingResultType;
                if (crushingResult != Objects.ID.Unknown)
                {
                    game.mInventory.RemoveItem(actorType);
                    game.mInventory.AddItem(crushingResult);
                    outText = "You crushed the " + actorString;
                }
            }

            if (outText == "")
            {
                outText = "You don't think you can do that.";
                mStatus = Status.Frustrated;
            }

            return(outText);
        }