From 829029d57eafe2b704401e6a5e2dfd2e88980852 Mon Sep 17 00:00:00 2001
From: Ahmed Yusuf <yusufa7@cardiff.ac.uk>
Date: Mon, 24 Oct 2022 19:28:08 +0100
Subject: [PATCH] some more additions to game

---
 Group_game/game.py    | 86 +++++++++++++++++++++++++++----------------
 Group_game/level_1.py |  3 +-
 Group_game/level_2.py | 10 +++--
 Group_game/map.py     | 60 +++++++++++++++++++-----------
 Group_game/player.py  |  5 +--
 5 files changed, 103 insertions(+), 61 deletions(-)

diff --git a/Group_game/game.py b/Group_game/game.py
index 5e90a43..ea7bfbf 100644
--- a/Group_game/game.py
+++ b/Group_game/game.py
@@ -5,12 +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
 
-
 def list_of_items(items):
     new_list = ""
     for number in range(len(items)):
@@ -48,7 +48,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):
@@ -56,6 +56,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:
@@ -72,8 +73,11 @@ 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 == location_door:
-        print("UNLOCK DOOR to attempt to unlock the escape door")
+    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:
@@ -81,11 +85,12 @@ 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")
-
     print("What do you want to do?")
 
 
@@ -129,30 +134,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")
 
@@ -213,10 +228,17 @@ def execute_command(command):
         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:
@@ -239,11 +261,13 @@ 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 start_time
     start_time = datetime.now()
     # Main game loop
diff --git a/Group_game/level_1.py b/Group_game/level_1.py
index 86fc5e6..50d98ca 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
index c97782d..59df259 100644
--- a/Group_game/level_2.py
+++ b/Group_game/level_2.py
@@ -3,11 +3,11 @@ from operator import truediv
 from items import *
 from player import *
 from map import *
-from game import time_taken
+from gameparser import *
 
-def drink_wine():
-    counter = 0 
-    more = True
+
+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.')
@@ -33,3 +33,5 @@ def hangman():
 
 def open_closet():
     pass
+def use_battery_lock():
+    pass
\ No newline at end of file
diff --git a/Group_game/map.py b/Group_game/map.py
index 9d5eab9..07d50eb 100644
--- a/Group_game/map.py
+++ b/Group_game/map.py
@@ -8,7 +8,7 @@ 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": []
 }
@@ -49,26 +49,26 @@ 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": []
 }
@@ -77,43 +77,59 @@ location_winecellar = {
 
     "description": "(description needed)",
 
-    "exits": {},
+    "exits": {"south": "entrance"},
 
-    "items": {}
+    "items": []
 }
 location_storage = {
     "name": "Storage Room",
 
     "description": "(description needed)",
 
-    "exits": {},
+    "exits": {"north": "closet", "east": "entrance"},
 
-    "items": {}
+    "items": []
 }
 location_boileroom = {
     "name": "Boiler Room",
     
     "description": "(description needed)",
 
-    "exits": {},
+    "exits": {"north": "entrance"},
 
-    "items": {}
+    "items": []
 }
-
-level1 = {
+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
-
-}
-level2 = {
+    "office desk": Location_desk,
+    "door": location_door,
     "entrance": location_entrance,
     "wine cellar": location_winecellar,
     "storage room": location_storage,
-    "boiler room": location_boileroom
-
+    "boiler room": location_boileroom,
+    "trap door": trap_door,
+    "desk": desk,
+    "closet": closet
 }
-levels = {"level 1": level1, "level 2": level2}
+
diff --git a/Group_game/player.py b/Group_game/player.py
index 5ddb662..e234b6c 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"]
 
-- 
GitLab