From b291a3fcf6c007ad1600368ae3407b912f367fba Mon Sep 17 00:00:00 2001
From: Ahmed Yusuf <yusufa7@cardiff.ac.uk>
Date: Tue, 25 Oct 2022 12:39:05 +0100
Subject: [PATCH] boiler room gas leakage works

---
 Group_game/game.py    | 36 +++++++++++++++++++++++++++++++++---
 Group_game/items.py   |  8 ++++++++
 Group_game/level_2.py | 23 ++++++++++++++++++++---
 Group_game/map.py     |  6 ++++--
 4 files changed, 65 insertions(+), 8 deletions(-)

diff --git a/Group_game/game.py b/Group_game/game.py
index ea7bfbf..c778eb3 100644
--- a/Group_game/game.py
+++ b/Group_game/game.py
@@ -10,6 +10,7 @@ from level_2 import *
 start_time = ""
 global current_room
 global current_level
+gas_starttime = ""
 
 def list_of_items(items):
     new_list = ""
@@ -72,7 +73,8 @@ 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 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")
@@ -91,6 +93,10 @@ def print_menu(exits, room_items, inv_items):
     #     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?")
 
 
@@ -218,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":
@@ -227,6 +237,11 @@ 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 len(command) > 1:
             if command[1] == "batteries":
@@ -268,6 +283,7 @@ def move(exits, direction):
 def main():
     global current_level
     current_level = "level 1"
+    global gas_starttime
     global start_time
     start_time = datetime.now()
     # Main game loop
@@ -278,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 34d68bb..a9e0f19 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_2.py b/Group_game/level_2.py
index 59df259..31462d4 100644
--- a/Group_game/level_2.py
+++ b/Group_game/level_2.py
@@ -3,6 +3,7 @@ from operator import truediv
 from items import *
 from player import *
 from map import *
+from datetime import datetime
 from gameparser import *
 
 
@@ -23,15 +24,31 @@ def drink_wine(time_taken):
             False
 
 def close_valve():
-    pass
+    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 hangman():
+def play_hangman():
     pass
 
 def open_closet():
     pass
 def use_battery_lock():
-    pass
\ No newline at end of file
+    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 07d50eb..2cef007 100644
--- a/Group_game/map.py
+++ b/Group_game/map.py
@@ -10,7 +10,7 @@ Good luck you have 20 minutes!""",
 
     "exits": {"south": "fireplace", "west": "bookshelf", "north": "door", "north-east": "office desk", "south-east": "dark corner"},
 
-    "items": []
+    "items": [item_screwdriver]
 }
 
 location_Fireplace = {
@@ -97,7 +97,9 @@ location_boileroom = {
 
     "exits": {"north": "entrance"},
 
-    "items": []
+    "items": [],
+    "valve_open": False,
+    "entered": False
 }
 desk = {
     "name": "desk",
-- 
GitLab