Skip to content

Instantly share code, notes, and snippets.

@micaiahparker
Created April 12, 2012 17:46
Show Gist options
  • Save micaiahparker/2369579 to your computer and use it in GitHub Desktop.
Save micaiahparker/2369579 to your computer and use it in GitHub Desktop.
can anyone tell me why the enemy.name works in some parts but not others.
#Gladiator by Micaiah Parker
import random
import os
rnd = 1
turn = 1
def enter(): #enter()clears the screen after clicking enter
input()
os.system(['clear','cls'][os.name == 'nt'])
def cls(): #clears the screen
os.system(['clear','cls'][os.name == 'nt'])
def battle():
while player.life > 0 and enemy.life > 0:
print("Turn {}".format(turn))
r = random.randint(0, 1)#Rolls to see who attacks
if r == 0:#Opponent attacks
damage = random.randint(0, attx) - random.randint(0, defe)
if damage < 0: #Prevents life gain glitch
damage = 0
player.life = player.life - damage
print(enemy.name + " Attacks")
if damage == 0:
print("You block!")
if r == 1:#You attack
damage = random.randint(0, att) - random.randint(0, defex)
if damage <0: #Prevents life gain glitch
damage = 0
enemy.life = enemy.life - damage
print("You attack!")
if damage == 0:
print(enemy.name + " Blocks!")
turn = turn + 1
enter()
def begin():
cls()
enemy = gladiator()
print("Round " + str(rnd))
print(player.name + " VS " + enemy.name)
enter()
stats()
battle()
def afterbat():
if enemy.life <= 0:
player.lvl = player.lvl + 1
player.life = player.lifelock
enter()
print("You Win!")
rnd = rnd + 1
begin()
if player.life <= 0:
print("You Died")
enter()
class gladiator(): #creates an enemy
def __init__(self):
self.name = "Prisoner " + str(rnd)
self.lvl = random.randint(0, 5)
self.life = random.randint(50, 100) + self.lvl * 10
self.att = random.randint(5, 15) + self.lvl
self.dfnc = random.randint(5, 15) + self.lvl
class player(): #creates the player
def __init__(self):
self.name = input("What is your name? ")
self.lvl = 0
self.life = random.randint(50, 100) + self.lvl * 10
self.lifelock = self.life
self.att = random.randint(5, 15) + self.lvl
self.dfnc = random.randint(5, 15) + self.lvl
def stats():
print(player.name + " stats")
print("Life")
print(player.life)
print("Level")
print(player.lvl)
print("Attack")
print(player.att)
print("Defence")
print(player.dfnc)
enter()
print(enemy.name + " stats")
print("Life")
print(enemy.life)
print("Level")
print(enemy.lvl)
print("Attack")
print(enemy.att)
print("Defence")
print(enemy.dfnc)
enter()
player = player()
begin()
afterbat()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment