-
Notifications
You must be signed in to change notification settings - Fork 0
/
object.py
143 lines (117 loc) · 4.61 KB
/
object.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# -*- coding: utf-8 -*-
import random
# Här har vi ett slimemonster
slimenr = 0
class Slime(object):
def __init__(self):
global slimenr
slimenr = slimenr + 1
self.name = "Slime"
self.strength = 2 + int(random.random()*11)
self.defence = 0
self.hp = 25 + int(random.random()*11)
def fight(self, hero):
while self.hp > 0 and hero.hp > 0:
if int(random.random() * 101) < 90:
if hero.weapon.ability == "fire":
self.hp = self.hp - 10 - hero.weapon.dmg
print ("Damage done: " + str(10 + hero.weapon.dmg)
+ ", hp left: " + str(self.hp) + ". Keep going!")
else:
self.hp = self.hp - 1 - int(hero.weapon.dmg*0.2)
print ("Damage done: " + str(1 + int(hero.weapon.dmg*0.2))
+ ", hp left: " + str(self.hp)
+ ". It doesn't seem to go that well")
else:
print "You missed"
if self.hp > 0 and hero.hp > 0:
# Ifall den redan dött ska vi ej fortsätta här!
if int(random.random() * 101) < 90:
hero.hp = hero.hp - self.strength
print ("The acid burns your skinn! You have " + str(hero.hp)
+ " hp left!")
else:
print "The monster missed"
print ('The fight is going on... you can either stay and fight'
+ ', change your weapon or run away! If you want to stay'
+ ' and fight, type "fight". If you want to change your weapon'
+', type "weapon". If you want to run away from the fight, '
+ 'type "run"')
while True:
choice = raw_input("What do you choose to do?")
if choice == "fight":
break
# "break" gör att man kommer ut ur befintlig loop (bara i
# while och for loop)
elif choice == "weapon":
hero.showinventory()
choice = raw_input("What weapon do you want to use?")
hero.setweapon(choice)
break
elif choice == "run":
return
# "return" gör slut på nuvarande funktion. och den kan skicka
# tillbaka ett värde
else:
print "Wrong choice"
if self.hp > hero.hp:
print "You are dead!"
else:
print "You won!"
# Här har vi en slimeking
slimeking = 0
class Slimeking(Slime):
def __init__(self):
global slimekingnr
slimekingnr = slimekingnr + 1
self.name = "Slimeking"
self.strength = 10 + int(random.random() * 11)
self.defence = 0
self.hp = 60 + int(random.random() * 11)
# Här har vi vapen
class Weapon(object):
def __init__(self, name, dmg, ability):
self.name = name
self.dmg = dmg
self.ability = ability
excalibur = Weapon("Excalibur", 20, "stonecutter")
glowstick = Weapon("Glowstick", 15, "fire")
icicle = Weapon("Icicle", 7, "freeze")
dullknife = Weapon("Dull knife", 5, "tickle")
sabre = Weapon("Sabre", 10, "slice")
# Här har vi en hero
class Hero(object):
def __init__(self, name, strength, defence, hp):
self.name = name
self.strength = strength
self.defence = defence
self.hp = hp
self.inventory = [dullknife]
self.weapon = dullknife
def showinventory(self):
print
def setweapon(self, weaponname):
self.weapon = "Excalibur"
def __str__(self):
return(self.name + ": Strength:" + str(self.strength)
+ " Defence:" + str(self.defence) + " Hp:" + str(self.hp))
def attack(self, what): pass
hannes = Hero("Hannes", 5, 5, 20)
pauline = Hero("Pauline", 30, 30, 30)
thomas = Hero("Thomas", 100, 100, 100)
bastian = Hero("Bastian", 30, 50, 30)
testslime = Slime()
me = Hero("Me", 30, 30, 30)
testslime.fight(me)
skeletonnr = 0
class skeleton(object):
def __init__(self):
global skeletonnr
skeletonnr=skeletonnr + 1
self.name = "Skeleton: " + str(skeletonnr)
self.strength = 10 + int(random.random()*11)
self.defence = 10 + int(random.random()*11)
self.hp = 30 + int(random.random()*11)
[Weapon("Excalibur", 20, "stonecutter"),
Weapon("Glowstick", 15, "fire"),
Weapon("Icicle", 7, "freeze")]