Skip to content
Snippets Groups Projects
Commit f7efd5be authored by Ahmed Yusuf's avatar Ahmed Yusuf
Browse files

changes to lock and closet

parent 72848d68
No related branches found
No related tags found
No related merge requests found
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
from map import * from map import *
from player import * from player import *
from gameparser import * from gameparser import *
from hangman import *
from datetime import datetime from datetime import datetime
from items import * from items import *
from level_1 import * from level_1 import *
...@@ -56,12 +57,11 @@ def print_room(room): ...@@ -56,12 +57,11 @@ def print_room(room):
def exit_leads_to(exits, direction): def exit_leads_to(exits, direction):
time.sleep(0.1)
return locations[exits[direction]]["name"] return locations[exits[direction]]["name"]
def print_exit(direction, leads_to): def print_exit(direction, leads_to):
time.sleep(0.8) time.sleep(0.2)
print("GO " + direction.upper() + " to " + leads_to + ".") print("GO " + direction.upper() + " to " + leads_to + ".")
...@@ -75,57 +75,61 @@ def print_menu(exits, room_items, inv_items): ...@@ -75,57 +75,61 @@ def print_menu(exits, room_items, inv_items):
print_exit(direction, exit_leads_to(exits, direction)) print_exit(direction, exit_leads_to(exits, direction))
for items in room_items: for items in room_items:
if items["pick-up"]: if items["pick-up"]:
time.sleep(0.8) time.sleep(0.2)
print("TAKE", items["id"], "to take", items["name"] + ".") print("TAKE", items["id"], "to take", items["name"] + ".")
for items in inv_items: for items in inv_items:
time.sleep(0.8) time.sleep(0.2)
print("DROP", items["id"], "to drop", items["name"] + ".") print("DROP", items["id"], "to drop", items["name"] + ".")
for items in inv_items: for items in inv_items:
if "open" in items: if "open" in items:
if not items["open"]: if not items["open"]:
time.sleep(0.8) time.sleep(0.2)
print("OPEN", items["id"], "to open", items["name"] + ".") print("OPEN", items["id"], "to open", items["name"] + ".")
if not location_boileroom["valve_open"]: if not location_boileroom["valve_open"]:
time.sleep(0.8) time.sleep(0.2)
print("CHECK TIMER to check the time remaining") print("CHECK TIMER to check the time remaining")
if current_room == location_door and location_door["locked"]: if current_room == location_door and location_door["locked"]:
if current_level == "level 1": if current_level == "level 1":
time.sleep(0.8) time.sleep(0.2)
print("UNLOCK DOOR to attempt to unlock the escape door") print("UNLOCK DOOR to attempt to unlock the escape door")
else: else:
time.sleep(0.8) time.sleep(0.2)
print("GO UPSTAIRS to go back to level 1") print("GO UPSTAIRS to go back to level 1")
if item_note in inv_items: if item_note in inv_items:
time.sleep(0.8) time.sleep(0.2)
print("READ NOTE to read the hidden note") print("READ NOTE to read the hidden note")
if item_safe in room_items: if item_safe in room_items:
if not item_safe["open"]: if not item_safe["open"]:
time.sleep(0.8) time.sleep(0.2)
print("OPEN SAFE to attempt to open the safe") print("OPEN SAFE to attempt to open the safe")
else: else:
"You've already opened the safe" "You've already opened the safe"
if item_batteries in inventory and unpowered_torch in inventory: if item_batteries in inventory and unpowered_torch in inventory:
time.sleep(0.8) time.sleep(0.2)
print("USE BATTERIES for TORCH to place the batteries in the torch") print("USE BATTERIES for TORCH to place the batteries in the torch")
# if item_batteries in inventory and item_lock in inventory: # if item_batteries in inventory and item_lock in inventory:
# print("USE BATTERIES for LOCK to place the batteries in the torch") # print("USE BATTERIES for LOCK to place the batteries in the torch")
if (powered_torch in inv_items) or (unpowered_torch in inv_items): if (powered_torch in inv_items) or (unpowered_torch in inv_items):
time.sleep(0.8) time.sleep(0.2)
print("USE TORCH to use your torch") print("USE TORCH to use your torch")
if current_room == location_boileroom and location_boileroom["valve_open"]: if current_room == location_boileroom and location_boileroom["valve_open"]:
time.sleep(0.8) time.sleep(0.2)
print("CLOSE valve to close the valve and stop the leakage") print("CLOSE valve to close the valve and stop the leakage")
if location_boileroom["valve_open"]: if location_boileroom["valve_open"]:
time.sleep(0.8) time.sleep(0.2)
print("CHECK GAS TIMER to see how long left before the room fills with gas") print("CHECK GAS TIMER to see how long left before the room fills with gas")
if item_winebottle in inventory: if item_winebottle in inventory:
time.sleep(0.8) time.sleep(0.2)
print('DRINK WINE to have a glass of wine') print('DRINK WINE to have a glass of wine')
if powered_torch in inventory: if powered_torch in inventory:
print("REMOVE BATTERIES from TORCH to remove the batteries from the torch") print("REMOVE BATTERIES from TORCH to remove the batteries from the torch")
time.sleep(0.8) time.sleep(0.2)
time.sleep(0.8) if current_room==desk:
print("PLAY HANGMAN to play a game of hangman")
time.sleep(0.2)
if current_room==trap_door and item_batteries in inventory:
print("USE BATTERIES for LOCK to place the batteries in the electrical lock")
print("What do you want to do?") print("What do you want to do?")
...@@ -135,18 +139,20 @@ def is_valid_exit(exits, chosen_exit): ...@@ -135,18 +139,20 @@ def is_valid_exit(exits, chosen_exit):
def execute_go(direction): def execute_go(direction):
time.sleep(0.1)
global current_room global current_room
if is_valid_exit(current_room["exits"], direction): 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 if new_room == closet and not closet["open"]:
return current_room print("The closet is locked, complete an activity to open the closet")
time.sleep(0.8)
else:
current_room = new_room
return current_room
else: else:
print("you cannot go there") print("you cannot go there")
time.sleep(0.8)
def execute_take(item_id): def execute_take(item_id):
time.sleep(0.1)
found = False found = False
for items in current_room["items"]: for items in current_room["items"]:
if item_id == items["id"]: if item_id == items["id"]:
...@@ -156,8 +162,10 @@ def execute_take(item_id): ...@@ -156,8 +162,10 @@ def execute_take(item_id):
current_room["items"].remove(items) current_room["items"].remove(items)
else: else:
print("Your inventory is full, Drop an item to free some space.") print("Your inventory is full, Drop an item to free some space.")
time.sleep(0.8)
if not found: if not found:
print("You cannot take that.") print("You cannot take that.")
time.sleep(0.4)
def execute_drop(item_id): def execute_drop(item_id):
...@@ -297,8 +305,6 @@ def execute_command(command): ...@@ -297,8 +305,6 @@ def execute_command(command):
if len(command) > 2: if len(command) > 2:
if command[2] == "torch": if command[2] == "torch":
remove_battery_torch() remove_battery_torch()
elif command[2] == "lock":
"" # remove_battery_lock()
else: else:
print("remove batteries from what?") print("remove batteries from what?")
elif command[1] == "torch": elif command[1] == "torch":
...@@ -310,6 +316,11 @@ def execute_command(command): ...@@ -310,6 +316,11 @@ def execute_command(command):
drink_wine() drink_wine()
else: else:
print("drink what?") print("drink what?")
elif command[0] == "play":
if command[1] == "hangman":
hangman("closet")
else:
print("drink what?")
else: else:
print("This makes no sense.") print("This makes no sense.")
...@@ -358,7 +369,8 @@ def main(): ...@@ -358,7 +369,8 @@ def main():
if current_room == location_boileroom: if current_room == location_boileroom:
if not location_boileroom["entered"]: if not location_boileroom["entered"]:
location_boileroom["valve_open"] = True location_boileroom["valve_open"] = True
print("(gas warning message 2 min)") print("You immediately start hearing a high pitched hissing sound. You look around and see a valve needs to be closed. If only you had come sort of utensil to shut it.")
print("You've got 2 minutes to close the valve before the room fills with gas")
time.sleep(5) time.sleep(5)
gas_starttime = datetime.now() gas_starttime = datetime.now()
location_boileroom["entered"] = True location_boileroom["entered"] = True
......
Python 3.10.8 (tags/v3.10.8:aaaf517, Oct 11 2022, 16:50:30) [MSC v.1933 64 bit (AMD64)] on win32 import time
Type "help", "copyright", "credits" or "license()" for more information. from collections import Counter
>>> from map import *
... from collections import Counter
... def hangman(word):
... word = "closet" print('Guess the word! HINT: you may find this thing in your bedroom')
... print("You will have 15 chances to guess the word. ")
... def hangman(word):
... print('Guess the word! HINT: you may find this thing in your bedroom') for i in word:
... print("You will have 15 chances to guess the word. ") # For printing the empty spaces for letters of the word
... print('_', end=' ')
... for i in word: print()
... # For printing the empty spaces for letters of the word
... print('_', end = ' ') playing = True
... print() # list for storing the letters guessed by the player
... letterGuessed = ''
... playing = True chances = 15
... # list for storing the letters guessed by the player correct = 0
... letterGuessed = '' flag = 0
... chances = 15 try:
... correct = 0 while (chances != 0) and flag == 0: # flag is updated when the word is correctly guessed
... flag = 0 print()
... try: print("you have " + str(chances) + " guesses left!")
... while (chances != 0) and flag == 0: #flag is updated when the word is correctly guessed chances -= 1
... print()
... print("you have "+str(chances)+" guesses left!") try:
... chances -= 1 guess = str(input('Enter a letter to guess: '))
... except:
... try: print('Enter only a letter!')
... guess = str(input('Enter a letter to guess: ')) continue
... except: # Validation of the guess
... print('Enter only a letter!') if not guess.isalpha():
... continue print('Enter only a LETTER')
... continue
... # Validation of the guess
... if not guess.isalpha():
... print('Enter only a LETTER')
... continue
elif len(guess) > 1: elif len(guess) > 1:
print('Enter only a SINGLE letter') print('Enter only a SINGLE letter')
continue continue
elif guess in letterGuessed: elif guess in letterGuessed:
print('You have already guessed that letter') print('You have already guessed that letter')
continue continue
# If letter is guessed correctly # If letter is guessed correctly
if guess in word: if guess in word:
k = word.count(guess) #k stores the number of times the guessed letter occurs in the word k = word.count(guess) # k stores the number of times the guessed letter occurs in the word
for _ in range(k): for _ in range(k):
letterGuessed += guess # The guess letter is added as many times as it occurs letterGuessed += guess # The guess letter is added as many times as it occurs
# Print the word # Print the word
for char in word: for char in word:
if char in letterGuessed and (Counter(letterGuessed) != Counter(word)): if char in letterGuessed and (Counter(letterGuessed) != Counter(word)):
print(char, end = ' ') print(char, end=' ')
correct += 1 correct += 1
# If user has guessed all the letters # If user has guessed all the letters
elif (Counter(letterGuessed) == Counter(word)): # Once the correct word is guessed fully, elif (Counter(letterGuessed) == Counter(word)): # Once the correct word is guessed fully,
# the game ends, even if chances remain # the game ends, even if chances remain
print("The word is: ", end=' ') print("The word is: ", end=' ')
print(word) print(word)
flag = 1 flag = 1
print('Congratulations, You won!') print('Congratulations, You won!')
break # To break out of the for loop print()
break # To break out of the while loop time.sleep(1)
print("You hear a strange click sound from the closet in the storage room")
closet["open"] = True
break # To break out of the for loop
break # To break out of the while loop
else: else:
print('_', end = ' ') print('_', end=' ')
# If user has used all of his chances # If user has used all of his chances
if chances <= 0 and (Counter(letterGuessed) != Counter(word)): if chances <= 0 and (Counter(letterGuessed) != Counter(word)):
print() print()
print('You lost! Try again..') print('You lost! Try again..')
print('The word was {}'.format(word)) print('The word was {}'.format(word))
except KeyboardInterrupt: except KeyboardInterrupt:
print() print()
print('Bye! Try again.') print('Bye! Try again.')
......
...@@ -79,4 +79,22 @@ item_winebottle = { ...@@ -79,4 +79,22 @@ item_winebottle = {
"pick-up": True, "pick-up": True,
}
key_card = {
"id": "keycard",
"name": "a key card",
"description": "()",
"pick-up": True,
}
item_lock = {
"id": "lock",
"name": "an electric lock",
"pick-up": False,
"batteries": False
} }
\ No newline at end of file
import time
from items import * from items import *
from player import * from player import *
from map import * from map import *
...@@ -6,10 +8,12 @@ from map import * ...@@ -6,10 +8,12 @@ from map import *
def open_diary(room_items): def open_diary(room_items):
if item_diary in inventory: if item_diary in inventory:
print("You opened the diary and found a hidden note.") print("You opened the diary and found a hidden note.")
time.sleep(0.8)
room_items.append(item_note) room_items.append(item_note)
item_diary.update({"open": True}) item_diary.update({"open": True})
else: else:
print("You cannot open that.") print("You cannot open that.")
time.sleep(0.8)
def open_safe(room_items): def open_safe(room_items):
...@@ -19,17 +23,23 @@ def open_safe(room_items): ...@@ -19,17 +23,23 @@ def open_safe(room_items):
if passcode == "042": if passcode == "042":
print("THE PASSCODE WAS CORRECT!") print("THE PASSCODE WAS CORRECT!")
print("inside the safe you found a pair of batteries") print("inside the safe you found a pair of batteries")
time.sleep(0.8)
room_items.append(item_batteries) room_items.append(item_batteries)
item_safe.update({"open": True}) item_safe.update({"open": True})
else: else:
print("you try the code", passcode, "but the safe wouldn't open") print("you try the code", passcode, "but the safe wouldn't open")
print("TRY AGAIN") print("TRY AGAIN")
time.sleep(0.8)
def remove_battery_torch(): def remove_battery_torch():
if powered_torch in inventory: if powered_torch in inventory:
inventory.remove(powered_torch) inventory.remove(powered_torch)
inventory.append(item_batteries) inventory.append(item_batteries)
inventory.append(unpowered_torch) inventory.append(unpowered_torch)
print("You removed the batteries from the torch") print("You removed the batteries from the torch")
time.sleep(0.5)
def use_battery_torch(): def use_battery_torch():
if item_batteries in inventory: if item_batteries in inventory:
...@@ -38,6 +48,8 @@ def use_battery_torch(): ...@@ -38,6 +48,8 @@ def use_battery_torch():
inventory.remove(unpowered_torch) inventory.remove(unpowered_torch)
inventory.append(powered_torch) inventory.append(powered_torch)
print("You placed the batteries in the torch.") print("You placed the batteries in the torch.")
time.sleep(0.5)
def use_torch(room): def use_torch(room):
if powered_torch in inventory: if powered_torch in inventory:
...@@ -45,9 +57,11 @@ def use_torch(room): ...@@ -45,9 +57,11 @@ def use_torch(room):
room["items"].append(item_key) room["items"].append(item_key)
else: else:
print("There is no use for the torch in this room") print("There is no use for the torch in this room")
time.sleep(0.8)
elif unpowered_torch in inventory: elif unpowered_torch in inventory:
print("You flick the on/off button but the torch wouldn't turn on, " print("You flick the on/off button but the torch wouldn't turn on, "
"(try finding some batteries to power the torch)") "(try finding some batteries to power the torch)")
time.sleep(0.8)
else: else:
print("you cannot do that") print("you cannot do that")
...@@ -60,5 +74,6 @@ def read_note(): ...@@ -60,5 +74,6 @@ def read_note():
print("206 >> two numbers are correct but wrong placed") print("206 >> two numbers are correct but wrong placed")
print("738 >> nothing is correct") print("738 >> nothing is correct")
print("870 >> one number is correct but wrong placed") print("870 >> one number is correct but wrong placed")
time.sleep(5)
else: else:
print("There is no note to read") print("There is no note to read")
...@@ -58,16 +58,26 @@ def close_valve(): ...@@ -58,16 +58,26 @@ def close_valve():
print("You need a screwdriver to close the valve") print("You need a screwdriver to close the valve")
def open_trapdoor(): def open_trapdoor():
pass if current_room == trap_door:
if item_lock["batteries"]:
if item_keycard in inventory:
trap_door["open"] = True
else:
print("You need a key card to open the lock")
else:
print("The electrical lock requires batteries to open")
def play_hangman():
pass
def open_closet():
pass
def use_battery_lock(): def use_battery_lock():
pass if current_room == trap_door:
if item_batteries in inventory:
item_lock["batteries"] = True
inventory.remove(item_batteries)
print("You placed the batteries in the electrical lock")
time.sleep(1)
def gas_timer(timer): def gas_timer(timer):
current_time = datetime.now() current_time = datetime.now()
time_taken = current_time - timer time_taken = current_time - timer
......
...@@ -112,13 +112,14 @@ trap_door = { ...@@ -112,13 +112,14 @@ trap_door = {
"name": "trap door", "name": "trap door",
"description": "The trap door is locked! There is an electrocated lock, you could use your key again but there is no guarantee it would work and there is no power in this lock. ", "description": "The trap door is locked! There is an electrocated lock, you could use your key again but there is no guarantee it would work and there is no power in this lock. ",
"exits": {"west": "entrance"}, "exits": {"west": "entrance"},
"items": [] "open": False
"items": [item_lock]
} }
closet = { closet = {
"name": "closet", "name": "closet",
"description": "You are amazed that the door is now mysteriously open, wondering how it happened you inspect it further. The closet is wooden with dusty shelves and old literary texts. There is a key card here as well.", "description": "You are amazed that the door is now mysteriously open, wondering how it happened you inspect it further. The closet is wooden with dusty shelves and old literary texts. There is a key card here as well.",
"exits": {}, "exits": {},
"items": [] "items": [key_card]
} }
locations = { locations = {
"fireplace": location_Fireplace, "fireplace": location_Fireplace,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment