Esempio n. 1
0
def AddRoom(GAME, screen):

    # Get the name of the room
    screen.clear()
    header = GAME.name
    question = "What is the name of this room?"
    name = useful.AskWithConfirm(header, question, screen)

    # Get the description of the room
    screen.clear()
    header = name
    question = "What is the description of this room? ('Look' action)"
    description = useful.AskWithConfirm(header, question, screen)

    Room = roomsquirrel.RoomSquirrel(name, description)
    GAME.rooms.append(Room)
Esempio n. 2
0
def AddCustomAction(GAME, screen):

    # Get the verb of the action
    screen.clear()
    header = GAME.name
    # We should be careful not to use words that will be excluded for uselessness
    question = "What is the command line associated with this action?"
    verb = useful.AskWithConfirm(header, question, screen)

    # Get the format of the action
    screen.clear()
    header = verb
    question = "What is the format of this action?"
    screen = useful.PrintHeader(header, screen, 0, 0)
    screen = useful.PrintText(question, screen, 4, 0)
    selectedformat = useful.ShowMenu(MENU_ACTION_FORMAT, screen, 6, 0)
    formatType = selectedformat[1]

    # To which room is this action bound?
    screen.clear()
    header = verb
    question = "To which room is this action bound?"
    screen = useful.PrintHeader(header, screen, 0, 0)
    screen = useful.PrintText(question, screen, 4, 0)

    roomMenu = [(r.name) for r in GAME.rooms]
    roomMenu.append("NOT ROOM BOUND")
    roomselected = useful.ShowMenu(roomMenu, screen, 6, 0)

    if roomselected[0] == "NOT ROOM BOUND":
        roomBound = False
    else:
        roomBound = roomselected[1]

    # To which item is this action bound?
    screen.clear()
    header = verb
    question = "To which item is this action bound?"
    screen = useful.PrintHeader(header, screen, 0, 0)
    screen = useful.PrintText(question, screen, 4, 0)

    pickableItems = GAME.GetPickableItems()
    itemMenu = []
    for item in pickableItems:
        itemMenu.append(GAME.items[item].name)
    itemMenu.append("NOT ITEM BOUND")
    itemselected = useful.ShowMenu(itemMenu, screen, 6, 0)

    if itemselected[0] == "NOT ITEM BOUND":
        itemBound = False
    else:
        itemBound = pickableItems[itemselected[1]]

    # Give the custom action its behavior
    listFuns, listArgs = ChooseBehaviors(GAME, screen, verb)

    customAction = actionsquirrel.CustomAction(verb, formatType, roomBound,
                                               itemBound, listFuns, listArgs)
    GAME.customActions.append(customAction)
Esempio n. 3
0
def AddBlockDisplayText(GAME, screen, verb):
    screen.clear()
    header = verb
    question = "What text do you want to be displayed?"

    text = useful.AskWithConfirm(header, question, screen)

    return actionsquirrel.DisplayText, [text]
Esempio n. 4
0
def AddBlockChangeScore(GAME, screen, verb):
    screen.clear()
    header = verb
    question = "How many points does the player gain? (Only Digits)"

    while True:
        points = useful.AskWithConfirm(header, question, screen)
        if useful.IsOnlyDigits(points):
            break

    return actionsquirrel.ChangeScore, [int(points)]
Esempio n. 5
0
def EditGame(GAME, screen):
    while True:
        screen.clear()

        # GAME MENU #
        header = GAME.name
        screen = useful.PrintHeader(header, screen, 0, 0)
        screen = useful.PrintText("What do you want to do?", screen, 4, 0)
        selection = useful.ShowMenu(MENU_EDIT_GAME, screen, 6, 0)
        # END GAME MENU #

        # CHANGE NAME #
        if selection[0] == MENU_EDIT_GAME[0]:
            screen.clear()
            question = "What is the new name of your game?"
            GAME.name = useful.AskWithConfirm(header, question, screen)
        # END CHANGE NAME #

        # WRITE INTRODUCTION #
        if selection[0] == MENU_EDIT_GAME[1]:
            screen.clear()
            question = "What is the introductory text for your game?"
            GAME.introduction = useful.AskWithConfirm(header, question, screen)
        # END WRITE INTRODUCTION #

        # WRITE HELP #
        if selection[0] == MENU_EDIT_GAME[2]:
            question = "Write the HELP information."
            GAME.instructions = useful.AskWithConfirm(header, question, screen)
        # END WRITE HELP "

        # WRITE CREDITS #
        if selection[0] == MENU_EDIT_GAME[3]:
            question = "Write the CREDITS."
            GAME.credits = useful.AskWithConfirm(header, question, screen)
        # END WRITE CREDITS "

        # BACK #
        if selection[0] == "BACK":
            break
