This repository has been archived by the owner on Mar 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcombat.py
116 lines (102 loc) · 3.34 KB
/
combat.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
# -*- coding: utf-8 -*
from subprocess import call
from random import random
from random import uniform
from characters import *
#########################################################################################
def generateEnemy(ratio,lvl):
"""Function in order to generate enemies in a random way"""
ratio = ratio
random_tipe = random()
if random_tipe <= 0.2:
random_tipe = "warrior"
elif random_tipe <= 0.4:
random_tipe="guardian"
elif random_tipe <= 0.6:
random_tipe = "assassin"
elif random_tipe <= 0.8:
random_tipe = "mage"
elif random_tipe <= 1:
random_tipe = "antimage"
ene = enemy(ratio,lvl,random_tipe)
ene.lvluptipe()
return(ene)
def userattacks(user,enemy,totalDamageDone):
print ("Your turn!")
input()
damageDone = round(user.attvalues[2]*uniform(user.attvalues[7],1)*(1-(enemy.attvalues[3]/100)),2)
print ("You have done",damageDone,"damage points!")
totalDamageDone += damageDone
input()
return(totalDamageDone)
def enemyattacks(user,enemy,damageRecived):
print ("Your enemy attacks!")
input()
damageDone = round(enemy.attvalues[2]*uniform(enemy.attvalues[7],1)*(1-(user.attvalues[3]/100)),2)
damageRecived += damageDone
print ("You have recived",damageDone,"damage points!.","You have",(user.attvalues[0]-damageRecived), "HP left!")
input()
return(damageRecived)
#combate
def combate(user):
"""Function to make fights"""
call(["clear"])
turn_value = 100
enemy_turn = 0
user_turn = 0
damageDone = 0
totalDamageDone = 0
damageRecived = 0
fight = False
win = False
enemy=generateEnemy(1+random(),user.lvl)
print ("You have entered in combat with a " + enemy.tipe + "!\n")
while fight == False:
if totalDamageDone >= enemy.attvalues[0]:
input()
print ("You have defeated the " + enemy.tipe + "!")
print ("You have earned",enemy.exp,"exp points!")
user.exp += enemy.exp
user.checklvl()
input()
win = True
fight = True
elif damageRecived >= user.attvalues[0]:
print ("You are dead!")
input()
win = False
fight = True
else:
user_turn+=user.attvalues[4]
enemy_turn+=enemy.attvalues[4]
if user_turn >= turn_value and enemy_turn >= turn_value:
if user_turn > enemy_turn:
totalDamageDone = userattacks(user,enemy,totalDamageDone)
damageRecived = enemyattacks(user,enemy,damageRecived)
user_turn -= turn_value
enemy_turn -= turn_value
elif user_turn == enemy_turn:
user_random = random()
enemy_random = random()
if user_random > enemy_random:
totalDamageDone = userattacks(user,enemy,totalDamageDone)
damageRecived = enemyattacks(user,enemy,damageRecived)
user_turn -= turn_value
enemy_turn -= turn_value
else:
damageRecived = enemyattacks(user,enemy,damageRecived)
totalDamageDone = userattacks(user,enemy,totalDamageDone)
user_turn -= turn_value
enemy_turn -= turn_value
else:
damageRecived = enemyattacks(user,enemy,damageRecived)
totalDamageDone = userattacks(user,enemy,totalDamageDone)
user_turn -= turn_value
enemy_turn -= turn_value
elif user_turn >= turn_value and enemy_turn < turn_value:
totalDamageDone = userattacks(user,enemy,totalDamageDone)
user_turn -= turn_value
elif user_turn < turn_value and enemy_turn >= turn_value:
damageRecived = enemyattacks(user,enemy,damageRecived)
enemy_turn -= turn_value
return(win)