Bryan Tong Text RPG
Bryan Tong Text RPG
import cmd
import textwrap
import sys
import os
import time
import random
screen_width = 100
class player:
def __init__(self):
self.name = ''
self.job = ''
self.hp = 0
self.mp = 0
self.status_effects = []
self.location = 'b2'
self.game_over = False
myPlayer = player()
def title_screen_selections():
option = input("> ")
if option.lower() == ("play"):
setup_game() # place holder until written
elif option.lower() == ("help"):
help_menu()
elif option.lower() == ("quit"):
sys.exit()
while option.lower() not in ['play', 'help', 'quit']:
print("INVALID COMMAND")
option = input("> ")
if option.lower() == ("play"):
setup_game() # place holder until written
elif option.lower() == ("help"):
help_menu()
elif option.lower() == ("quit"):
sys.exit()
def title_screen():
os.system('clear')
print('+++++++++++++++++++++++++++')
print('+ Welcome to the Text RPG +')
print('+++++++++++++++++++++++++++')
print(' - Play - ')
print(' - Help - ')
print(' - Quit - ')
print('+++++++++++++++++++++++++++')
title_screen_selections()
def help_menu():
print('+++++++++++++++++++++++++++')
print('+ Welcome to the Text RPG +')
print('+++++++++++++++++++++++++++')
print(' Use directions to move ')
print(' - Know commands - ')
print(' - Use Look to examine - ')
print('+++++++++++++++++++++++++++')
title_screen_selections()
ZONENAME = ''
DESCRIPTION = 'description'
EXAMINATION = 'examine'
SOLVED = False
UP = 'up', 'north'
DOWN = 'down', 'south'
LEFT = 'left', 'west'
RIGHT = 'right','east'
zonemap = {
'a1' : {
ZONENAME: "Town Market",
DESCRIPTION: 'The market is bustling with many stalls!',
EXAMINATION: 'You see three different stores, maybe try to SHOP?',
SOLVED: False,
UP: '',
DOWN: 'b1',
LEFT: '',
RIGHT: 'a2'
},
'a2' : {
ZONENAME: "Town Entrance",
DESCRIPTION: 'The guard nods at you while you come into the Town',
EXAMINATION: 'There appears to be a few scraps of METAL',
SOLVED: False,
UP: '',
DOWN: 'b2',
LEFT: 'a1',
RIGHT: 'a3'
},
'a3' : {
ZONENAME: "Town Square",
DESCRIPTION: 'The town square is filled with people. There is some sort of
commotion',
EXAMINATION: 'Looks like someone is about to be hanged.',
SOLVED: False,
UP: '',
DOWN: '',
LEFT: 'a2',
RIGHT: 'a4'
},
'a4' : {
ZONENAME: "Town Hall",
DESCRIPTION: 'The town hall is empty, the execution is about to begin',
EXAMINATION: 'There is a SWORD outside of the armory!',
SOLVED: False,
UP: '',
DOWN: 'b4',
LEFT: 'a3',
RIGHT: ''
},
'b1' : {
ZONENAME: "Alleyway",
DESCRIPTION: 'The old alleyway is rather dark',
EXAMINATION: 'There is something GLOWING on the ground under some trash',
SOLVED: False,
UP: 'a1',
DOWN: '',
LEFT: '',
RIGHT: 'b2'
},
'b2' : {
ZONENAME: "Home",
DESCRIPTION: 'This is your home',
EXAMINATION: 'Your home looks rather... depressing',
SOLVED: False,
UP: 'a2',
DOWN: 'c2',
LEFT: 'b1',
RIGHT: 'b3'
}
}
def print_location():
print('\n' + ('#' * (4 + len(myPlayer.location))))
print('# ' + myPlayer.location.upper() + ' #')
print('# ' + zonemap[myPlayer.location][DESCRIPTION] + ' #')
print('\n' + ('#' * (4 + len(myPlayer.location))))
def prompt():
print("\n" + ("==============================="))
print("What will you do?")
action = input("> ")
acceptable_actions = ['move', 'go', 'travel', 'walk', 'quit', 'examine',
'look', 'interact', 'get']
while action.lower() not in acceptable_actions:
print("INVALID COMMAND")
action = input("> ")
if action.lower() == 'quit':
sys.exit()
elif action.lower() in ['move', 'go', 'travel', 'walk']:
player_move(action.lower())
elif action.lower() in ['examine', 'inspect', 'interact', 'look']:
player_examine(action.lower())
def player_move(myAction):
ask = "Where would you like to move to?\n"
dest = input(ask)
if dest in ['up', 'north']:
destination = zonemap[myPlayer.location][UP]
movement_handler(destination)
elif dest in ['left', 'west']:
destination = zonemap[myPlayer.location][LEFT]
movement_handler(destination)
elif dest in ['east', 'right']:
destination = zonemap[myPlayer.location][RIGHT]
movement_handler(destination)
elif dest in ['south', 'down']:
destination = zonemap[myPlayer.location][DOWN]
movement_handler(destination)
def movement_handler(destination):
print("\n" + "You have moved to the " + destination + ".")
myPlayer.location = destination
print_location()
def main_game_loop():
while myPlayer.game_over is False:
prompt()
# here handle if puzzles solved / boss defeated / etc #
def setup_game():
os.system('clear')
if myPlayer.job is 'warrior':
self.hp = 120
self.mp = 10
elif myPlayer.job is 'mage':
self.hp = 60
self.mp = 100
elif myPlayer.job is 'technician':
self.hp = 70
self.mp = 50
os.system('clear')
print("++++++++++++++++++++++++++")
print("+ Let's start now! +")
print("++++++++++++++++++++++++++")
main_game_loop()
title_screen()