diff --git a/Group_game/game.py b/Group_game/game.py index 37971b80c1cd3dc0ce9b252320c7c12faf928ace..7034af0ab15a6fdaf93da03b5f79e9fcd31753fd 100644 --- a/Group_game/game.py +++ b/Group_game/game.py @@ -1,9 +1,10 @@ #!/usr/bin/python3 - -from map import rooms +from map import * from player import * -from items import * from gameparser import * +from datetime import datetime +from items import * +start_time = "" def list_of_items(items): @@ -43,7 +44,7 @@ def print_room(room): def exit_leads_to(exits, direction): - return rooms[exits[direction]]["name"] + return level1[exits[direction]]["name"] def print_exit(direction, leads_to): @@ -61,6 +62,13 @@ def print_menu(exits, room_items, inv_items): for items in inv_items: print("DROP", items["id"], "to drop", items["name"] + ".") + for items in inv_items: + if "open" in items: + print("OPEN", items["id"], "to open", items["name"] + ".") + print("CHECK TIMER to check the time remaining") + if current_room == current_level["door"]: + print("UNLOCK DOOR to attempt to unlock the escape door") + # # COMPLETE ME! # @@ -75,7 +83,7 @@ def is_valid_exit(exits, chosen_exit): def execute_go(direction): global current_room if is_valid_exit(current_room["exits"], direction): - new_room = move(current_room["exits"],direction) + new_room = move(current_room["exits"], direction) current_room = new_room return current_room else: @@ -91,9 +99,9 @@ def execute_take(item_id): found = True if not found: + print(current_room["items"]) print("You cannot take that.") - def execute_drop(item_id): found = False @@ -106,7 +114,29 @@ def execute_drop(item_id): if not found: print("You cannot drop that.") - + +def execute_open(item_id): + found = False + x = "" + for items in inventory: + if items["id"] == item_id: + print("You opened the", item_id, "and found", items["open"]["name"]) + x = items["open"] + found = True + if found: + inventory.append(x) + else: + print("You cannot open that.") + + +def check_timer(): + current_time = datetime.now() + time_taken = current_time - start_time + time_left = 1200 - time_taken.total_seconds() + minutes = time_left//60 + seconds = time_left%60 + print("You have", round(minutes), "minutes and", round(seconds), "seconds") + def execute_command(command): if 0 == len(command): @@ -130,12 +160,30 @@ def execute_command(command): else: print("Drop what?") + # elif command[0] == "read": + # if len(command) > 1: + # execute_read(command[1]) + # else: + # print("read what?") + + elif command[0] == "open": + if len(command) > 1: + execute_open(command[1]) + else: + print("check what?") + + elif command[0] == "check": + if command[1] == "timer": + check_timer() + else: + print("Check what?") else: print("This makes no sense.") def menu(exits, room_items, inv_items): # Display menu + print_menu(exits, room_items, inv_items) # Read player's input @@ -149,14 +197,21 @@ def menu(exits, room_items, inv_items): def move(exits, direction): # Next room to go to - return rooms[exits[direction]] + return level1[exits[direction]] # This is the entry point of our program def main(): - + global start_time + start_time = datetime.now() # Main game loop while True: + current_time = datetime.now() + time_taken = current_time - start_time + time_left = 1200 - time_taken.total_seconds() + if time_left < 0: + print("Oh no! You ran out of time!") + break # Display game status (room description, inventory etc.) print_room(current_room) print_inventory_items(inventory) @@ -173,4 +228,3 @@ def main(): # See https://docs.python.org/3.4/library/__main__.html for explanation if __name__ == "__main__": main() - diff --git a/Group_game/gameparser.py b/Group_game/gameparser.py index 3c9e0a712b9394b625a13ab38b71f18880e06478..cdbcd92912f947f9c6c7b0c6c523ca0feb5f8ce5 100644 --- a/Group_game/gameparser.py +++ b/Group_game/gameparser.py @@ -11,6 +11,8 @@ skip_words = ['a', 'about', 'all', 'an', 'another', 'any', 'around', 'at', 'towards', 'until', 'us', 'want', 'we', 'what', 'when', 'why', 'wish', 'with', 'would'] +punctuation = ["!", ".", "/", "'", "`", "@", "^", "*", ",", "?"] + def filter_words(words, skip_words): new_list = [] @@ -29,7 +31,7 @@ def filter_words(words, skip_words): def remove_punct(text): no_punct = "" for char in text: - if not (char in string.punctuation): + if not (char in punctuation): no_punct = no_punct + char return no_punct diff --git a/Group_game/items.py b/Group_game/items.py index 3a9e0f2f83e2051c683b5902c2079c9a619a0698..6b1b17b847706dd99d5ea8437c16754f993ea8a7 100644 --- a/Group_game/items.py +++ b/Group_game/items.py @@ -1,51 +1,51 @@ -item_id = { - "id": "id", - "name": "id card", - "description": - """You new shiny student ID card. Expires 1 June 2017. -You wonder why they have printed a suicide hotline number on it?...""" -} - -item_laptop = { - "id": "laptop", +item_safe = { + "id": "safe", - "name": "laptop", + "name": "a secure safe", - "description": - "It has seen better days. At least it has a WiFi card!" + "description": "(no description)" } -item_money = { - "id": "money", +item_battery = { + "id": "battery", - "name": "money", + "name": "a pair of batteries", - "description": - "This wad of cash is barely enough to pay your tuition fees." + "description": "(no description)" } -item_biscuits = { - "id": "biscuits", +item_note = { + "id": "note", - "name": "a pack of biscuits", + "name": "a hidden note", - "description": "A pack of biscuits." + "description": "(no description)" + # "read": read_note() } -item_pen = { - "id": "pen", +item_key = { + "id": "key", - "name": "a pen", + "name": "a key", - "description": "A basic ballpoint pen." + "description": "(no description)." } -item_handbook = { - "id": "handbook", +item_torch = { + "id": "torch", - "name": "a student handbook", + "name": "a torch", - "description": "This student handbook explains everything. Seriously." + "description": "(no description)" } + +item_diary = { + "id": "diary", + + "name": "a personal diary", + + "description": "(no description)", + "open": item_note +} \ No newline at end of file diff --git a/Group_game/map.py b/Group_game/map.py index 0b67e922bf4cf6a6079fd73a0fba67c1df514c0c..f2ee264d02ac96cc6f6e741b423f7a4db4a44f2c 100644 --- a/Group_game/map.py +++ b/Group_game/map.py @@ -1,81 +1,74 @@ from items import * -room_reception = { - "name": "Reception", +location_centre = { + "name": "Centre of the room", - "description": - """You are in a maze of twisty little passages, all alike. -Next to you is the School of Computer Science and -Informatics reception. The receptionist, Matt Strangis, -seems to be playing an old school text-based adventure -game on his computer. There are corridors leading to the -south and east. The exit is to the west.""", + "description": "(description for centre spawn needed)", - "exits": {"south": "Admins", "east": "Tutor", "west": "Parking"}, + "exits": {"south": "fireplace", "west": "bookshelf", "north": "door", "north-east": "desk", "south-east": "dark corner"}, - "items": [item_biscuits, item_handbook] + "items": [item_torch] } -room_admins = { - "name": "MJ and Simon's room", +location_Fireplace = { + "name": "The Fireplace", - "description": - """You are leaning agains the door of the systems managers' -room. Inside you notice Matt "MJ" John and Simon Jones. They -ignore you. To the north is the reception.""", + "description": "(description for fireplace needed)", - "exits": {"north": "Reception"}, + "exits": {"north": "centre", "east": "Dark corner"}, - "items": [] + "items": [item_safe] } -room_tutor = { - "name": "your personal tutor's office", +location_bookshelf = { + "name": "Bookshelf", - "description": - """You are in your personal tutor's office. He intently -stares at his huge monitor, ignoring you completely. -On the desk you notice a cup of coffee and an empty -pack of biscuits. The reception is to the west.""", + "description": "(description for bookshelf needed)", - "exits": {"west": "Reception"}, + "exits": {"north-east": "door", "east": "centre"}, - "items": [] + "items": [item_diary] +} + +Location_desk = { + "name": "The office desk", + + "description": "(description for desk needed)", + + "exits": {"west": "door", "south- west": "centre", "west" : "dark corner"}, + + "items": [item_battery] } -room_parking = { - "name": "the parking lot", +location_dark_corner = { + "name": "a dark corner of the room", - "description": - """You are standing in the Queen's Buildings parking lot. -You can go south to the COMSC reception, or east to the -general office.""", + "description": "(description for dark corner needed)", - "exits": {"east": "Office", "south": "Reception"}, + "exits": {"west": "fireplace", "north": "desk", "north-west": "centre"}, "items": [] } +location_door = { + "name": "Escape door", -room_office = { - "name": "the general office", + "description": "(description for escape door needed) ", - "description": - """You are standing next to the cashier's till at -30-36 Newport Road. The cashier looks at you with hope -in their eyes. If you go west you can return to the -Queen's Buildings.""", + "exits": {"south": "centre"}, - "exits": {"west": "Parking"}, + "items": [] - "items": [item_pen] } +level1 = { + "fireplace": location_Fireplace, + "dark corner": location_dark_corner, + "centre": location_centre, + "bookshelf": location_bookshelf, + "desk": Location_desk, + "door": location_door -rooms = { - "Reception": room_reception, - "Admins": room_admins, - "Tutor": room_tutor, - "Parking": room_parking, - "Office": room_office } +level2 = {} +levels = {"level 1": level1, "level 2": level2} diff --git a/Group_game/player.py b/Group_game/player.py index d2bc13055a08f9c2abc22cec3358f19409d7a659..5ddb6624359a3d6065d7ba342c374a04dc27a903 100644 --- a/Group_game/player.py +++ b/Group_game/player.py @@ -1,7 +1,9 @@ from items import * -from map import rooms +from map import levels -inventory = [item_id, item_laptop, item_money] +inventory = [] + +# Start game at the centre +current_level = levels["level 1"] +current_room = current_level["centre"] -# Start game at the reception -current_room = rooms["Reception"]