I have done most of the work but currently having problems with my dictionary linking rooms and then the items within together. Line 21 (which begins with 'Main Fair ground': {'South':
) is too long and invalid. Below is the code I have done so far, I will be grateful for any help because I am new to Python and struggling a little bit.
# Sample function showing the goal of the game and move commands
def show_instructions():
# print a main menu and the commands
print("Killer Wolf Text Adventure Game")
print("Collect 6 items to win the game, or be eaten by the killer Wolf.")
print("Move commands: go South, go North, go East, go West")
print("Add to Inventory: get 'item name'")
def player_stat():
print("-" * 20)
print('You are in the {}'.format(currentRoom))
print("-" * 20)
def main():
pass
rooms = {
'Main Fair ground': {'South': 'Food stand', 'item' : '1LB of meat', 'North': 'Arcade', 'item' : 'real sword', 'East': 'Corn field', 'item' : 'wolf repellent', 'West': 'Candy shop', 'item' : 'candy'},
'Security': {'item': 'protective gear', 'East': 'Food stand'},
'Gift shop': {'item': 'map', 'West': 'Arcade'},
'Petting area': {'item': 'killer wolf', 'South': 'Corn field'} # villain
}
currentRoom = 'Main Fair ground'
player_move = ''
while currentRoom != 'Exit':
player_stat()
player_move = input('Enter your move:\n').lower()
if player_move in ['Exit', 'exit']:
currentRoom = 'Exit'
print('Play again soon')
continue
try:
currentRoom = rooms[currentRoom][player_move]
except Exception:
print("invalid move")
continue
if 'Petting' == currentRoom:
print("Kill the wolf")
The error message I get is:
File "wolf.py", line 41 continue ^ SyntaxError: 'continue' not properly in loop
Here is an example of a dictionary from a dragon text game, this is basically what I am doing so this is a great example.
#A dictionary linking a room to other rooms
#and linking one item for each room except the Start room (Great Hall) and the room containing the villain
rooms = {
'Great Hall' : { 'South' : 'Bedroom', 'North': 'Dungeon', 'East' : 'Kitchen', 'West' : 'Library' },
'Bedroom' : { 'North' : 'Great Hall', 'East' : 'Cellar', 'item' : 'Armor' },
'Cellar' : { 'West' : 'Bedroom', 'item' : 'Helmet' },
'Dining Room' : { 'South' : 'Kitchen', 'item' : 'Dragon' } #villain
}
The player should enter a command to either move between rooms or to get an item, if one exists, from a room. The gameplay loop should continue looping, allowing the player to move to different rooms and acquire items until the player has either won or lost the game. Remember that the player wins the game by retrieving all of the items before encountering the room with the villain. The player loses the game by moving to the room with the villain before collecting all of the items. Be sure to include output to the player for both possible scenarios: winning and losing the game.