Advertisement
Kalidor_Vorlich

Untitled

Apr 10th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 8.31 KB | None | 0 0
  1. import os
  2. import sys
  3. import cmd
  4. import time
  5.  
  6. # ======== CHARACTER CLASS ==========
  7. class Player:
  8.     def __init__(self):
  9.         self.name = ''
  10.         self.job = ''
  11.         self.max_hp = 0
  12.         self.hp = 0
  13.         self.max_mp = 0
  14.         self.mp = 0
  15.         self.attack = 1
  16.         self.defence = 1
  17.         self.knows_magic = False
  18.         self.position = 'a1'
  19.         self.gold = 0
  20.  
  21. # ========= ENEMY CLASS ===========
  22. class Enemy:
  23.     def __init__(self,name,max_hp,hp,attack,defence,gold):
  24.         self.name = name
  25.         self.max_hp = max_hp
  26.         self.hp = hp
  27.         self.attack = attack
  28.         self.defence = defence
  29.         self.gold = gold
  30.  
  31. myplayer = Player()  # character created with no stats or name, those values will be passed in the object during the character creation
  32.  
  33.  
  34. # first screen
  35. def title_screen():
  36.     os.system('cls')
  37.     print('==========================================')
  38.     print('==  Welcome to a Python Text Based RPG  ==')
  39.     print('==                                      ==')
  40.     print('==      This is a learning project.     ==')
  41.     print('==                                      ==')
  42.     print('==         2018 Kalidor and Coop        ==')
  43.     print('==========================================\n')
  44.     print('')
  45.     print('[1] Start Game \n[2] Load Game \n[3] Help \n[4] Quit Game')
  46.     option = input('> ')
  47.     if option.lower() in ['1', 'start']:
  48.         character_creation()
  49.     elif option.lower() in ['2', 'load']:
  50.         load_game()
  51.     elif option.lower() in ['3', 'help']:
  52.         help_menu()
  53.     elif option.lower() in ['4', 'quit']:
  54.         sys.exit()
  55.     else:
  56.         title_screen()
  57.  
  58.  
  59.  
  60. # ========= CHARACTER CREATION =============
  61. def character_creation():
  62.     os.system('cls') # clears the screen
  63.     print('What is your name?\n')
  64.     playername = input('> ')
  65.     myplayer.name = playername     # passes name into player object
  66.    
  67.     print('What is your job?')
  68.     print('You can choose:\n[1]Warrior\n[2]Mage')
  69.     playerjob = input('> ')
  70.     if playerjob.lower() in ['1', 'warrior']:
  71.         myplayer.job = 'Warrior'
  72.         myplayer.max_hp = 20
  73.         myplayer.hp = 20
  74.         myplayer.attack = 5
  75.         myplayer.defence = 5
  76.         start_game()
  77.  
  78.     elif playerjob.lower() in ['2', 'mage']:
  79.         myplayer.job = 'Mage'
  80.         myplayer.max_hp = 15
  81.         myplayer.hp = 15
  82.         myplayer.max_mp = 10
  83.         myplayer.mp = 10
  84.         myplayer.attack = 2
  85.         myplayer.defence = 3
  86.         myplayer.knows_magic = True
  87.         start_game()
  88.  
  89.  
  90.  
  91.  
  92. # ========== LOAD GAME FUNCTION =============
  93. def load_game():
  94.     pass
  95.  
  96. # ============== HELP MENU ==================
  97. def help_menu():
  98.     pass
  99.  
  100.  
  101. # ===========    MAP    =======================
  102. #
  103. #|a1|a2|
  104. #|b1|b2|
  105.  
  106.  
  107. solved_areas = {'a1': False, 'a2': False, 'b1': False, 'b2': False}
  108.  
  109.  
  110. GRIDNAME = 'name'
  111. DESCRIPTION = 'description'
  112. SOLVED_DESCRIPTION = 'solved description'
  113. SOLVED = ''
  114. UP = 'up', 'north'
  115. DOWN = 'down', 'south'
  116. LEFT = 'left', 'west'
  117. RIGHT = 'right', 'east'
  118.  
  119. cavemap = {
  120.     'a1': {
  121.     GRIDNAME : 'Cave Entrance',
  122.     DESCRIPTION : 'You have entered a small cave. It is dark inside.',
  123.     SOLVED_DESCRIPTION: "This is a cave entrance. You see light coming from outside.",
  124.     SOLVED : False,
  125.     UP : None,
  126.     DOWN : 'b1',
  127.     LEFT : None,
  128.     RIGHT : 'a2',
  129. },        
  130.     'a2': {
  131.     GRIDNAME : 'Cave Room 1',
  132.     DESCRIPTION : 'This is a dead end. You see a pile of bones and a sword on the ground.',
  133.     SOLVED_DESCRIPTION : "This room doesn't lead anywhere. Pile of bones on the ground has nothing interesting in it.",
  134.     SOLVED : False,
  135.     UP : None,
  136.     DOWN : None,
  137.     LEFT : 'a1',
  138.     RIGHT : None,
  139. },
  140.     'b1': {
  141.     GRIDNAME : 'Cave Room 2',
  142.     DESCRIPTION : 'You entered a room, there\'s a goblin looking at you.',
  143.     SOLVED_DESCRIPTION : "A dead goblin is lying on the ground.",
  144.     SOLVED : False,
  145.     'ENEMY' : Enemy('Orc',10,10,5,5,2),
  146.     UP : 'a1',
  147.     DOWN : None,
  148.     LEFT : None,
  149.     RIGHT : 'b2',
  150. },
  151.     'b2': {
  152.     GRIDNAME : 'Cave Trasure Room',
  153.     DESCRIPTION : 'This is a dead end. You see a chest with gold.',
  154.     SOLVED_DESCRIPTION : "This room is a dead end and there's an empty chest lying on the ground.",
  155.     SOLVED : False,
  156.     UP : None,
  157.     DOWN : None,
  158.     LEFT : 'b1',
  159.     RIGHT : None,        
  160. }}
  161.  
  162.  
  163. # GAME INTERACTIVITY
  164.  
  165. def battle_start(enemy):
  166.     os.system('cls')
  167.     a = (myplayer.name + '     ' + enemy.name)
  168.     print(enemy.name + ' is attacking you!\n')
  169.     while myplayer.hp > 0:
  170.         print(a)
  171.         print(str(myplayer.hp) + '/' + str(myplayer.max_hp) + (' ' * (len(a) -10)) + str(enemy.hp) + '/' + str(enemy.max_hp))
  172.         print('\n\n\n')
  173.         print('What would you like to do?')
  174.         print('[1] Attack\n[2] Magic\n[3] Run')
  175.         action = input('> ')
  176.         if action == '1':
  177.             damage = myplayer.attack - enemy.defence
  178.             enemy.hp -= damage
  179.             if enemy.hp > 0:
  180.                 enemy_damage = enemy.attack - myplayer.defence
  181.                 if enemy_damage <= 0:
  182.                     enemy_damage = 1
  183.                 myplayer.hp -= enemy_damage
  184.             else:
  185.                 print('You killed ' + enemy.name)
  186.                 print('You have collected ' + str(enemy.gold) + ' gold.')
  187.                 myplayer.gold += enemy.gold
  188.                 cavemap[myplayer.position][SOLVED] = True
  189.                 cavemap[myplayer.position]['ENEMY'] = None
  190.                 time.sleep(5)
  191.                 print_location()
  192.         elif action == '2':
  193.             cast_spell()
  194.         elif action == '3':
  195.             myplayer.position = 'a1'
  196.             print_location()
  197.     print("You died")
  198.     time.sleep(3)
  199.     title_screen()
  200.                
  201.  
  202. def cast_spell():
  203.     pass
  204.  
  205.  
  206. def print_location():
  207.     print('')
  208.     print('===== {} ====='.format(cavemap[myplayer.position][GRIDNAME]))
  209.     print('')
  210.     if cavemap[myplayer.position][SOLVED]:
  211.         print(cavemap[myplayer.position][SOLVED_DESCRIPTION])
  212.         prompt()
  213.     else:
  214.         print(cavemap[myplayer.position][DESCRIPTION])
  215.         if 'ENEMY' in cavemap[myplayer.position]:
  216.             time.sleep(5)
  217.             battle_start(cavemap[myplayer.position]['ENEMY'])
  218.         else:
  219.             prompt()
  220.  
  221.  
  222. def prompt():
  223.     print('\nWhat would you like to do? (You can only use \'go\' so far.\n')
  224.     answers = ['go', 'quit']
  225.     action = input('> ')
  226.     while action not in answers:
  227.         prompt()
  228.     if action.lower() == 'go':
  229.         player_movement()
  230.     elif action.lower() == 'quit':
  231.         sys.exit()
  232.  
  233. def player_movement():
  234.     print('\nGo where?\n')
  235.     answers = ['north', 'south', 'east', 'west']
  236.     direction = input('> ')
  237.     while direction not in answers:
  238.         player_movement()
  239.     if direction.lower() == 'north':
  240.         if cavemap[myplayer.position][UP]:
  241.             destination = cavemap[myplayer.position][UP]
  242.             movement_handler(destination)
  243.         else:
  244.             print("You cannot go there!")
  245.             player_movement()
  246.     elif direction.lower() == 'south':
  247.         if cavemap[myplayer.position][DOWN]:
  248.             destination = cavemap[myplayer.position][DOWN]
  249.             movement_handler(destination)
  250.         else:
  251.             print("You cannot go there!")
  252.             player_movement()
  253.     elif direction.lower() == 'west':
  254.         if cavemap[myplayer.position][LEFT]:
  255.             destination = cavemap[myplayer.position][LEFT]
  256.             movement_handler(destination)
  257.         else:
  258.             print("You cannot go there!")
  259.             player_movement()
  260.     elif direction.lower() == 'east':
  261.         if cavemap[myplayer.position][RIGHT]:
  262.             destination = cavemap[myplayer.position][RIGHT]
  263.             movement_handler(destination)
  264.         else:
  265.             print("You cannot go there!")
  266.             player_movement()
  267.  
  268. def movement_handler(destination):
  269.     print('You have moved to the {}.'.format(cavemap[destination][GRIDNAME]))
  270.     cavemap[myplayer.position][SOLVED] = True
  271.     myplayer.position = destination
  272.     print_location()
  273.  
  274.  
  275. # ============== STARTING THE GAME ==========
  276. def start_game():
  277.     print('Wecome, {} the {}!'.format(myplayer.name, myplayer.job))
  278.     print('This is a small game, a Python learning project. Hope you\'ll enjoy!')
  279.     print_location()
  280.  
  281.  
  282.  
  283. title_screen()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement