Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #text rpg
- # Matthew Clarke
- #terminal game (no flask)
- import cmd #uses command line
- import textwrap #wraps text on console
- import sys #system funtions
- import os #os related functions
- import time #time functions
- import random #random gen (rolling a dice)
- screen_width = 100 #define console screensize
- #### Create your Player ####
- class player:
- def __init__(self): #initialse function as itself
- self.name = ''
- self.job = ''
- self.hp = 0
- self.mp = 0
- self.status_effects = [] #this will all be used to store values for the players character
- self.location = 'start' #stored string, where the player is currently
- self.game_over = False
- myPlayer = player() #call the function 'player' inside the class
- #### Title screen ####
- #play help or quit commands#
- def title_screen_selections():
- option = input("-> ") #something someone will type into the comand prompt
- if option.lower() == ("play"):
- setup_game() #placeholder until written
- elif option.lower() ==("help"):
- help_menu()
- elif option.lower() ==("quit"):
- sys.exit() #imported from import sys
- while option.lower() not in ['play', 'help', 'quit']: #if the person doesnt type one of these command cycle through to promt them to type an acceptable value
- print("please enter a valid command.(play, help or quit)")
- option = input("-> ")
- if option.lower() == ("play"):
- setup_game() #placeholder until written
- elif option.lower() ==("help"):
- help_menu()
- elif option.lower() ==("quit"):
- sys.exit()
- def title_screen():
- os.system('clear')
- print('################################')
- print('# Welcome to my text game! #')
- print('################################')
- print(' #-PLAY-# ')
- print(' #-HELP-# ')
- print(' #-QUIT-# ')
- title_screen_selections() #call the player options after printing the home screen ( use () so the function is called to run)
- def help_menu():
- print('################################')
- print('# Welcome to my text game! #')
- print('################################')
- print('-type: up, down, left and right to move-')
- print('- type all commands to do them-')
- print('-Use "look" to inspect something-')
- print('################################')
- print(' -Good luck- ')
- print('################################')
- title_screen_selections() #once again, call the title screen selections option
- ####### MAP #######
- #a1 a2 a3 a4 visualising the map for myself, player starts at b2
- #-------------
- #| | | | | a4
- #-------------
- #| | x| | | b4
- #-------------
- #| | | | | c4
- #-------------
- #| | | | | e4
- #-------------
- ZONENAME = '' #The name of the currect players zone
- DESCRIPTION = 'description' # user will type description for a description of their current location
- EXAMINATION = 'examine' #examine command examines something in the world
- SOLVED = False
- UP = 'up', 'north'
- DOWN = 'down', 'south'
- RIGHT = 'right', 'east'
- LEFT = 'left', 'west'
- #now we create our grid system
- 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,
- } #{} in python adds to a dictionary, a1 is the key for the value False
- #now we code each zone, again adding them into a dictionary and another dictionary within that dictionary. Like a terminal based database ( research how to convert to SQL later?)
- zonemap = {
- #A section
- 'a1': { #each zone will have differant attributes to make the game feel more alive
- ZONENAME: "Trade district",
- DESCRIPTION: 'description',
- EXAMINATION: 'examine',
- SOLVED: False,
- UP: '',
- DOWN: 'b1',
- RIGHT: 'a1',
- LEFT: '',
- },
- 'a2': {
- ZONENAME: 'City Gates',
- DESCRIPTION: 'description',
- EXAMINATION: 'examine',
- SOLVED: False,
- UP: '',
- DOWN: 'b2',
- RIGHT: 'a3',
- LEFT: 'a1',
- },
- 'a3': {
- ZONENAME: 'City Square',
- DESCRIPTION: 'description',
- EXAMINATION: 'examine',
- SOLVED: False,
- UP: '',
- DOWN: 'b3',
- RIGHT: 'a4',
- LEFT: 'a2',
- },
- 'a4': {
- ZONENAME: 'City Dungeons',
- DESCRIPTION: 'description',
- EXAMINATION: 'examine',
- SOLVED: False,
- UP: '',
- DOWN: 'b4',
- RIGHT: '',
- LEFT: 'a3',
- },
- 'b1': { #B section
- ZONENAME: 'Yellow Feather Town',
- DESCRIPTION: 'Yellow feather Town is a small bundle of houses located outside Altdorf, It is mainly used by travellers who visit the inn',
- EXAMINATION: 'As you wander around the small town you catch people staring at you, You feel out of place',
- SOLVED: False,
- UP: 'a2',
- DOWN: 'c1',
- RIGHT: 'b2',
- LEFT: '',
- },
- 'b2': {
- ZONENAME: 'Yellow Feather Inn',
- DESCRIPTION: 'The Yellow Feather Inn is a safe spot for you, The inn keeper has provided you with a room, It is located just south of the City of Altdorf',
- EXAMINATION: 'This inn is filled with shadey looking people, Best not cause any trouble here',
- SOLVED: False,
- UP: 'a2',
- DOWN: 'c2',
- RIGHT: 'b3',
- LEFT: 'b1',
- },
- 'b3': {
- ZONENAME: '',
- DESCRIPTION: 'description',
- EXAMINATION: 'examine',
- SOLVED: False,
- UP: 'up',
- DOWN: 'down',
- RIGHT: 'right',
- LEFT: 'left',
- },
- 'b4': {
- ZONENAME: '',
- DESCRIPTION: 'description',
- EXAMINATION: 'examine',
- SOLVED: False,
- UP: 'up',
- DOWN: 'down',
- RIGHT: 'right',
- LEFT: 'left',
- },
- 'c1': { #c section
- ZONENAME: '',
- DESCRIPTION: 'description',
- EXAMINATION: 'examine',
- SOLVED: False,
- UP: 'up',
- DOWN: 'down',
- RIGHT: 'right',
- LEFT: 'left',
- },
- 'c2': {
- ZONENAME: '',
- DESCRIPTION: 'description',
- EXAMINATION: 'examine',
- SOLVED: False,
- UP: 'up',
- DOWN: 'down',
- RIGHT: 'right',
- LEFT: 'left',
- },
- 'c3': {
- ZONENAME: '',
- DESCRIPTION: 'description',
- EXAMINATION: 'examine',
- SOLVED: False,
- UP: 'up',
- DOWN: 'down',
- RIGHT: 'right',
- LEFT: 'left',
- },
- 'c4': {
- ZONENAME: '',
- DESCRIPTION: 'description',
- EXAMINATION: 'examine',
- SOLVED: False,
- UP: 'up',
- DOWN: 'down',
- RIGHT: 'right',
- LEFT: 'left',
- },
- 'd1': { #d section
- ZONENAME: '',
- DESCRIPTION: 'description',
- EXAMINATION: 'examine',
- SOLVED: False,
- UP: 'up',
- DOWN: 'down',
- RIGHT: 'right',
- LEFT: 'left',
- },
- 'd2': {
- ZONENAME: '',
- DESCRIPTION: 'description',
- EXAMINATION: 'examine',
- SOLVED: False,
- UP: 'up',
- DOWN: 'down',
- RIGHT: 'right',
- LEFT: 'left',
- },
- 'd3': {
- ZONENAME: '',
- DESCRIPTION: 'description',
- EXAMINATION: 'examine',
- SOLVED: False,
- UP: 'up',
- DOWN: 'down',
- RIGHT: 'right',
- LEFT: 'left',
- },
- 'd4': {
- ZONENAME: '',
- DESCRIPTION: 'description',
- EXAMINATION: 'examine',
- SOLVED: False,
- UP: 'up',
- DOWN: 'down',
- RIGHT: 'right',
- LEFT: 'left',
- }
- }
- ####### GAME INTERACTIVITY ######
- def print_location(): #print location statement
- print('\n' + ('#' * (4 + len(myPlayer.location))))#\n makes it print on a new line
- print('# ' + myPlayer.location.upper() + ' #')
- print('# ' + zonemap[myPlayer.position] [DESCRIPTION] + ' #')
- print('\n' + ('#' * (4 + len(myPlayer.location)))) #this line adds padding of the word * 4 in hastags to improve console visuals
- def prompt():
- print("\n" + "======================")
- print("What would you like to do?")
- action = input("-> ") #ask for the users input
- acceptable_actions = ['move', 'go', 'travel', 'walk', 'quit', 'examine', 'inspect', 'interact', 'look'] #determine acceptable user inputs
- while action.lower() not in acceptable_actions: #if the entered action is not acceptable
- print("Unknown action, try again.\n")
- 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 go?\n" #defining where the user is travelling to
- destination = input(ask)
- if dest in ['up', 'north']:
- destination = zonemap[myPlayer.location][UP]
- movement_handler(destination)
- elif dest in ['down', 'south']:
- destination = zonemap[myPlayer.location][DOWN]
- movement_handler(destination)
- elif dest in ['right', 'east']:
- destination = zonemap[myPlayer.location][RIGHT]
- movement_handler(destination)
- elif dest in ['left', 'west']:
- destination = zonemap[myPlayer.location][LEFT]
- movement_handler(destination)
- def movement_handler(destination):
- print("\n" + "You have moved to " + destination + ".")
- myPlayer.location = destination
- print_location()
- def player_examine(action):
- if zonemap[myPlayer.location] [SOLVED]:
- print("This Zone is safe.... For now.")
- else:
- print("") #trigger a puzzle here
- ####### Game functions ##########
- def main_game_loop():
- while myPlayer.game_over is False:
- prompt()
- # here handle if puzzles have been solved, boss defeated, explored everything, ect.
- def setup_game():
- os.system('clear')
- #naming the character
- question1 = "What is your characters name?\n"
- for character in question1:
- sys.stdout.write(character)
- sys.stdout.flush()
- time.sleep(0.05) #add delay to the text being presented to the user
- player_name = input ("-> ")
- myPlayer.name = player_name
- ##picking player class
- question2 = "What's your combat style?\n"
- question2added = "(type: warrior, wizard or archer)\n" # assigning second line of text
- for character in question2:
- sys.stdout.write(character)
- sys.stdout.flush()
- for character in question2added:
- sys.stdout.write(character)
- sys.stdout.flush()
- time.sleep(0.01) #sped this section up as it is a command and not 'npc' text
- player_job = input ("-> ")
- valid_jobs = ['warrior', 'wizard', 'archer'] #assigning valid game classes
- if player_job.lower() in valid_jobs:
- myPlayer.job = player_job
- print(player_job + " is your selected class!\n")
- else:
- while player_job.lower() not in valid_jobs:
- player_job = input("-> ")
- if player_job.lower() in valid_jobs:
- myPlayer.job = player_job
- print(player_job + " is your selected class!\n")
- #player stats
- if myPlayer.job is 'warrior':
- self.hp = 120
- self.mp = 10
- elif myPlayer.job is 'wizard':
- self.hp = 50
- self.mp = 100
- elif myPlayer.job is 'archer':
- self.hp = 75
- self.mp = 30
- ##inroduction
- question3 = "Welcome to the Yellow Feather Inn, " + myPlayer.name + " the " + player_job + ".\n"
- for character in question3:
- sys.stdout.write(character)
- sys.stdout.flush()
- time.sleep(0.05) #add delay to the text being presented to the user
- player_name = input ("-> ")
- myPlayer.name = player_name
- speech1 = "Welcome to the Yellow Feather inn Adventurer"
- speech2 = "head North into the city of Altdorf or stick around here a while"
- speech3 = "Just make sure you dont wander too far off the road"
- speech4 = "Can never be too careful round these parts...."
- print("The innkeeper leaves your room while glaring over his shoulder \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("# begin your adventure #")
- print("###########################")
- main_game_loop()
- title_screen()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement