Skip to content

Instantly share code, notes, and snippets.

@AmaxJ
Created January 16, 2015 02:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AmaxJ/849c766926fd08433196 to your computer and use it in GitHub Desktop.
Save AmaxJ/849c766926fd08433196 to your computer and use it in GitHub Desktop.
Game damage engine
from random import randrange
class Player:
def __init__(self, name):
self.health = 100
self.name = name
self.dam = 0
def low_damage (self):
roll = randrange(10)
hp = self.health
if roll <= 3:
self.health -= 3
elif roll <= 7:
self.health -= 5
else:
self.health -= 7
self.dam = hp - self.health
def med_damage (self):
roll = randrange(10)
hp = self.health
if roll <= 3:
self.health -= 10
elif roll <= 7:
self.health -= 20
else:
self.health -= 30
self.dam = hp - self.health
def high_damage (self):
roll = randrange(10)
hp = self.health
if roll <= 3:
self.health -= 25
elif roll <= 7:
self.health -= 48
else:
self.health -= 66
self.dam = hp - self.health
def dead_test(self):
if self.health <= 0:
print 'You died!'
print """ _____ _
| ___| | |
| |__ _ __ __| |
| __| '_ \ / _` |
| |__| | | | (_| |
\____/_| |_|\__,_|"""
quit(0)
print """
| _ \
| | | |__ _ _ __ ___ __ _ __ _ ___
| | | / _` | '_ ` _ \ / _` |/ _` |/ _ \
| |/ / (_| | | | | | | (_| | (_| | __/
|___/ \__,_|_| |_| |_|\__,_|\__, |\___|
__/ |
|___/
_____ _ _ _
|_ _| | | /\| |/\ /\| |/\
| | ___ ___| |_ ___ _ __ \ ` ' / \ ` ' /
| |/ _ \/ __| __/ _ \ '__|_ _|_ _|
| | __/\__ \ || __/ | / , . \ / , . \
\_/\___||___/\__\___|_| \/|_|\/ \/|_|\/
"""
player1 = Player(raw_input('enter a name for your player: '))
print 'player name is {0}' .format(player1.name)
print '{0}\'s health is: {1}' .format(player1.name, player1.health)
raw_input('press enter to do low damage: ')
player1.low_damage()
print 'You did {0} damage!' .format(player1.dam)
print '{0}\'s health is now {1}.' .format(player1.name, player1.health)
raw_input('press enter to do medium damage: ')
player1.med_damage()
print 'You did {0} damage!' .format(player1.dam)
print '{0}\'s health is now {1}.' .format(player1.name, player1.health)
raw_input('press enter to do high damage: ')
player1.high_damage()
print 'You did {0} damage!' .format(player1.dam)
print '{0}\'s health is now {1}.' .format(player1.name, player1.health)
player1.dead_test()
raw_input('press enter to do high damage: ')
player1.high_damage()
print 'You did {0} damage!' .format(player1.dam)
print '{0}\'s health is now {1}.' .format(player1.name, player1.health)
player1.dead_test()
raw_input('press enter to do high damage: ')
player1.high_damage()
print 'You did {0} damage!' .format(player1.dam)
print '{0}\'s health is now {1}.' .format(player1.name, player1.health)
player1.dead_test()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment