-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcharacter.py
71 lines (57 loc) · 2.26 KB
/
character.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from random import *
class Character():
# Create a character
def __init__(self, char_name, char_description):
self.name = char_name
self.description = char_description
self.speech = None
def isEnemy(self):
return False
# Describe this character
def describe(self):
print( self.name + " is here!" )
print( self.description )
print("You can TALK to "+self.name)
# Set what this character will say when talked to
def set_speech(self, speech):
self.speech = speech
# Talk to this character
def talk(self):
if self.speech is not None:
print("[" + self.name + " says]: " + self.speech)
else:
print(self.name + " doesn't want to talk to you")
# Fight with this character
def fight(self, combat_item):
print(self.name + " doesn't want to fight with you")
return True
# Enemy Is A Sub Class of Character
class Enemy(Character):
# Constructor for enemy
def __init__(self, char_name, char_description):
super().__init__(char_name, char_description)
self.weaknesses = [] # Array for multiple weaknesses
self.enemyHealth = randrange(20,40)
def isEnemy(self):
return True
# set_weakness expects to be passed an array
def set_weaknesses(self, newWeaknesses):
self.weaknesses = newWeaknesses
# Returns enemyHealth
# If weapon matches weakness, then extra damage
def fight(self, combat_item):
if combat_item in self.weaknesses:
attack = randrange(1,7)+randrange(1,7)+randrange(1,7)+5
print("-=-=-=-=-=- You fend " + self.name + " off with the " + combat_item + ". -=-=-=-=-=-")
if attack > 12:
print("-=-=-=-=-=- It's super effective!")
print("-=-=-=-=-=- A -"+str(attack)+" attack!")
else:
attack = randrange(1,7)
print("********** You use the " + combat_item + " for a -"+str(attack)+" attack! **********")
self.enemyHealth -= attack
return self.enemyHealth
def enemyAttack(self):
damage = randrange(1,7) + randrange(1,7)
print("\n!@#$%^&*!@#$%^&* "+self.name+" attacks you! -"+str(damage)+" HP! *&^%$#@!*&^%$#@!\n")
return damage