Created
February 14, 2019 02:26
-
-
Save timbledum/bcb00816090fd47d8c6ab8e7131b4420 to your computer and use it in GitHub Desktop.
Wizard example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Weapon: | |
def __init__(self, types): | |
self.types = types | |
def damageDealt(self): | |
if self.types == "dagger": | |
damage = 4 | |
elif self.types == "axe": | |
damage = 6 | |
elif self.types == "staff": | |
damage = 6 | |
elif self.types == "sword": | |
damage = 10 | |
else: | |
damage = 1 | |
class Armor: | |
def __init__(self, types): | |
self.types = types | |
def AC(self): | |
if self.types == "plate": | |
AC = 2 | |
elif self.types == "chain": | |
AC = 5 | |
elif self.types == "leather": | |
AC = 8 | |
else: | |
AC = 10 | |
class Wizard(): | |
def __init__(self, name): | |
self.name = name | |
self.health = 16 | |
self.spellPoints = 20 | |
self.weapon = None | |
self.armor = None | |
def wield(self, weapon): | |
weaponAllowed = ["dagger", "staff", "none"] | |
if weapon.types in weaponAllowed: | |
self.weapon = weapon | |
return self.name + " is now wielding a(n) " + self.weapon.types | |
else: | |
print("Weapon not allowed for this character class.") | |
def putOnArmor(self, armor): | |
armorAllowed = ["none"] | |
if armor.types in armorAllowed: | |
self.armor = armor | |
return self.name + "is now wearing " + self.armor.types | |
else: | |
print("Armor not allowed for this class.") | |
def main(): | |
plateMail = Armor("plate") | |
chainMail = Armor("chain") | |
sword = Weapon("sword") | |
staff = Weapon("staff") | |
axe = Weapon("axe") | |
gandalf = Wizard("Gandalf the Grey") | |
gandalf.wield(staff) | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment