예제 #1
0
def test_take_and_drop_mat_and_leaflet():
    adventure = Adventure()
    adventure.take(['mat'])
    adventure.open(['mailbox'])
    adventure.take(['leaflet'])
    assert(adventure.drop(['mat', 'leaflet']) == 'mat: Dropped.\nleaflet: Dropped.')
    assert(adventure.list_inventory([]) == 'You are empty handed.')
    assert(any((item.name == 'mat' or item.name == item.name == 'leaflet' for item in adventure.current_room.items)))
예제 #2
0
def test_open_mailbox_and_look():
    adventure = Adventure()
    adventure.open(['mailbox'])
    assert(adventure.look([]) == """**West of House**
This is an open field west of a white house, with a boarded front door.
There is a small mailbox here.
The mailbox contains:
- A small leaflet.
A rubber mat saying 'Welcome to Zork!' lies by the door.""")
예제 #3
0
def test_take_and_drop_leaflet_and_mat_then_look():
    adventure = Adventure()
    adventure.open(['mailbox'])
    adventure.take(['leaflet', 'mat'])
    adventure.drop(['mat', 'leaflet'])
    assert(adventure.look([]) == """**West of House**
This is an open field west of a white house, with a boarded front door.
There is a small mailbox, a welcome mat, and a small leaflet here.""")
예제 #4
0
def test_take_mat_go_north_then_drop_mat():
    adventure = Adventure()
    adventure.take(['mat'])
    adventure.go_north([])
    adventure.drop(['mat'])
    assert (adventure.current_room.description == """**North of House**
You are facing the north side of a white house.  There is no door here, and all the windows are barred.
There is a welcome mat here.""")
예제 #5
0
def test_house_open_mailbox_read_leaflet():
    adv = Adventure()
    adv.open(['mailbox'])
    assert(adv.examine(['leaflet']) == '(Taking the leaflet first)\n'
                                       '    ZORK is a game of adventure, danger, and low cunning.  In it you will '
                                       'explore some of the most amazing territory ever seen by mortal man.  Hardened '
                                       'adventurers have run screaming from the terrors contained within!\n\n'
                                       '    In ZORK the intrepid explorer delves into the forgotten secrets of a lost '
                                       'labyrinth deep in the bowels of the earth, searching for vast treasures long '
                                       'hidden from prying eyes, treasures guarded by fearsome monsters and diabolical '
                                       'traps!\n\n'
                                       '    No PDP-10 should be without one!\n\n'
                                       '    ZORK was created at the MIT Laboratory for Computer Science, by Tim '
                                       'Anderson, Marc Blank, Bruce Daniels, and Dave Lebling.  It was inspired by the '
                                       'ADVENTURE game of Crowther and Woods, and the long tradition of fantasy and '
                                       'science fiction adventure.  ZORK was originally written in MDL (alias MUDDLE). '
                                       'The current version was written by Brandon Corfman.')
예제 #6
0
def index(session: hug.directives.session):
    """main index / page"""
    starting_text = "resuming..."
    if not session:
        starting_text = markdown.markdown(
            Adventure(output_strategy=MarkdownPassthru()).current_room.description
        )
    # TODO: actually set the session_id if there is one
    return get_template("index.html").render(session_id="", starting_text=starting_text)
예제 #7
0
def index(session: hug.directives.session):
    """main index / page"""
    starting_text = ""
    if not session:
        starting_text = markdown2html(
            Adventure(
                output_strategy=MarkdownPassthru()).current_room.description)
    else:
        starting_text = f"Resuming (session: {session.get('session_id')})"
    return get_template("index.html").render(session_id="",
                                             starting_text=starting_text)
예제 #8
0
def adventure_api(session: hug.directives.session, input_data: str):
    """the /api endpoint for XMLHttpRequest handling"""
    adventure = Adventure(output_strategy=MarkdownPassthru())
    if session and session.get("save_data"):
        adventure.admin_load(base64.b64decode(session["save_data"].encode()))
    _output = markdown.markdown(adventure.execute(input_data.split()))
    session["save_data"] = base64.b64encode(adventure.admin_save()).decode("ascii")
    return {"input": input_data, "output": _output}