Esempio n. 6
0
def EditItem(GAME, screen):
    while True:
        screen.clear()
        # Chose Item to Edit
        header = GAME.name
        question = "Which item would you like to edit?"
        screen = useful.PrintHeader(header, screen, 0, 0)
        screen = useful.PrintText(question, screen, 4, 0)

        ItemMenu = [(i.name) for i in GAME.items]
        ItemMenu.append("BACK")
        itemselected = useful.ShowMenu(ItemMenu, screen, 6, 0)

        if itemselected[0] == "BACK":
            break

        else:

            while True:
                screen.clear()
                item = GAME.items[itemselected[1]]
                header = item.name
                name = "Name: " + item.name
                description = "Description: " + item.description
                pickable = "Is Pickable: " + str(item.isPickable)
                droppable = "Is Droppable: " + str(item.isDroppable)
                if item.whereIs == -1:
                    place = "Place: NOT SET"
                elif item.whereIs == -2:
                    place = "Place: PLAYER INVENTORY"
                else:
                    place = "Place: " + GAME.rooms[item.whereIs].name

                screen = useful.PrintHeader(header, screen, 0, 0)
                screen = useful.PrintText(name, screen, 4, 0)
                screen = useful.PrintText(description, screen, 5, 0)
                screen = useful.PrintText(pickable, screen, 6, 0)
                screen = useful.PrintText(droppable, screen, 7, 0)
                screen = useful.PrintText(place, screen, 8, 0)
                question = "What would you like to change??"
                screen = useful.PrintText(question, screen, 10, 0)

                selected = useful.ShowMenu(MENU_EDIT_ITEM, screen, 12, 0)

                # EDIT NAME #
                if selected[0] == MENU_EDIT_ITEM[0]:
                    screen.clear()
                    question = "What is the new name of this item?"
                    name = useful.AskWithConfirm(header, question, screen)
                    GAME.items[itemselected[1]].name = name
                    header = name
                # END EDIT NAME #

                # EDIT DESCRIPTION #
                elif selected[0] == MENU_EDIT_ITEM[1]:
                    screen.clear()
                    question = "What is the new description of this item?"
                    description = useful.AskWithConfirm(
                        header, question, screen)
                    GAME.items[itemselected[1]].description = description
                # END EDIT DESCRIPTION #

                # INVENTORY BEHAVIOR #
                elif selected[0] == MENU_EDIT_ITEM[2]:
                    # Pickable?
                    screen.clear()
                    question = "Can the user pick this item up?"
                    screen = useful.PrintHeader(header, screen, 0, 0)
                    screen = useful.PrintText(question, screen, 4, 0)
                    if useful.ShowMenu(MENU_CONFIRM, screen, 6, 0)[0] == "YES":
                        isPickable = True

                        # Droppable?
                        screen.clear()
                        question = "Can the user drop this item from his inventory?"
                        screen = useful.PrintHeader(header, screen, 0, 0)
                        screen = useful.PrintText(question, screen, 4, 0)
                        if useful.ShowMenu(MENU_CONFIRM, screen, 6,
                                           0)[0] == "YES":
                            isDroppable = True
                        else:
                            isDroppable = False
                    else:
                        isPickable = False
                        isDroppable = False
                    GAME.items[itemselected[1]].isPickable = isPickable
                    GAME.items[itemselected[1]].isDroppable = isDroppable

                # END INVENTORY BEHAVIOR #

                # PLACE ITEM #
                elif selected[0] == MENU_EDIT_ITEM[3]:
                    # Select room in which to place item
                    screen.clear()
                    question = "Where would you like to put this item?"
                    screen = useful.PrintHeader(header, screen, 0, 0)
                    screen = useful.PrintText(question, screen, 4, 0)

                    RoomMenu = [(r.name) for r in GAME.rooms]
                    if item.isPickable == True:
                        RoomMenu.append("PLAYER INVENTORY")
                    RoomMenu.append("NOWHERE")
                    RoomMenu.append("BACK")
                    roomselected = useful.ShowMenu(RoomMenu, screen, 6, 0)

                    if roomselected[0] == "BACK":
                        break

                    elif roomselected[0] == "PLAYER INVENTORY":
                        # HERE I'M USING -2 TO MARK PLAYER INVENTORY
                        GAME.PlaceItem(itemselected[1], -2)

                    elif roomselected[0] == "NOWHERE":
                        GAME.PlaceItem(itemselected[1], -1)
                    else:
                        GAME.PlaceItem(itemselected[1], roomselected[1])

                # END PLACE ITEM #

                # Exit menu
                elif selected[0] == "BACK":
                    break
