118 lines
5.0 KiB
Python
118 lines
5.0 KiB
Python
from game import Game
|
|
|
|
def main():
|
|
game = Game()
|
|
game.load_game('data.json')
|
|
print()
|
|
|
|
while game.is_running:
|
|
print(f"[{game.current_room.name}] {game.current_room.enter_text}")
|
|
|
|
cmd = input("[Player] ")
|
|
cmd_parts = cmd.split(' ')
|
|
cmd_name = cmd_parts[0]
|
|
cmd_args = cmd_parts[1:] if len(cmd_parts) >= 2 else []
|
|
|
|
if cmd_name.lower().strip() == "quit":
|
|
game.is_running = False
|
|
|
|
if cmd_name.lower().strip() == "look":
|
|
if len(cmd_args) >= 1 and cmd_args[0].lower().strip() == "around":
|
|
door_count = len(game.current_room.doors)
|
|
interactables_count = len(game.current_room.interactables)
|
|
|
|
if door_count == 0:
|
|
print("[Player] In diesem Raum befinden sich keine Tueren.")
|
|
elif door_count == 1:
|
|
room = game.get_room(game.current_room.doors[0])
|
|
print(f"[Player] In diesem Raum befindet sich eine Tuer zu {room.name}.")
|
|
else:
|
|
rooms = []
|
|
for room_id in game.current_room.doors:
|
|
rooms.append(game.get_room(room_id).name)
|
|
|
|
print(f"[Player] In diesem Raum befinden sich {door_count} Tueren zu {', '.join(rooms)}.")
|
|
|
|
if interactables_count == 0:
|
|
print("[Player] Ansonsten kann ich hier nichts interessantes erkennen.")
|
|
else:
|
|
visible_interactables = []
|
|
for i in game.current_room.interactables:
|
|
if i.can_see():
|
|
visible_interactables.append(i.name)
|
|
|
|
if len(visible_interactables) == 1:
|
|
print(f"[Player] Da ist doch {visible_interactables[0]}?")
|
|
elif len(visible_interactables) == 2:
|
|
print(f"[Player] Hier finden sich so allerlei Dinge, zum Beispiel {visible_interactables[0]} und {visible_interactables[1]}.")
|
|
elif len(visible_interactables) > 1:
|
|
interactables_text = ", ".join(visible_interactables)
|
|
print(f"[Player] Hier finden sich so allerlei Dinge, zum Beispiel {interactables_text}.")
|
|
|
|
elif len(cmd_args) >= 2 and cmd_args[0].lower().strip() == "at":
|
|
at = cmd_args[1]
|
|
interactable = game.current_room.get_interactable(at)
|
|
|
|
if interactable is None:
|
|
print(f"[Player] Ich kann hier kein {at} erkennen")
|
|
else:
|
|
interactable.look()
|
|
|
|
else:
|
|
print(f"[Player] Wie soll ich denn dort hinschauen?")
|
|
|
|
if cmd_name.lower().strip() == "take":
|
|
if len(cmd_args) == 1:
|
|
what = cmd_args[0]
|
|
interactable = game.current_room.get_interactable(what)
|
|
|
|
if what is None:
|
|
print(f"[Player] Ich kann {what} nicht nehmen, da es nicht da ist!")
|
|
else:
|
|
interactable.take()
|
|
else:
|
|
print(f"[Player] Klar, ich nehme die Luft hier mal mit - sie wird mir sicher noch von Nutzen sein.")
|
|
|
|
if cmd_name.lower().strip() == "use":
|
|
if len(cmd_args) == 1:
|
|
what = cmd_args[0]
|
|
interactable = game.current_room.get_interactable(what)
|
|
|
|
if what is None:
|
|
print(f"[Player] Ich kann {what} nicht benutzen, da es nicht da ist!")
|
|
else:
|
|
interactable.use()
|
|
else:
|
|
print(f"[Player] Ich will mich nicht selbst benutzen ... das ist irgendwie falsch.")
|
|
|
|
if cmd_name.lower().strip() == "inspect":
|
|
if len(cmd_args) == 1:
|
|
item_name = cmd_args[0].lower().strip()
|
|
item = game.inventory.get_item(item_name)
|
|
|
|
if item is not None:
|
|
print(f"[Player] {item['name']}: {item['description']}")
|
|
else:
|
|
print(f"[Player] {item_name} habe ich nicht bei mir")
|
|
else:
|
|
print(f"[Player] Was soll ich mir denn anschauen?")
|
|
|
|
if cmd_name.lower().strip() == "enter":
|
|
if len(cmd_args) == 1:
|
|
room_id = cmd_args[0].lower().strip()
|
|
room = game.get_room(room_id)
|
|
|
|
if room is not None and room_id in game.current_room.doors:
|
|
print(f"[{game.current_room.name}] Du gehst durch die Tuer zum {room.name}")
|
|
game.current_room = room
|
|
else:
|
|
print(f"[Player] Hier gibt es keine Tuer dort hin ... vielleicht sollte ich ja einfach mit dem Kopf durch die Wand?")
|
|
else:
|
|
print(f"[Player] Wenn ich nicht weiss, wo ich rein soll, dann bleibe ich lieber einfach, wo ich bin.")
|
|
|
|
|
|
print()
|
|
print("Game has ended.")
|
|
|
|
if __name__ == '__main__':
|
|
main() |