diff --git a/Group_game/game.py b/Group_game/game.py index 76bbf92a6e6934df1513fc206dcfb2795e08c0f7..c778eb31d841894df6c69322a25335776b9732f7 100644 --- a/Group_game/game.py +++ b/Group_game/game.py @@ -5,10 +5,12 @@ from gameparser import * from datetime import datetime from items import * from level_1 import * +import time +from level_2 import * start_time = "" global current_room global current_level - +gas_starttime = "" def list_of_items(items): new_list = "" @@ -47,7 +49,7 @@ def print_room(room): def exit_leads_to(exits, direction): - return level1[exits[direction]]["name"] + return locations[exits[direction]]["name"] def print_exit(direction, leads_to): @@ -55,6 +57,7 @@ def print_exit(direction, leads_to): def print_menu(exits, room_items, inv_items): + global current_level print("You can:") # Iterate over available exits for direction in exits: @@ -70,9 +73,13 @@ def print_menu(exits, room_items, inv_items): if "open" in items: if not items["open"]: print("OPEN", items["id"], "to open", items["name"] + ".") - print("CHECK TIMER to check the time remaining") - if current_room == location_door: - print("UNLOCK DOOR to attempt to unlock the escape door") + if not location_boileroom["valve_open"]: + print("CHECK TIMER to check the time remaining") + if current_room == location_door and location_door["locked"]: + if current_level == "level 1": + print("UNLOCK DOOR to attempt to unlock the escape door") + else: + print("GO UPSTAIRS to go back to level 1") if item_note in inv_items: print("READ NOTE to read the hidden note") if item_safe in room_items: @@ -80,11 +87,16 @@ 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 item_batteries in inventory and unpowered_torch in inventory: + print("USE BATTERIES for TORCH to place the batteries in the torch") + # if item_batteries in inventory and item_lock in inventory: + # print("USE BATTERIES for LOCK to place the batteries in the torch") if (powered_torch in inv_items) or (unpowered_torch in inv_items): print("USE TORCH to use your torch") - + if current_room == location_boileroom and location_boileroom["valve_open"]: + print("CLOSE valve to close the valve and stop the leakage") + if location_boileroom["valve_open"]: + print("CHECK GAS TIMER to see how long left before the room fills with gas") print("What do you want to do?") @@ -128,30 +140,40 @@ def execute_drop(item_id): print("You cannot drop that.") +def time_taken(): + current_time = datetime.now() + time_taken = (current_time - start_time).total_seconds() + minutes = time_taken // 60 + seconds = time_taken % 60 + time = [round(minutes), round(seconds)] + return time + + def unlock_door(): - global current_level global current_room global start_time - if current_room["name"] == "Escape door": - if item_key in inventory: - 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 + minutes = time_taken()[0] + seconds = time_taken()[1] + if current_room["name"] == "level 1 Escape door": + if location_door["locked"]: + if item_key in inventory: + while True: + print("WELL DONE! You've escaped LEVEL 1 in a time of", minutes, "minutes and", seconds,"seconds") + print("type CONTINUE to begin the next level") + response = input() + if normalise_input(response)[0] == "continue": + location_door["locked"] = False + location_door["exits"].update({"upstairs": "entrance"}) + current_room = locations["entrance"] + start_time = datetime.now() + print("(introduction to level 2)") + time.sleep(5) + break + else: + print("You need a key to open the door") else: - print("You need a key to open the door") + print("Door is already unlocked") else: print("There is no door to open") @@ -202,8 +224,12 @@ def execute_command(command): print("open what?") elif command[0] == "check": - if command[1] == "timer": - check_timer() + if len(command) > 1: + if command[1] == "timer": + check_timer() + elif command[1] == "gas": + if location_boileroom["valve_open"]: + gas_timer(gas_starttime) else: print("Check what?") elif command[0] == "unlock": @@ -211,11 +237,23 @@ def execute_command(command): unlock_door() else: print("unlock what?") + elif command[0] == "close": + if command[1] == "valve": + close_valve() + else: + print("unlock what?") elif command[0] == "use": - if command[1] == "batteries": - use_battery() - if command[1] == "torch": - use_torch(current_room) + if len(command) > 1: + if command[1] == "batteries": + if len(command) > 2: + if command[2] == "torch": + use_battery_torch() + elif command[2] == "lock": + use_battery_lock() + else: + print("use batteries on what?") + elif command[1] == "torch": + use_torch(current_room) else: print("use what?") else: @@ -238,11 +276,14 @@ def menu(exits, room_items, inv_items): def move(exits, direction): # Next room to go to - return level1[exits[direction]] + return locations[exits[direction]] # This is the entry point of our program def main(): + global current_level + current_level = "level 1" + global gas_starttime global start_time start_time = datetime.now() # Main game loop @@ -253,7 +294,21 @@ def main(): if time_left < 0: print("Oh no! You ran out of time!") break + if location_boileroom["valve_open"]: + gastime = current_time - gas_starttime + gastime_left = 120 - gastime.total_seconds() + if gastime_left < 0: + print("OH NO! the floor was filled with gas and you died") + break # Display game status (room description, inventory etc.) + if current_room == location_boileroom: + if not location_boileroom["entered"]: + location_boileroom["valve_open"] = True + print("(gas warning message 2 min)") + time.sleep(5) + gas_starttime = datetime.now() + location_boileroom["entered"] = True + print_room(current_room) print_inventory_items(inventory) diff --git a/Group_game/items.py b/Group_game/items.py index 34d68bb2a4df34dee05bf678b0e054f583f0c9f7..a9e0f19e6e5399b1b6a378f498b2dad81ac9cedc 100644 --- a/Group_game/items.py +++ b/Group_game/items.py @@ -62,3 +62,11 @@ item_diary = { "pick-up": True, "open": False } +item_screwdriver = { + "id": "screwdriver", + + "name": "a screwdriver", + + "description": "()", + "pick-up": True +} \ No newline at end of file diff --git a/Group_game/level_1.py b/Group_game/level_1.py index 86fc5e60cb296f01bed3e415f3a706883907f52c..50d98ca3a73b74b53d8f3f5bfbcb5f84bf579a5b 100644 --- a/Group_game/level_1.py +++ b/Group_game/level_1.py @@ -26,12 +26,13 @@ def open_safe(room_items): print("TRY AGAIN") -def use_battery(): +def use_battery_torch(): if item_batteries in inventory: if unpowered_torch in inventory: inventory.remove(item_batteries) inventory.remove(unpowered_torch) inventory.append(powered_torch) + print("You placed the batteries in the torch.") else: print("You have no items in your inventory that uses a battery") diff --git a/Group_game/level_2.py b/Group_game/level_2.py new file mode 100644 index 0000000000000000000000000000000000000000..31462d4ab3bd545eb63a54bb0e3963371227c0d0 --- /dev/null +++ b/Group_game/level_2.py @@ -0,0 +1,54 @@ +from itertools import count +from operator import truediv +from items import * +from player import * +from map import * +from datetime import datetime +from gameparser import * + + +def drink_wine(time_taken): + counter = 0 + while True: + if counter < 2: + print('You drink a glass of the wine, but still cannot see the clue.') + print('Would you like to drink another glass?') + more = str(input()) + if more == 'yes': + counter += 1 + False + else: + print('You pass out from too much alchohol consumption.') + print('You wake up 5 minutes later on the floor.') + time_taken = time_taken - 360 + False + +def close_valve(): + if item_screwdriver in inventory: + if location_boileroom["valve_open"]: + location_boileroom["valve_open"] = False + print("Well done! You stopped the leakage") + else: + print("valve is closed") + else: + print("You need a screwdriver to close the valve") + + +def open_trapdoor(): + pass + +def play_hangman(): + pass + +def open_closet(): + pass +def use_battery_lock(): + pass +def gas_timer(timer): + current_time = datetime.now() + time_taken = current_time - timer + time_left = 120 - time_taken.total_seconds() + minutes = time_left//60 + seconds = time_left%60 + if time_left > 0: + print("You have", round(minutes), "minutes and", round(seconds), "seconds before the room fills with gas") \ No newline at end of file diff --git a/Group_game/map.py b/Group_game/map.py index d39fd99227f8969c98a049e7194fce5c6c154df6..2cef007ebc6b0fe9a1bc4e8785ef3147cc7421a7 100644 --- a/Group_game/map.py +++ b/Group_game/map.py @@ -8,9 +8,9 @@ from the WEST there is a Bookshelf. From NORTH of the room there is a locked doo You also see an office desk NORTH-EAST. There is a mysterious dark corner SOUTH-EAST of the room. Good luck you have 20 minutes!""", - "exits": {"south": "fireplace", "west": "bookshelf", "north": "door", "north-east": "desk", "south-east": "dark corner"}, + "exits": {"south": "fireplace", "west": "bookshelf", "north": "door", "north-east": "office desk", "south-east": "dark corner"}, - "items": [] + "items": [item_screwdriver] } location_Fireplace = { @@ -49,38 +49,89 @@ location_dark_corner = { "description": "The dark corner is filled with dust, cobwebs and old papers. There are also some old computers that no one uses anymore, probably the remnants of old computer science students", - "exits": {"west": "fireplace", "north": "desk", "north-west": "centre"}, + "exits": {"west": "fireplace", "north": "office desk", "north-west": "centre"}, "items": [] } location_door = { - "name": "Escape door", + "name": "level 1 Escape door", "description": "The door is locked, the keypad has a red light that’s blinking. You press the buttons randomly only to no avail. You press more random buttons and the red light blinks faster. :( ", "exits": {"south": "centre"}, - + "locked": True, "items": [] } location_entrance = { - "name": "level 2 Stairs", + "name": "level 2 Entrance", "description": "(description needed)", - "exits": {}, + "exits": {"north": "wine cellar", "west": "storage room", "south": "boiler room", "east": "trap door", "south-east": "desk", "downstairs": "door"}, + + "items": [] +} +location_winecellar = { + "name": "Wine Cellar", + + "description": "(description needed)", + + "exits": {"south": "entrance"}, + + "items": [] +} +location_storage = { + "name": "Storage Room", + + "description": "(description needed)", + + "exits": {"north": "closet", "east": "entrance"}, "items": [] } +location_boileroom = { + "name": "Boiler Room", + + "description": "(description needed)", + + "exits": {"north": "entrance"}, -level1 = { + "items": [], + "valve_open": False, + "entered": False +} +desk = { + "name": "desk", + "description": "(description needed)", + "exits": {"north-west": "entrance"}, + "items": [] +} +trap_door = { + "name": "trap door", + "description": "(description needed)", + "exits": {"west": "entrance"}, + "items": [] +} +closet = { + "name": "closet", + "description": "(description needed)", + "exits": {}, + "items": [] +} +locations = { "fireplace": location_Fireplace, "dark corner": location_dark_corner, "centre": location_centre, "bookshelf": location_bookshelf, - "desk": Location_desk, - "door": location_door - + "office desk": Location_desk, + "door": location_door, + "entrance": location_entrance, + "wine cellar": location_winecellar, + "storage room": location_storage, + "boiler room": location_boileroom, + "trap door": trap_door, + "desk": desk, + "closet": closet } -level2 = {"entrance": location_entrance} -levels = {"level 1": level1, "level 2": level2} + diff --git a/Group_game/player.py b/Group_game/player.py index 5ddb6624359a3d6065d7ba342c374a04dc27a903..e234b6c6bc15b6e8b34b6b171d6808712ce4809a 100644 --- a/Group_game/player.py +++ b/Group_game/player.py @@ -1,9 +1,8 @@ from items import * -from map import levels +from map import * inventory = [] # Start game at the centre -current_level = levels["level 1"] -current_room = current_level["centre"] +current_room = locations["centre"]