Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- import os
- import random
- # In this lesson we are going to create a text-based RPG game
- # We are going to use our knowledge of variables, logic and printning in
- # order to accomplish our goal
- # The first thing we want to do is think of a story four our game
- # Lets start by thinking about a main character and an antagonist
- # The first we want to do is to create the main character
- # We can use input for this!
- player = input('Name of character: ')
- # Let's check that the user actually provided us with something!
- if not player:
- print('Please enter a valid name')
- # Now we need to create some variables for our character
- # We need to think, what does our character need in our game? (health, attack...)
- player_health = 100
- player_damage = 5
- # Now that we gave our player some variables, let's create our enemy!
- enemy_health = 100
- enemy_damage = 5
- # Now that we have that, we can initiate our game!
- # Our game is going to be stored in an infinite loop which will always repeat actions
- while True:
- # Make a variable to see if the player had a turn
- had_turn = False
- # Make an array of available options
- actions = ['attack', 'upgrade', 'miss']
- # Ask the player what action he would like to take
- action = input('What do you want to do? ')
- # If action is not valid then ask again
- if action not in actions:
- print('enter a valid option')
- if action == 'attack':
- print('{} attacked enemy'.format(player))
- enemy_health -= 5
- had_turn = True
- elif action == 'ajshdfka':
- print('action')
- had_turn = True
- # Enemy's turn
- if had_turn:
- enemy_action = random.choice(actions)
- if enemy_action == 'attack':
- print('goblin attacked you')
- player_health -= 5
- else:
- print('something else')
- if enemy_health <= 0:
- print('Enemy is dead\n')
- break
- elif enemy_health <= 0:
- print('The enemy killed you\n')
- break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement