-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame.py
More file actions
150 lines (128 loc) · 4.05 KB
/
game.py
File metadata and controls
150 lines (128 loc) · 4.05 KB
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
144
145
146
147
148
149
import threading
import time
import sys
from src.structures import *
from src.clan import *
from src.input import *
from pickle import dump
import copy
import os
leader = 0
while leader==0 :
leader=int(input("Select 1 for King and 2 for Queen\n"))
x=0
m = 25
n = 25
myClan = Clan(m, n,3,3,3 , 2 , 1,leader)
replay_list2 = [myClan,]
myMap = Map(m, n)
myMap.draw(myClan)
replay_list1 = [myMap,]
for x in range (1,3):
terminate = False
if(x>1):
myClan = Clan(m, n,3,3,3 , 2 , 1,leader)
myMap = Map(m, n)
#while x!=1 or x!=2 or x!=3 :
# x=int(input("Select 1 for Easy,2 for Normal or 3 for Hard\n"))
if x==1:
myMap.setupMaplvl1()
# break
elif x==2:
myMap.setupMaplvl2()
# break
elif x==3:
myMap.setupMaplvl3()
# break
myMap.draw(myClan)
# render loop
status = ''
flag=0
replay_list1.append(myMap)
replay_list2.append(myClan)
def background():
global myClan
global replay_list1
global replay_list2
global myMap
global status
global flag
global terminate
while True:
# move troops
myClan.moveTroops(myMap)
myMap.fireCanons(myClan)
time.sleep(0.5)
if terminate:
break
threading1 = threading.Thread(target=background)
threading1.daemon = True
threading1.start()
while True:
old_status = status
flag=myMap.checkWinLoss(myClan)
if flag == 1:
print("You won!")
terminate = True
break
elif flag == -1:
print("You lost.")
terminate = True
break
elif flag == 0:
pass
command = input_to(Get())
myClan.king.move(command, myMap)
if command == 'q':
terminate = True
break
elif command == ' ' and leader==1:
if myClan.king.alive:
status = "King attacks with sword!"
elif command == ' ' and leader==2:
if myClan.king.alive:
status = "Queen launches arrows!"
elif command == 'x' and leader==1:
if myClan.king.alive:
status = "King attacks with axe!"
elif command == 'h':
if myClan.useHealSpell() :
status = ('Heal spell used')
else:
status = "No more heal spells"
elif command == 'j':
if myClan.useRageSpell():
status = "Rage spell used"
else:
status = "No more rage spells"
elif command == '1' or command == '2' or command == '3' :
if myClan.spawn(command, myMap):
status = "Barbarian spawned at spawnpoint " + command
else:
status = "No more barbarian spawns available"
elif command =='4' or command =='5' or command =='6':
if myClan.spawn(command, myMap):
status = "Archer spawned at spawnpoint " + command
else:
status = "No more archer spawns available"
elif command =='7' or command =='8' or command =='9':
if myClan.spawn(command, myMap):
status = "Balloon spawned at spawnpoint " + command
else:
status = "No more balloon spawns available"
#for saving the replay
replay_list1.append(copy.deepcopy(myMap))
replay_list2.append(copy.deepcopy(myClan))
os.system('clear')
myMap.draw(myClan)
# print status texts
if(old_status==status):
print("\n"+status)
threading1.join()
with open("replays/maps", 'wb') as f:
dump(replay_list1, f)
with open("replays/clans", 'wb') as f:
dump(replay_list2, f)
os.system('clear')
myMap.draw(myClan)
print("Game Over")