Esempio n. 7
0
def main(screen):

    # Initialize curses
    screen = curses.initscr()
    curses.curs_set(False)  # Removes blinking cursor

    header = "Adventure Squirrel"

    while True:
        screen.clear()
        # TOP MENU #
        screen = useful.PrintHeader(header, screen, 0, 0)
        screen = useful.PrintText("A text-based adventure game engine", screen,
                                  4, 0)
        selection = useful.ShowMenu(MENU_TOP, screen, 6, 0)
        # End TOP MENU #

        # BEGIN Create a new game #
        if selection[0] == MENU_TOP[0]:
            screen.clear()

            # Initialize the Game
            GAME = gamesquirrel.GameSquirrel()

            # Ask for the name of the game
            question = "What is the name of your game?"
            GAME.name = useful.AskWithConfirm(header, question, screen)

            WriteGame(GAME, screen)
            break
        # END Create a new game#

        # BEGIN EDIT a saved game #
        elif selection[0] == MENU_TOP[1]:
            screen.clear()

            question = "What is name of the pickle file that contains the game information?"
            # Ask for the name of the pickle file
            while True:
                filename = useful.Ask(header, question, screen)
                filename += ".pickle"
                GAME = useful.LoadStory(filename)
                if GAME == -1:
                    screen.clear()
                    question2 = "The file '" + filename + "' was not found. Do you want to try a different one?."
                    screen = useful.PrintHeader(header, screen, 0, 0)
                    screen = useful.PrintText(question2, screen, 4, 0)
                    again = useful.ShowMenu(MENU_CONFIRM, screen, 6, 0)
                    if again[0] != "YES":
                        break

                else:
                    WriteGame(GAME, screen)
                    break
            if GAME != -1:
                break
        # END EDIT a saved game #

        # BEGIN EXIT THIS PROGRAM #
        else:
            screen.clear()
            screen = useful.PrintHeader(header, screen, 0, 0)
            screen = useful.PrintText("It was good to have you around!",
                                      screen, 4, 0)
            screen.refresh()
            time.sleep(2)
            break
        # END EXIT this program#

    curses.endwin()
Esempio n. 8
0
def AddItem(GAME, screen, fromRoomFlag):

    # Ask for the name of the item
    screen.clear()
    header = GAME.name
    question = "What is the name of this item?"
    name = useful.AskWithConfirm(header, question, screen)

    # Ask for the description of the item
    screen.clear()
    header = name
    question = "What is the description of this item? ('Look' action)"
    description = useful.AskWithConfirm(header, question, screen)

    # Pickable?
    screen.clear()
    question = "Can the user pick this item up?"
    screen = useful.PrintHeader(header, screen, 0, 0)
    screen = useful.PrintText(question, screen, 4, 0)
    if useful.ShowMenu(MENU_CONFIRM, screen, 6, 0)[0] == "YES":
        isPickable = True

        # Droppable?
        screen.clear()
        question = "Can the user drop this item from his inventory?"
        screen = useful.PrintHeader(header, screen, 0, 0)
        screen = useful.PrintText(question, screen, 4, 0)
        if useful.ShowMenu(MENU_CONFIRM, screen, 6, 0)[0] == "YES":
            isDroppable = True
        else:
            isDroppable = False
    else:
        isPickable = False
        isDroppable = False

    newItem = itemsquirrel.ItemSquirrel(name, description, isPickable,
                                        isDroppable)

    if fromRoomFlag == 0:
        # which room does it belong to?
        screen.clear()
        question = "What is the initial placement of this item??"
        screen = useful.PrintHeader(header, screen, 0, 0)
        screen = useful.PrintText(question, screen, 4, 0)

        RoomMenu = [(r.name) for r in GAME.rooms]
        RoomMenu.append("Player Inventory")
        RoomMenu.append("NOWHERE")
        roomselected = useful.ShowMenu(RoomMenu, screen, 6, 0)

        # if it belongs to no room, we simply append it to the item list
        if roomselected[0] == "NOWHERE":
            GAME.AddItem(newItem)

        elif roomselected[0] == "Player Inventory":
            GAME.AddItem(newItem)
            GAME.PlaceItem(len(GAME.items) - 1, -2)

        # if it belongs to a specific room, then we set the location attribute of this item
        else:
            # roomselected[1] is actual room index in GAME.rooms
            GAME.AddItem(newItem)
            GAME.PlaceItem(len(GAME.items) - 1, roomselected[1])

    else:
        GAME.AddItem(newItem)
