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

changes made

parent f480b7c2
Branches
No related tags found
No related merge requests found
#!/usr/bin/python3
from map import rooms
from map import *
from player import *
from items import *
from gameparser import *
from datetime import datetime
from items import *
start_time = ""
def list_of_items(items):
......@@ -43,7 +44,7 @@ def print_room(room):
def exit_leads_to(exits, direction):
return rooms[exits[direction]]["name"]
return level1[exits[direction]]["name"]
def print_exit(direction, leads_to):
......@@ -61,6 +62,13 @@ def print_menu(exits, room_items, inv_items):
for items in inv_items:
print("DROP", items["id"], "to drop", items["name"] + ".")
for items in inv_items:
if "open" in items:
print("OPEN", items["id"], "to open", items["name"] + ".")
print("CHECK TIMER to check the time remaining")
if current_room == current_level["door"]:
print("UNLOCK DOOR to attempt to unlock the escape door")
#
# COMPLETE ME!
#
......@@ -75,7 +83,7 @@ def is_valid_exit(exits, chosen_exit):
def execute_go(direction):
global current_room
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
return current_room
else:
......@@ -91,9 +99,9 @@ def execute_take(item_id):
found = True
if not found:
print(current_room["items"])
print("You cannot take that.")
def execute_drop(item_id):
found = False
......@@ -106,7 +114,29 @@ def execute_drop(item_id):
if not found:
print("You cannot drop that.")
def execute_open(item_id):
found = False
x = ""
for items in inventory:
if items["id"] == item_id:
print("You opened the", item_id, "and found", items["open"]["name"])
x = items["open"]
found = True
if found:
inventory.append(x)
else:
print("You cannot open that.")
def check_timer():
current_time = datetime.now()
time_taken = current_time - start_time
time_left = 1200 - time_taken.total_seconds()
minutes = time_left//60
seconds = time_left%60
print("You have", round(minutes), "minutes and", round(seconds), "seconds")
def execute_command(command):
if 0 == len(command):
......@@ -130,12 +160,30 @@ def execute_command(command):
else:
print("Drop what?")
# elif command[0] == "read":
# if len(command) > 1:
# execute_read(command[1])
# else:
# print("read what?")
elif command[0] == "open":
if len(command) > 1:
execute_open(command[1])
else:
print("check what?")
elif command[0] == "check":
if command[1] == "timer":
check_timer()
else:
print("Check what?")
else:
print("This makes no sense.")
def menu(exits, room_items, inv_items):
# Display menu
print_menu(exits, room_items, inv_items)
# Read player's input
......@@ -149,14 +197,21 @@ def menu(exits, room_items, inv_items):
def move(exits, direction):
# Next room to go to
return rooms[exits[direction]]
return level1[exits[direction]]
# This is the entry point of our program
def main():
global start_time
start_time = datetime.now()
# Main game loop
while True:
current_time = datetime.now()
time_taken = current_time - start_time
time_left = 1200 - time_taken.total_seconds()
if time_left < 0:
print("Oh no! You ran out of time!")
break
# Display game status (room description, inventory etc.)
print_room(current_room)
print_inventory_items(inventory)
......@@ -173,4 +228,3 @@ def main():
# See https://docs.python.org/3.4/library/__main__.html for explanation
if __name__ == "__main__":
main()
......@@ -11,6 +11,8 @@ skip_words = ['a', 'about', 'all', 'an', 'another', 'any', 'around', 'at',
'towards', 'until', 'us', 'want', 'we', 'what', 'when', 'why',
'wish', 'with', 'would']
punctuation = ["!", ".", "/", "'", "`", "@", "^", "*", ",", "?"]
def filter_words(words, skip_words):
new_list = []
......@@ -29,7 +31,7 @@ def filter_words(words, skip_words):
def remove_punct(text):
no_punct = ""
for char in text:
if not (char in string.punctuation):
if not (char in punctuation):
no_punct = no_punct + char
return no_punct
......
item_id = {
"id": "id",
"name": "id card",
"description":
"""You new shiny student ID card. Expires 1 June 2017.
You wonder why they have printed a suicide hotline number on it?..."""
}
item_laptop = {
"id": "laptop",
item_safe = {
"id": "safe",
"name": "laptop",
"name": "a secure safe",
"description":
"It has seen better days. At least it has a WiFi card!"
"description": "(no description)"
}
item_money = {
"id": "money",
item_battery = {
"id": "battery",
"name": "money",
"name": "a pair of batteries",
"description":
"This wad of cash is barely enough to pay your tuition fees."
"description": "(no description)"
}
item_biscuits = {
"id": "biscuits",
item_note = {
"id": "note",
"name": "a pack of biscuits",
"name": "a hidden note",
"description": "A pack of biscuits."
"description": "(no description)"
# "read": read_note()
}
item_pen = {
"id": "pen",
item_key = {
"id": "key",
"name": "a pen",
"name": "a key",
"description": "A basic ballpoint pen."
"description": "(no description)."
}
item_handbook = {
"id": "handbook",
item_torch = {
"id": "torch",
"name": "a student handbook",
"name": "a torch",
"description": "This student handbook explains everything. Seriously."
"description": "(no description)"
}
item_diary = {
"id": "diary",
"name": "a personal diary",
"description": "(no description)",
"open": item_note
}
\ No newline at end of file
from items import *
room_reception = {
"name": "Reception",
location_centre = {
"name": "Centre of the room",
"description":
"""You are in a maze of twisty little passages, all alike.
Next to you is the School of Computer Science and
Informatics reception. The receptionist, Matt Strangis,
seems to be playing an old school text-based adventure
game on his computer. There are corridors leading to the
south and east. The exit is to the west.""",
"description": "(description for centre spawn needed)",
"exits": {"south": "Admins", "east": "Tutor", "west": "Parking"},
"exits": {"south": "fireplace", "west": "bookshelf", "north": "door", "north-east": "desk", "south-east": "dark corner"},
"items": [item_biscuits, item_handbook]
"items": [item_torch]
}
room_admins = {
"name": "MJ and Simon's room",
location_Fireplace = {
"name": "The Fireplace",
"description":
"""You are leaning agains the door of the systems managers'
room. Inside you notice Matt "MJ" John and Simon Jones. They
ignore you. To the north is the reception.""",
"description": "(description for fireplace needed)",
"exits": {"north": "Reception"},
"exits": {"north": "centre", "east": "Dark corner"},
"items": []
"items": [item_safe]
}
room_tutor = {
"name": "your personal tutor's office",
location_bookshelf = {
"name": "Bookshelf",
"description":
"""You are in your personal tutor's office. He intently
stares at his huge monitor, ignoring you completely.
On the desk you notice a cup of coffee and an empty
pack of biscuits. The reception is to the west.""",
"description": "(description for bookshelf needed)",
"exits": {"west": "Reception"},
"exits": {"north-east": "door", "east": "centre"},
"items": []
"items": [item_diary]
}
Location_desk = {
"name": "The office desk",
"description": "(description for desk needed)",
"exits": {"west": "door", "south- west": "centre", "west" : "dark corner"},
"items": [item_battery]
}
room_parking = {
"name": "the parking lot",
location_dark_corner = {
"name": "a dark corner of the room",
"description":
"""You are standing in the Queen's Buildings parking lot.
You can go south to the COMSC reception, or east to the
general office.""",
"description": "(description for dark corner needed)",
"exits": {"east": "Office", "south": "Reception"},
"exits": {"west": "fireplace", "north": "desk", "north-west": "centre"},
"items": []
}
location_door = {
"name": "Escape door",
room_office = {
"name": "the general office",
"description": "(description for escape door needed) ",
"description":
"""You are standing next to the cashier's till at
30-36 Newport Road. The cashier looks at you with hope
in their eyes. If you go west you can return to the
Queen's Buildings.""",
"exits": {"south": "centre"},
"exits": {"west": "Parking"},
"items": []
"items": [item_pen]
}
level1 = {
"fireplace": location_Fireplace,
"dark corner": location_dark_corner,
"centre": location_centre,
"bookshelf": location_bookshelf,
"desk": Location_desk,
"door": location_door
rooms = {
"Reception": room_reception,
"Admins": room_admins,
"Tutor": room_tutor,
"Parking": room_parking,
"Office": room_office
}
level2 = {}
levels = {"level 1": level1, "level 2": level2}
from items import *
from map import rooms
from map import levels
inventory = [item_id, item_laptop, item_money]
inventory = []
# Start game at the centre
current_level = levels["level 1"]
current_room = current_level["centre"]
# Start game at the reception
current_room = rooms["Reception"]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment