Difference between revisions of "CombatSimulation.py"
From WLCS
Line 46: | Line 46: | ||
warrior = Creature() | warrior = Creature() | ||
warrior.hitPoints = WARRIOR_HP | warrior.hitPoints = WARRIOR_HP | ||
− | warrior. | + | warrior.strength = WARRIOR_STR |
warrior.skill = WARRIOR_SKILL | warrior.skill = WARRIOR_SKILL | ||
warrior.armorClass = WARRIOR_AC | warrior.armorClass = WARRIOR_AC |
Latest revision as of 13:59, 25 April 2013
# This class will run a combat simulation using the Weapon and Creature classes
from creature import *
#Warrior
WARRIOR_NAME = "Gnusto Frotz";
WARRIOR_TYPE = "valiant warrior";
WARRIOR_PRONOUN = "his";
WARRIOR_HP = 50;
WARRIOR_STR = 10;
WARRIOR_SKILL = 15;
WARRIOR_AC = 5;
#monster creature
MONSTER_NAME = "Schmoo";
MONSTER_TYPE = "gruesome monster";
MONSTER_PRONOUN = "its";
MONSTER_HP = 50;
MONSTER_STR = 15;
MONSTER_SKILL = 10;
MONSTER_AC = 7;
#Monster's claws weapon
CLAWS_DAMAGE_MOD = 3;
CLAWS_NAME = "claws";
CLAWS_HIT = "slashes";
CLAWS_MISS = "swipes at but misses";
#Warrior's sword weapon
SWORD_DAMAGE_MOD = 5;
SWORD_NAME = "sword";
SWORD_HIT = "stabs";
SWORD_MISS = "swings at but misses";
# Create the warrior's weapon (sword)
sword = Weapon(SWORD_NAME, SWORD_DAMAGE_MOD, SWORD_HIT, SWORD_MISS);
#Create the monster's weapon (claws)
claws = Weapon()
claws.damageModifier = CLAWS_DAMAGE_MOD
claws.name = CLAWS_NAME
claws.hitVerb = CLAWS_HIT
claws.missVerb = CLAWS_MISS
#Create the warrior
warrior = Creature()
warrior.hitPoints = WARRIOR_HP
warrior.strength = WARRIOR_STR
warrior.skill = WARRIOR_SKILL
warrior.armorClass = WARRIOR_AC
warrior.name = WARRIOR_NAME
warrior.type = WARRIOR_TYPE
warrior.pronoun = WARRIOR_PRONOUN
# Create the monster
monster = Creature(MONSTER_NAME, MONSTER_TYPE, MONSTER_PRONOUN, MONSTER_HP, MONSTER_STR, MONSTER_SKILL, MONSTER_AC)
# Arm the creatures with their weapons
monster.weapon = claws
warrior.weapon = sword
# While both creatures are still alive...
while monster.isAlive() and warrior.isAlive():
# The monster tries to attack the warrior
if monster.tryToAttack(warrior.armorClass):
# If the monster hit, the warrior takes damage
print(monster.constructHitString(warrior))
warrior.takeDamage(monster.calcHitDamage())
else:
print(monster.constructMissString(warrior))
print(warrior.name + ":" + str(warrior.hitPoints) + " HP")
print(monster.name + ":" + str(monster.hitPoints) + " HP")
print()
# If the warrior dies, break out of this loop
if warrior.isAlive() == False:
break
# The warrior tries to attack the monster
if warrior.tryToAttack(monster.armorClass):
# If the warrior hit, the monster takes damage
print(warrior.constructHitString(monster))
monster.takeDamage(warrior.calcHitDamage())
else:
print(warrior.constructMissString(monster))
print(warrior.name + ":" + str(warrior.hitPoints) + " HP")
print(monster.name + ":" + str(monster.hitPoints) + " HP")
print()
# Figure out whose alive and dead (good example of the ? : operator)
if warrior.isAlive() == True:
alive = warrior
dead = monster
else:
alive = monster
dead = warrior
# print out a message to indicate the outcome of the battle.
print(dead.name + " dies. ")
print(alive.name + " is victorious!")