Esempio n. 9
0
def EditRoom(GAME, screen):
    while True:
        screen.clear()

        # Chose Room to Edit
        header = GAME.name
        question = "Which room would you like to edit?"
        screen = useful.PrintHeader(header, screen, 0, 0)
        screen = useful.PrintText(question, screen, 4, 0)

        RoomMenu = [(r.name) for r in GAME.rooms]
        RoomMenu.append("BACK")
        roomselected = useful.ShowMenu(RoomMenu, screen, 6, 0)

        if roomselected[0] == "BACK":
            break

        else:
            while True:
                screen.clear()
                room = GAME.rooms[roomselected[1]]
                header = room.name
                name = "Name: " + room.name
                description = "Description: " + room.description

                currentLine = 0
                screen = useful.PrintHeader(header, screen, currentLine, 0)
                screen = useful.PrintText(name, screen, currentLine + 4, 0)
                screen = useful.PrintText(description, screen, currentLine + 5,
                                          0)

                # Print items in the room
                screen = useful.PrintText("Items in this room:", screen,
                                          currentLine + 7, 0)
                itemNameList = []
                currentLine = 8
                for itemIndex in room.items:
                    itemNameList.append(GAME.items[itemIndex].name)
                    screen = useful.PrintText(GAME.items[itemIndex].name,
                                              screen, currentLine, 0)
                    currentLine += 1

                currentLine += 1

                # Print connections of the room
                screen = useful.PrintText("Connections:", screen, currentLine,
                                          0)
                currentLine += 1
                connectionList = []
                for i in range(len(MENU_DIRS) -
                               1):  # -1 because MENU_DIRS has -- BACK --
                    if room.connections[i] < 0:
                        connectionList.append(MENU_DIRS[i] + ":")
                    else:
                        connectionList.append(
                            MENU_DIRS[i] + ": " +
                            GAME.rooms[room.connections[i]].name)
                    screen = useful.PrintText(connectionList[i], screen,
                                              currentLine, 0)
                    currentLine += 1

                question = "What would you like to change?"
                screen = useful.PrintText(question, screen, currentLine + 1, 0)
                selection = useful.ShowMenu(MENU_EDIT_ROOM, screen,
                                            currentLine + 3, 0)

                # EDIT NAME #
                if selection[0] == MENU_EDIT_ROOM[0]:
                    screen.clear()
                    question = "What is the new name of this room?"
                    name = useful.AskWithConfirm(header, question, screen)
                    GAME.rooms[roomselected[
                        1]].name = name  # roomselected[1] is the index
                    header = name  # of the selected room
                # END EDIT NAME #

                # EDIT DESCRIPTION #
                elif selection[0] == MENU_EDIT_ROOM[1]:
                    screen.clear()
                    question = "What is the new description of this room?"
                    description = useful.AskWithConfirm(
                        header, question, screen)
                    GAME.rooms[roomselected[1]].description = description
                # END EDIT DESCRIPTION #

                # EDIT CONNECTIONS #
                elif selection[0] == MENU_EDIT_ROOM[2]:
                    screen.clear()
                    question = "Which direction do you want to edit?"
                    screen = useful.PrintHeader(header, screen, 0, 0)
                    screen = useful.PrintText(question, screen, 4, 0)

                    connectionEditList = connectionList
                    connectionEditList.append("-- BACK --")
                    selectedDirection = useful.ShowMenu(
                        connectionEditList, screen, 6, 0)
                    if selectedDirection[0] == "-- BACK --":
                        continue
                    else:
                        EditRoomConnection(GAME, screen, roomselected[1],
                                           selectedDirection[1])

                # END EDIT CONNECTIONS #

                # EDIT ITEMS #
                elif selection[0] == MENU_EDIT_ROOM[3]:
                    while True:
                        screen.clear()
                        question = "What do you want to do?"
                        screen = useful.PrintHeader(header, screen, 0, 0)
                        screen = useful.PrintText(question, screen, 4, 0)
                        selectedOption = useful.ShowMenu(
                            MENU_ROOM_ITEM, screen, 6, 0)

                        if selectedOption[0] == "ADD item to this Room":
                            AddItemToRoom(GAME, screen, roomselected[1])

                        elif selectedOption[0] == "REMOVE item from this Room":
                            RemoveItemFromRoom(GAME, screen, roomselected[1])

                        elif selectedOption[0] == "BACK":
                            break

                # END EDIT ITEMS #

                elif selection[0] == "BACK":
                    break