0% found this document useful (0 votes)
63 views6 pages

Bryan Tong Text RPG

This Python code defines a text-based role-playing game (RPG) with interactive elements like player setup, movement between locations on a map, and examining locations. The game initializes a Player class to store player attributes and starts the player at location 'b2' on the map. It includes functions for title screens, setting up the player name and class, printing the player's location, prompting player actions, handling movement, and examining areas. The main game loop runs until the player's game_over status is True.

Uploaded by

b
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views6 pages

Bryan Tong Text RPG

This Python code defines a text-based role-playing game (RPG) with interactive elements like player setup, movement between locations on a map, and examining locations. The game initializes a Player class to store player attributes and starts the player at location 'b2' on the map. It includes functions for title screens, setting up the player name and class, printing the player's location, prompting player actions, handling movement, and examining areas. The main game loop runs until the player's game_over status is True.

Uploaded by

b
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 6

### Python RPG from Bryan Tong ###

import cmd
import textwrap
import sys
import os
import time
import random

screen_width = 100

### Player Setup ###

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()

### TITLE SCREEN ###

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()

### Game Functionality ###

### MAP ###

ZONENAME = ''
DESCRIPTION = 'description'
EXAMINATION = 'examine'
SOLVED = False
UP = 'up', 'north'
DOWN = 'down', 'south'
LEFT = 'left', 'west'
RIGHT = 'right','east'

solved_places = {'a1': False, 'a2' : False, 'a3' : False, 'a4' : False,


'b1': False, 'b2' : False, 'b3' : False, 'b4' : False,
'c1': False, 'c2' : False, 'c3' : False, 'c4' : False,
'd1': False, 'd2' : False, 'd3' : False, 'd4' : False,
}

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'
}
}

### GAME INTERACTIVITY ###

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())

# HANDLING ALL MOVEMENT #

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 player_examine(action): # USE THIS TO MAKE ANYTHING W INTERACTION #


if zonemap[myPlayer.location][SOLVED]:
print("You have already solved this zone.")
else:
print("You can solve a puzzle here")

### GAME FUNCTIONALITY ###

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')

### Name Collecting ###

question1 = "Hello, what is your name?\n"


for character in question1:
sys.stdout.write(character)
sys.stdout.flush()
time.sleep(0.05)
player_name = input("> ")
myPlayer.name = player_name

### Class Handling ###

question2 = "Hello, what role do you want to play?\n"


question2added = "(You can be a warrior, mage, or technician)\n"
for character in question2:
sys.stdout.write(character)
sys.stdout.flush()
time.sleep(0.05)
for character in question2added:
sys.stdout.write(character)
sys.stdout.flush()
time.sleep(0.01)
player_job = input("> ")
valid_jobs = ['warrior', 'mage', 'technician']
if player_job.lower() in valid_jobs:
myPlayer.job = player_job
print("You are now a " + player_job + "!\n")
while player_job.lower() not in valid_jobs:
player_job = input("> ")
if player_job.lower() in valid_jobs:
myPlayer.job = player_job
print("You are now a " + player_job + "!\n")

### Class Stats Handling ###

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

### INTRODUCTION ###

question3 = "Welcome, " + player_name + " the " + player_job + ".\n"


for character in question1:
sys.stdout.write(character)
sys.stdout.flush()
time.sleep(0.05)

speech1 = "Welcome to this fantasy world!\n"


speech2 = "I hope it greets you well\n"
speech3 = "Just make sure you don't get too lost...\n"
speech4 = "he he he he...\n"
for character in speech1:
sys.stdout.write(character)
sys.stdout.flush()
time.sleep(0.03)
for character in speech2:
sys.stdout.write(character)
sys.stdout.flush()
time.sleep(0.03)
for character in speech3:
sys.stdout.write(character)
sys.stdout.flush()
time.sleep(0.1)
for character in speech4:
sys.stdout.write(character)
sys.stdout.flush()
time.sleep(0.2)

os.system('clear')
print("++++++++++++++++++++++++++")
print("+ Let's start now! +")
print("++++++++++++++++++++++++++")
main_game_loop()
title_screen()

You might also like