-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathE) Battle Master.py
103 lines (78 loc) · 2.64 KB
/
E) Battle Master.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
import time, random
counter=0
player1=0
player2=0
def player1_win():
print("Orcs win the battle")
global player1 # Generally speakin Global keyword is the worst
player1+=1 # approach to interact with variable outside the
# function but its good to know how to do it
def player2_win(): # Better methods is using data structure like list or OOP (CLASS)
print("Humans win the battle")
global player2
player2+=1
while True:
print("""The war between Orcs and Humans rage on forever
"You are the new commander, you have 100 men which you have to
allocate to the apprioate position to win the war """)
#The try and except block in Python is used to catch and handle exceptions.
while True:
knight=input("how many Knights ?")
try:
int(knight)
break
except:
print("This is not a number")
while True:
farmer=input("how many Farmers ?")
try:
int(farmer)
break
except:
print("This is not a number")
while True:
defender=input("how many Defenders ?")
try:
int(defender)
break
except:
print("This is not a number")
tog=int(defender)+int(farmer)+int(knight)
if tog>100:
print("You have allocated over 100")
else:
print("You have",str(defender),"Defenders.You have",str(farmer),"Farmers and"
,str(knight),"Knights")
break
while True:
while True:
counter+=1
print("The battle rages on and on ..")
time.sleep(.5)
print("...")
time.sleep(.5)
print("...")
time.sleep(.5)
print("...")
if counter==3:
break
print("A victor has been decided")
x=random.randint(1,3)
time.sleep(x)
defender1=int(defender)+random.randint(1,15)
farmer1=int(farmer)+random.randint(1,10)
knight1=int(knight)+random.randint(1,15)
if defender1>=35 and farmer1>=15 and knight1>=50:
player2_win()
else:
player1_win()
print("Orc victory:"+str(player1)+" Human victory:"+str(player2))
counter=0
if player1==5:
print("""The Orcs has won the war. You have been defeated !!""")
break
if player2==5:
print("The Humans has won the war, congratulations !!")
break
input("Press enter to exit")
#https://github.com/Ninedeadeyes/15-mini-python-games-