BLOG MAKE UP 1:

I made a RPG


def showInstructions():
  print('''
RPG Game
========
Commands:
  go [direction]
  get [item]
''')

def showStatus():

  print('---------------------------')
  print('You are in the ' + currentRoom)

  print('Inventory : ' + str(inventory))

  if "item" in rooms[currentRoom]:
    print('You see a ' + rooms[currentRoom]['item'])
  print("---------------------------")


inventory = []

This is the code that prints the commands you can use and shows your status and inventory.

rooms = {

            'Hall' : {
                  'south' : 'Kitchen',
                  'east'  : 'Dining Room',
                  'item'  : 'key'
                },

            'Kitchen' : {
                  'north' : 'Hall',
                  'item'  : 'monster',
                },
            'Dining Room' : {
                  'west' : 'Hall',
                  'south': 'Garden',
                  'item' : 'potion',
                  'north' : 'Pantry',
               },
            'Garden' : {
                  'north' : 'Dining Room'
               },
            'Pantry' : {
                  'south' : 'Dining Room',
                  'item' : 'cookie',
            }
         }

These are the rooms you can go to

currentRoom = 'Hall'

showInstructions()


while True:

  showStatus()


  move = ''
  while move == '':
    move = input('>')

      
  move = move.lower().split(" ", 1)


  if move[0] == 'go':

    if move[1] in rooms[currentRoom]:

      currentRoom = rooms[currentRoom][move[1]]

    else:
        print('You can\'t go that way!')


  if move[0] == 'get' :

    if "item" in rooms[currentRoom] and move[1] in rooms[currentRoom]['item']:

      inventory.append(move[1])

      print(move[1] + ' got!')

      del rooms[currentRoom]['item']

    else:

      print('Can\'t get ' + move[1] + '!')
      

  if currentRoom == 'Garden' and 'key' in inventory and 'potion' in inventory:
    print('You escaped the house with the ultra rare key and magic potion... YOU WIN!')
    break


  elif 'item' in rooms[currentRoom] and 'monster' in rooms[currentRoom]['item']:
    print('A monster has got you... GAME OVER!')
    break
```

This is the code that lets you select rooms and also has code for if you lose or win.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top