adding the create and describe functions to the game

fruitual
mb 1 year ago
parent 21f634ef7a
commit 67ef82eec6

@ -107,12 +107,14 @@ Hi there! This is the multiplayer, text-based version of the Experimental Publis
# send the player back the list of possible commands
mud.send_message(id, "Commands:")
mud.send_message(id, " say <message> - Says something out loud, "
mud.send_message(id, " say <message> - Says something out loud, "
+ "e.g. 'say Hello'")
mud.send_message(id, " look - Examines the "
mud.send_message(id, " look - Examines the "
+ "surroundings, e.g. 'look'")
mud.send_message(id, " go <exit> - Moves through the exit "
mud.send_message(id, " go <exit> - Moves through the exit "
+ "specified, e.g. 'go outside'")
mud.send_message(id, " create <exit> <new roomname> - Creates a new exit and room")
mud.send_message(id, " describe <description> - Change the description of the current room")
# 'say' command
elif command == "say":
@ -225,6 +227,90 @@ Hi there! This is the multiplayer, text-based version of the Experimental Publis
elif command == "made":
mud.send_message(id, "You made a ")
# 'create' command
elif command == "create":
# store the exit or room that will be created
parameters = params.lower()
parameters_list = parameters.split()
print("[INSPECT] parameters: ", parameters_list)
if len(parameters_list) >= 1:
# store the new exit name
new_exit = parameters_list[0]
print("[INSPECT] new exit: ", new_exit)
else:
new_exit = None
if len(parameters_list) >= 2:
# store the new room name
new_room = " ".join(parameters_list[1:])
print("[INSPECT] new room: ", new_room)
else:
new_exit = None
# store the player's current room
current_room_name = players[id]["room"]
print("[INSPECT] current room: ", current_room_name)
# store information about the player's current room
current_room = rooms[players[id]["room"]]
print("[INSPECT] current room dict: ", current_room)
# if both the new exit and new room are given
if new_exit is not None and new_room is not None:
# send player a message when the exit already exists
if new_exit in current_room["exits"]:
mud.send_message(id, "This exit already exist.")
# create new room
else:
print(f"[INSPECT] Make new room: { new_room }, in the direction: { new_exit }")
# add the new exit to the current room
rooms[current_room_name]["exits"][new_exit] = new_room
# store information about the new room
rooms[new_room] = {}
rooms[new_room]["description"] = ""
rooms[new_room]["exits"] = {}
# add the opposite exit direction to the exits of the new room
if new_exit == "west":
exit_to_add = "east"
elif new_exit == "east":
exit_to_add = "east"
if new_exit == "north":
exit_to_add = "south"
elif new_exit == "south":
exit_to_add = "north"
# store this exit to the new room
rooms[new_room]["exits"][exit_to_add] = current_room_name
# announce the new room to the player
mud.send_message(id, f"A new room is added: { new_room } (in the { new_exit })")
# invite the player to write a description for the room
mud.send_message(id, "The room is not described yet. When you are in the room, you can use 'describe' to add a description. For example: 'describe This is the XML! It smells a bit muffy here.'")
# warn the player when the "create" command is not used in the right way
else:
mud.send_message(id, f"Sorry you cannot create a new room in that way. Try: 'create direction roomname'")
# 'describe' command
elif command == "describe":
# store the exit or room that will be created
description = params.lower()
print("[INSPECT] description: ", description)
# store the player's current room
current_room_name = players[id]["room"]
print("[INSPECT] current room: ", current_room_name)
rooms[new_room]["description"] = description
# some other, unrecognised command
else:
# send back an 'unknown command' message

Loading…
Cancel
Save