diff --git a/Group_game/game.py b/Group_game/game.py index e2659f3ce1d9d639eddd0acc447d08a9abca7e1b..68f020cee85ae5e096d0d3ae8654ca7bf89101f0 100644 --- a/Group_game/game.py +++ b/Group_game/game.py @@ -6,6 +6,8 @@ from datetime import datetime from items import * from level_1 import * start_time = "" +global current_room +global current_level def list_of_items(items): @@ -69,7 +71,7 @@ def print_menu(exits, room_items, inv_items): if not items["open"]: print("OPEN", items["id"], "to open", items["name"] + ".") print("CHECK TIMER to check the time remaining") - if current_room == current_level["door"]: + if current_room == location_door: print("UNLOCK DOOR to attempt to unlock the escape door") if item_note in inv_items: print("READ NOTE to read the hidden note") @@ -78,6 +80,11 @@ def print_menu(exits, room_items, inv_items): print("OPEN SAFE to attempt to open the safe") else: "You've already opened the safe" + if item_batteries in inventory: + print("USE BATTERIES to use the batteries") + if (powered_torch in inv_items) or (unpowered_torch in inv_items): + print("USE TORCH to use your torch") + print("What do you want to do?") @@ -119,19 +126,34 @@ def execute_drop(item_id): print("You cannot drop that.") - def unlock_door(): + global current_level + global current_room + global start_time if current_room["name"] == "Escape door": if item_key in inventory: - print("WELL DONE! You've escaped",current_level) + current_time = datetime.now() + time_taken = (current_time - start_time).total_seconds() + minutes = time_taken // 60 + seconds = time_taken % 60 + while True: + print("WELL DONE! You've escaped LEVEL 1 in a time of", round(minutes), "minutes and", round(seconds), "seconds") + print("type CONTINUE to begin the next level") + response = input() + print(normalise_input(response)[0]) + if normalise_input(response)[0] == "continue": + current_level = levels["level 2"] + current_room = current_level["entrance"] + start_time = datetime.now() + print("(introduction to level 2)") + break + else: print("You need a key to open the door") else: print("There is no door to open") - - def check_timer(): current_time = datetime.now() time_taken = current_time - start_time @@ -187,15 +209,15 @@ def execute_command(command): unlock_door() else: print("unlock what?") - # elif command[0] == "use": - # if command[1] == "battery": - # use_battery() - # if command[1] == "battery": - # use_torch() - # else: - # print("use what?") - # else: - # print("This makes no sense.") + elif command[0] == "use": + if command[1] == "batteries": + use_battery() + if command[1] == "torch": + use_torch(current_room) + else: + print("use what?") + else: + print("This makes no sense.") def menu(exits, room_items, inv_items): diff --git a/Group_game/items.py b/Group_game/items.py index 742664a145eb3a19fbb57b5c7b31862974900595..61ceec0208e8c7bdb67fcf9648b65daac86e483e 100644 --- a/Group_game/items.py +++ b/Group_game/items.py @@ -1,6 +1,6 @@ -item_battery = { - "id": "battery", +item_batteries = { + "id": "batteries", "name": "a pair of batteries", @@ -35,7 +35,7 @@ item_key = { "pick-up": True } -item_torch = { +unpowered_torch = { "id": "torch", "name": "a torch", @@ -43,6 +43,15 @@ item_torch = { "description": "(no description)", "pick-up": True } +powered_torch = { + "id": "powered torch", + + "name": "a torch with batteries", + + "description": "(no description)", + "pick-up": True + +} item_diary = { "id": "diary", diff --git a/Group_game/level_1.py b/Group_game/level_1.py index aab0d040dfbce3d8031f8f9aa87181ac597d4f3f..7cdd48bb9a9e66be399f5af06d0f88a039bb0f7d 100644 --- a/Group_game/level_1.py +++ b/Group_game/level_1.py @@ -1,6 +1,6 @@ from items import * from player import * - +from map import * def open_diary(): if item_diary in inventory: @@ -19,15 +19,33 @@ def open_safe(): if passcode == "042": print("THE PASSCODE WAS CORRECT!") print("inside the safe you found a pair of batteries") - inventory.append(item_battery) + inventory.append(item_batteries) item_safe.update({"open": True}) def use_battery(): - if item_battery in inventory: - if item_torch in inventory: - inventory.remove(item_battery) - inventory.remove(item_torch) + if item_batteries in inventory: + if unpowered_torch in inventory: + inventory.remove(item_batteries) + inventory.remove(unpowered_torch) + inventory.append(powered_torch) + else: + print("You have no items in your inventory that uses a battery") + + +def use_torch(room): + if powered_torch in inventory: + print(room) + if room == location_dark_corner: + print("true") + room["items"].append(item_key) + else: + print("There is no use for the torch in this room") + elif unpowered_torch in inventory: + print("You flick the on/off button but the torch wouldn't turn on, " + "(try finding some batteries to power the torch)") + else: + print("you cannot do that") def read_note(): diff --git a/Group_game/map.py b/Group_game/map.py index 261de5cffab3fff106cd7c397d8028855b863475..d39fd99227f8969c98a049e7194fce5c6c154df6 100644 --- a/Group_game/map.py +++ b/Group_game/map.py @@ -16,11 +16,12 @@ Good luck you have 20 minutes!""", location_Fireplace = { "name": "The Fireplace", - "description": "The fireplace is made of brick and has a red brick chimney. The brick is very old and worn, but still strong enough to support the weight of a person. ", + "description": "The fireplace is made of brick and has a red brick chimney." + "The brick is very old and worn, but still strong enough to support the weight of a person. ", - "exits": {"north": "centre", "east": "Dark corner"}, + "exits": {"north": "centre", "east": "dark corner"}, - "items": [item_torch] + "items": [unpowered_torch] } location_bookshelf = { @@ -38,7 +39,7 @@ Location_desk = { "description": "I see a desk with what looks to be a safe underneath it. I open the drawer, and sure enough, there is a small safe.", - "exits": {"west": "door", "south- west": "centre", "west" : "dark corner"}, + "exits": {"west": "door", "south-west": "centre", "south" : "dark corner"}, "items": [item_safe] } @@ -62,7 +63,15 @@ location_door = { "items": [] } +location_entrance = { + "name": "level 2 Stairs", + "description": "(description needed)", + + "exits": {}, + + "items": [] +} level1 = { "fireplace": location_Fireplace, @@ -73,5 +82,5 @@ level1 = { "door": location_door } -level2 = {} +level2 = {"entrance": location_entrance} levels = {"level 1": level1, "level 2": level2}