Python Forum
Thread Rating:
  • 2 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Basic RPG
#1
This is a basic RPG where you fight Goblins and Giant Rats until you die. I will make this a part of a larger more interesting game in the future maybe. The stat calculations are unbalanced, and it's really unpolished, but it's basically just my way of trying to teach myself Python.

import random
import sys

#Enemies
goblin = {}
goblin['Name'] = 'Goblin'
goblin['Health'] = 50.0
goblin['Agility'] = 40.0
goblin['Strength'] = 35.0
goblin['Level'] = 1

giant_rat = {}
giant_rat['Name'] = 'Giant Rat'
giant_rat['Health'] = 40.0
giant_rat['Agility'] = 55.0
giant_rat['Strength'] = 30.0
giant_rat['Level'] = 1

def Death():
    print("You have died!")
    print("GAME OVER")
    exit_game = raw_input()
    sys.exit()	

def Fight(enemy):
    print("All of a sudden a " + str(enemy['Name']) + " attacks you!")
    Enemy = enemy.copy()
    while Enemy['Health'] > 0:
        Attack = False
        A = raw_input("Type A to attack the " + str(Enemy['Name']) + ". ")
        if A == "Attack" or "attack" or "A" or "a":
            Attack = True
        else:
            pass
        if Attack == True:
            print("You swing at the " + str(Enemy['Name']) + " with your sword!...")
            Player_attack_lands = False
            Enemy_attack_lands = False
            if (Enemy['Agility'] - player['Agility'] + (random.random() - random.random()) * 100) <= 0:
                Player_attack_lands = True
            else:
                pass
            if Player_attack_lands == True:
                print("You strike the " + str(Enemy['Name']) + "!")
                Enemy['Health'] = Enemy['Health'] - player['Strength']
                print("You've done " + str(player['Strength']) +" damage! ")
                print("The " + str(Enemy['Name']) + " now has " + str(Enemy['Health']) + " left. ")
                if Enemy['Health'] <= 0:
                    pass
                else:
                    print("The " + str(Enemy['Name']) + " launches an attack at you! ")
                    if (Enemy['Agility'] - player['Agility'] + (random.random() - random.random()) * 100) <= 0:
                        Enemy_attack_lands = True
                    else:
                        print("The " + str(Enemy['Name']) + " missed! ")
                    if Enemy_attack_lands == True:
                        print("The " + str(Enemy['Name']) + " lands its attack! ")
                        player['Health'] = player['Health'] - Enemy['Strength']
                        print("The " + str(Enemy['Name']) + " deals " + str(Enemy['Strength']) + " damage to you. ")
                        print("You have " + str(player['Health']) + " Health left. ")
                        if player['Health'] <= 0:
                            Death()
                        else:
                            pass
                    else:
                        pass      
            else:
                print("You miss!")
                print("The " + str(Enemy['Name']) + " launches an attack at you! ")
                if (Enemy['Agility'] - player['Agility'] + (random.random() - random.random()) * 100) <= 0:
                    Enemy_attack_lands = True
                else:
                    print("The " + str(Enemy['Name']) + " missed! ")
                if Enemy_attack_lands == True:
                    print("The " + str(Enemy['Name']) + " lands its attack! ")
                    player['Health'] = player['Health'] - Enemy['Strength']
                    print("The " + str(Enemy['Name']) + " deals " + str(Enemy['Strength']) + " damage to you. ")
                    print("You have " + str(player['Health']) + " Health left. ")
                    if player['Health'] <= 0:
                        Death()
                    else:
                        pass
    print("You've killed the " + str(enemy['Name']) + "!")

#Character Creaion
player={}
player['Name'] = raw_input("Please enter your character's name. ")
player['Sex'] = raw_input("Please enter your character's sex. ")
player['Experience'] = 0
player['Level'] = 1
if player['Sex'] == 'female' or 'f' or 'F':
    player['Sex'] = 'Female'
elif player['Sex'] == 'male' or 'm' or 'M':
    player['Sex'] = 'Male'
else:
    pass
if player['Sex'] != 'Female' and player['Sex'] != 'Male':
    player['Sex'] = raw_input("Please enter your character's sex again. Please enter Male or Female. ")
else:
    pass
player['Strength'] = (random.random() * 100)
player['Agility'] = ((random.random() * 100) + 70) / 2
player['Health'] = (random.random() * 100 + 100)
#End Character Creation

while player['Health'] > 0:
    Fight(goblin)
    print("")
    Fight(giant_rat)
    print("")
Reply


Messages In This Thread
Basic RPG - by Iskuss - Dec-04-2017, 02:38 AM
RE: Basic RPG - by Larz60+ - Dec-04-2017, 03:55 AM
RE: Basic RPG - by Iskuss - Dec-07-2017, 06:05 AM
RE: Basic RPG - by nilamo - Dec-11-2017, 09:13 PM
RE: Basic RPG - by Iskuss - Dec-12-2017, 06:00 AM
RE: Basic RPG - by mpd - Dec-12-2017, 12:50 PM
RE: Basic RPG - by Windspar - Dec-12-2017, 03:14 PM
RE: Basic RPG - by uribrasil - Apr-25-2020, 09:16 PM
RE: Basic RPG - by Larz60+ - Apr-25-2020, 09:19 PM
RE: Basic RPG - by uribrasil - Apr-25-2020, 09:21 PM
RE: Basic RPG - by Larz60+ - Apr-25-2020, 09:24 PM
RE: Basic RPG - by uribrasil - Apr-25-2020, 09:26 PM
RE: Basic RPG - by asiaphone12 - May-08-2020, 04:59 AM
RE: Basic RPG - by Larz60+ - May-08-2020, 08:39 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020