Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import sys
- import cmd
- import time
- # ======== CHARACTER CLASS ==========
- class Player:
- def __init__(self):
- self.name = ''
- self.job = ''
- self.max_hp = 0
- self.hp = 0
- self.max_mp = 0
- self.mp = 0
- self.attack = 1
- self.defence = 1
- self.knows_magic = False
- self.position = 'a1'
- self.gold = 0
- # ========= ENEMY CLASS ===========
- class Enemy:
- def __init__(self,name,max_hp,hp,attack,defence,gold):
- self.name = name
- self.max_hp = max_hp
- self.hp = hp
- self.attack = attack
- self.defence = defence
- self.gold = gold
- myplayer = Player() # character created with no stats or name, those values will be passed in the object during the character creation
- # first screen
- def title_screen():
- os.system('cls')
- print('==========================================')
- print('== Welcome to a Python Text Based RPG ==')
- print('== ==')
- print('== This is a learning project. ==')
- print('== ==')
- print('== 2018 Kalidor and Coop ==')
- print('==========================================\n')
- print('')
- print('[1] Start Game \n[2] Load Game \n[3] Help \n[4] Quit Game')
- option = input('> ')
- if option.lower() in ['1', 'start']:
- character_creation()
- elif option.lower() in ['2', 'load']:
- load_game()
- elif option.lower() in ['3', 'help']:
- help_menu()
- elif option.lower() in ['4', 'quit']:
- sys.exit()
- else:
- title_screen()
- # ========= CHARACTER CREATION =============
- def character_creation():
- os.system('cls') # clears the screen
- print('What is your name?\n')
- playername = input('> ')
- myplayer.name = playername # passes name into player object
- print('What is your job?')
- print('You can choose:\n[1]Warrior\n[2]Mage')
- playerjob = input('> ')
- if playerjob.lower() in ['1', 'warrior']:
- myplayer.job = 'Warrior'
- myplayer.max_hp = 20
- myplayer.hp = 20
- myplayer.attack = 5
- myplayer.defence = 5
- start_game()
- elif playerjob.lower() in ['2', 'mage']:
- myplayer.job = 'Mage'
- myplayer.max_hp = 15
- myplayer.hp = 15
- myplayer.max_mp = 10
- myplayer.mp = 10
- myplayer.attack = 2
- myplayer.defence = 3
- myplayer.knows_magic = True
- start_game()
- # ========== LOAD GAME FUNCTION =============
- def load_game():
- pass
- # ============== HELP MENU ==================
- def help_menu():
- pass
- # =========== MAP =======================
- #
- #|a1|a2|
- #|b1|b2|
- solved_areas = {'a1': False, 'a2': False, 'b1': False, 'b2': False}
- GRIDNAME = 'name'
- DESCRIPTION = 'description'
- SOLVED_DESCRIPTION = 'solved description'
- SOLVED = ''
- UP = 'up', 'north'
- DOWN = 'down', 'south'
- LEFT = 'left', 'west'
- RIGHT = 'right', 'east'
- cavemap = {
- 'a1': {
- GRIDNAME : 'Cave Entrance',
- DESCRIPTION : 'You have entered a small cave. It is dark inside.',
- SOLVED_DESCRIPTION: "This is a cave entrance. You see light coming from outside.",
- SOLVED : False,
- UP : None,
- DOWN : 'b1',
- LEFT : None,
- RIGHT : 'a2',
- },
- 'a2': {
- GRIDNAME : 'Cave Room 1',
- DESCRIPTION : 'This is a dead end. You see a pile of bones and a sword on the ground.',
- SOLVED_DESCRIPTION : "This room doesn't lead anywhere. Pile of bones on the ground has nothing interesting in it.",
- SOLVED : False,
- UP : None,
- DOWN : None,
- LEFT : 'a1',
- RIGHT : None,
- },
- 'b1': {
- GRIDNAME : 'Cave Room 2',
- DESCRIPTION : 'You entered a room, there\'s a goblin looking at you.',
- SOLVED_DESCRIPTION : "A dead goblin is lying on the ground.",
- SOLVED : False,
- 'ENEMY' : Enemy('Orc',10,10,5,5,2),
- UP : 'a1',
- DOWN : None,
- LEFT : None,
- RIGHT : 'b2',
- },
- 'b2': {
- GRIDNAME : 'Cave Trasure Room',
- DESCRIPTION : 'This is a dead end. You see a chest with gold.',
- SOLVED_DESCRIPTION : "This room is a dead end and there's an empty chest lying on the ground.",
- SOLVED : False,
- UP : None,
- DOWN : None,
- LEFT : 'b1',
- RIGHT : None,
- }}
- # GAME INTERACTIVITY
- def battle_start(enemy):
- os.system('cls')
- a = (myplayer.name + ' ' + enemy.name)
- print(enemy.name + ' is attacking you!\n')
- while myplayer.hp > 0:
- print(a)
- print(str(myplayer.hp) + '/' + str(myplayer.max_hp) + (' ' * (len(a) -10)) + str(enemy.hp) + '/' + str(enemy.max_hp))
- print('\n\n\n')
- print('What would you like to do?')
- print('[1] Attack\n[2] Magic\n[3] Run')
- action = input('> ')
- if action == '1':
- damage = myplayer.attack - enemy.defence
- enemy.hp -= damage
- if enemy.hp > 0:
- enemy_damage = enemy.attack - myplayer.defence
- if enemy_damage <= 0:
- enemy_damage = 1
- myplayer.hp -= enemy_damage
- else:
- print('You killed ' + enemy.name)
- print('You have collected ' + str(enemy.gold) + ' gold.')
- myplayer.gold += enemy.gold
- cavemap[myplayer.position][SOLVED] = True
- cavemap[myplayer.position]['ENEMY'] = None
- time.sleep(5)
- print_location()
- elif action == '2':
- cast_spell()
- elif action == '3':
- myplayer.position = 'a1'
- print_location()
- print("You died")
- time.sleep(3)
- title_screen()
- def cast_spell():
- pass
- def print_location():
- print('')
- print('===== {} ====='.format(cavemap[myplayer.position][GRIDNAME]))
- print('')
- if cavemap[myplayer.position][SOLVED]:
- print(cavemap[myplayer.position][SOLVED_DESCRIPTION])
- prompt()
- else:
- print(cavemap[myplayer.position][DESCRIPTION])
- if 'ENEMY' in cavemap[myplayer.position]:
- time.sleep(5)
- battle_start(cavemap[myplayer.position]['ENEMY'])
- else:
- prompt()
- def prompt():
- print('\nWhat would you like to do? (You can only use \'go\' so far.\n')
- answers = ['go', 'quit']
- action = input('> ')
- while action not in answers:
- prompt()
- if action.lower() == 'go':
- player_movement()
- elif action.lower() == 'quit':
- sys.exit()
- def player_movement():
- print('\nGo where?\n')
- answers = ['north', 'south', 'east', 'west']
- direction = input('> ')
- while direction not in answers:
- player_movement()
- if direction.lower() == 'north':
- if cavemap[myplayer.position][UP]:
- destination = cavemap[myplayer.position][UP]
- movement_handler(destination)
- else:
- print("You cannot go there!")
- player_movement()
- elif direction.lower() == 'south':
- if cavemap[myplayer.position][DOWN]:
- destination = cavemap[myplayer.position][DOWN]
- movement_handler(destination)
- else:
- print("You cannot go there!")
- player_movement()
- elif direction.lower() == 'west':
- if cavemap[myplayer.position][LEFT]:
- destination = cavemap[myplayer.position][LEFT]
- movement_handler(destination)
- else:
- print("You cannot go there!")
- player_movement()
- elif direction.lower() == 'east':
- if cavemap[myplayer.position][RIGHT]:
- destination = cavemap[myplayer.position][RIGHT]
- movement_handler(destination)
- else:
- print("You cannot go there!")
- player_movement()
- def movement_handler(destination):
- print('You have moved to the {}.'.format(cavemap[destination][GRIDNAME]))
- cavemap[myplayer.position][SOLVED] = True
- myplayer.position = destination
- print_location()
- # ============== STARTING THE GAME ==========
- def start_game():
- print('Wecome, {} the {}!'.format(myplayer.name, myplayer.job))
- print('This is a small game, a Python learning project. Hope you\'ll enjoy!')
- print_location()
- title_screen()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement