SHARE
TWEET

Untitled

FedeCuci Apr 18th, 2019 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import time
  2. import os
  3. import random
  4.  
  5. # In this lesson we are going to create a text-based RPG game
  6. # We are going to use our knowledge of variables, logic and printning in
  7. # order to accomplish our goal
  8.  
  9. # The first thing we want to do is think of a story four our game
  10. # Lets start by thinking about a main character and an antagonist
  11.  
  12. # The first we want to do is to create the main character
  13.  
  14. # We can use input for this!
  15.  
  16. player = input('Name of character: ')
  17.  
  18. # Let's check that the user actually provided us with something!
  19. if not player:
  20.     print('Please enter a valid name')
  21.  
  22. # Now we need to create some variables for our character
  23. # We need to think, what does our character need in our game? (health, attack...)
  24.  
  25. player_health = 100
  26. player_damage = 5
  27.  
  28. # Now that we gave our player some variables, let's create our enemy!
  29.  
  30. enemy_health = 100
  31. enemy_damage = 5
  32.  
  33. # Now that we have that, we can initiate our game!
  34. # Our game is going to be stored in an infinite loop which will always repeat actions
  35.  
  36. while True:
  37.  
  38.     # Make a variable to see if the player had a turn
  39.     had_turn = False
  40.  
  41.     # Make an array of available options
  42.     actions = ['attack', 'upgrade', 'miss']
  43.  
  44.     # Ask the player what action he would like to take
  45.     action = input('What do you want to do? ')
  46.  
  47.     # If action is not valid then ask again
  48.     if action not in actions:
  49.         print('enter a valid option')
  50.  
  51.     if action == 'attack':
  52.         print('{} attacked enemy'.format(player))
  53.         enemy_health -= 5
  54.         had_turn = True
  55.     elif action == 'ajshdfka':
  56.         print('action')
  57.         had_turn = True
  58.  
  59.     # Enemy's turn
  60.  
  61.     if had_turn:
  62.         enemy_action = random.choice(actions)
  63.  
  64.         if enemy_action == 'attack':
  65.             print('goblin attacked you')
  66.             player_health -= 5
  67.         else:
  68.             print('something else')
  69.  
  70.     if enemy_health <= 0:
  71.         print('Enemy is dead\n')
  72.         break
  73.     elif enemy_health <= 0:
  74.         print('The enemy killed you\n')
  75.         break
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top