예제 #9
0
def test_take_inaccessible_object():
    adventure = Adventure()
    assert (adventure.execute(['take', 'leaflet']) == "I don't see any leaflet here.")
예제 #10
0
def test_take_unknown_object():
    adventure = Adventure()
    assert (adventure.execute(['take', 'printer']) == "I don't see any printer here.")
예제 #11
0
def test_drop_known_but_not_held_object():
    adventure = Adventure()
    assert (adventure.execute(['drop', 'mat']) == "The mat is already here.")
예제 #12
0
def test_unknown_verb():
    adventure = Adventure()
    assert(adventure.execute(['watch', 'mat']) == "I don't understand how to watch something.")
예제 #13
0
def test_house_open_mailbox():
    adventure = Adventure()
    assert(adventure.open(['mailbox']) == "You open the mailbox, revealing a small leaflet.")
예제 #14
0
def test_take_leaflet_and_mat():
    adventure = Adventure()
    adventure.open(['mailbox'])
    assert(adventure.take(['leaflet', 'mat']) == """leaflet: Taken.
mat: Taken.""")
예제 #15
0
def test_go_north_then_west_of_house():
    adventure = Adventure()
    adventure.go_north([])
    adventure.go_west([])
    assert(adventure.current_room.title == "West of House")
예제 #16
0
def test_go_north_of_house():
    adventure = Adventure()
    assert(adventure.go_north([]) == """**North of House**
You are facing the north side of a white house.  There is no door here, and all the windows are barred.""")
    assert(adventure.current_room.title == "North of House")
예제 #17
0
def test_take_and_drop_mat():
    adventure = Adventure()
    adventure.take(['mat'])
    assert(adventure.drop(['mat']) == 'Dropped.')
    assert(adventure.list_inventory([]) == 'You are empty handed.')
    assert(any((item.name == 'mat' for item in adventure.current_room.items)))
예제 #18
0
def test_inventory_after_taking_mat_and_leaflet():
    adventure = Adventure()
    adventure.open(['mailbox'])
    adventure.take(['mat', 'leaflet'])
    assert(adventure.list_inventory([]) == """You are holding a welcome mat and a small leaflet.""")
예제 #19
0
def test_close_already_closed_mailbox():
    adventure = Adventure()
    assert(adventure.close(['mailbox']) == "That's already closed.")
예제 #20
0
def test_empty_mailbox():
    adventure = Adventure()
    adventure.open(['mailbox'])
    adventure.take(['leaflet'])
    adventure.close(['mailbox'])
    assert (adventure.open(['mailbox']) == """You open the mailbox.""")
예제 #21
0
def test_house_read_leaflet_check_inventory():
    adventure = Adventure()
    adventure.open(['mailbox'])
    adventure.examine(['leaflet'])
    assert(adventure.list_inventory([]) == 'You are holding a small leaflet.')
예제 #22
0
def test_open_opened_mailbox():
    adventure = Adventure()
    adventure.open(['mailbox'])
    assert(adventure.open(['mailbox']) == "The mailbox is already open.")
예제 #23
0
import argparse
from adventure.app import Adventure
from adventure.output import MarkdownToHTML
try:
    from adventure.util import BUILD_NUMBER  # this is appended to the util module during GitHub Actions deployment
except ImportError:
    BUILD_NUMBER = ""  # default to an empty string if we can't find a build number

VERSION = '0.3'

if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('--version', action='store_true')
    parser.add_argument('--web', action='store_true')
    args = parser.parse_args()
    if args.version:
        print('ZorkDemo ' + VERSION + ' Build ' + BUILD_NUMBER)
    else:
        if args.web:
            output_strategy = MarkdownToHTML()
            adventure = Adventure(output_strategy)
            adventure.start_page()
        else:
            adventure = Adventure()
            adventure.start_console()