-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path28_Challenge-BattleTime.py
109 lines (90 loc) · 2.33 KB
/
28_Challenge-BattleTime.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
# Day 28 on Replit: "Challenge: Battle Time"
import random, time, os
def rollDice(maxSides):
return random.randint(1, maxSides)
def health():
hp = (rollDice(6) * rollDice(8)) / 2 + 10
return hp
def strength():
s = (rollDice(6) * rollDice(8)) / 2 + 12
return s
def clearConsole(seconds):
time.sleep(seconds)
os.system("clear")
def damage(strength1, strength2):
if strength1 > strength2:
punch = (strength1 - strength2) + 1
else:
punch = (strength2 - strength1) + 1
return punch
def showStats(name, type, health, strength):
print(name, "the", type)
print("Health:", health)
print("Strength:", strength)
print("Battle time")
print()
# first warrior
name1 = input("Name your warrior: ")
type1 = input("Character type (Human, Elf, Wizard, Orc): ")
health1 = health()
strength1 = strength()
print("""
--------------------------
""")
# second warrior
name2 = input("Name your oponent: ")
type2 = input("Character type (Human, Elf, Wizard, Orc): ")
health2 = health()
strength2 = strength()
clearConsole(1)
print("Generating characters...")
clearConsole(1)
# show stats
showStats(name1, type1, health1, strength1)
print()
showStats(name2, type2, health2, strength2)
print()
print("The battle is about to begin...")
clearConsole(8)
# Battle
print("Battle time!")
round = 1
while True:
luck1 = rollDice(6)
luck2 = rollDice(6)
# who hit who
if luck1 > luck2:
print(name1, "wins the round", round)
print(name2, "takes a hit, with", damage(strength1, strength2), "damage")
health2 -= damage(strength1, strength2)
print()
elif luck1 < luck2:
print(name2, "wins the round", round)
print(name1, "takes a hit, with", damage(strength1, strength2), "damage")
health1 -= damage(strength1, strength2)
print()
else:
print("Draw")
print()
# show stats
showStats(name1, type1, health1, strength1)
print()
showStats(name2, type2, health2, strength2)
# someone die?
if health1 <= 0:
print()
print(name1, "the", type1, "loose.", name2, "the", type2, "win")
clearConsole(8)
break
elif health2 <= 0:
print()
print(name2, "the", type2, "loose.", name1, "the", type1, "win")
clearConsole(8)
break
else:
print()
print("They´re both standing for the next round!")
clearConsole(8)
round += 1
continue
print("The battle lasted", round, "rounds")