-
Notifications
You must be signed in to change notification settings - Fork 0
/
command.py
64 lines (49 loc) · 2.18 KB
/
command.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
import requests, json
from consts import ProduceType, TechType
class Client:
def __init__(self, key: str, url: str):
self.url = url + "/api/"
self.key = key
def getTemplate(self, component: str):
return json.loads(requests.get(self.url + component, params={"key": self.key}).text)
def getBoard(self):
return self.getTemplate("board")
def getCities(self):
return self.getTemplate("cities")
def getArmies(self):
return self.getTemplate("armies")
def getWorkers(self):
return self.getTemplate("workers")
def getResources(self):
return self.getTemplate("resources")
def getCurrentTurn(self):
return self.getTemplate("current_player")
def getPlayers(self):
return self.getTemplate("players")
def getPlayerIndex(self):
return self.getTemplate("player_index")
def produce(self, typ: ProduceType, srcTup: tuple):
params = {"key": self.key, "type": typ.value, "x": srcTup[0], "y": srcTup[1]}
x = json.loads(requests.post(self.url + "produce", params=params).text)
#assert x["error"] == None
if x["error"] !=None:
print(x)
print(params)
def produceTech(self, techType: TechType):
params = {"key": self.key, "type": techType.value}
x = json.loads(requests.post(self.url + "technology", params=params).text)
#print(x)
def moveWorker(self, srcTup: tuple, toTup: tuple):
params = {"key": self.key, "srcX": srcTup[0], "srcY": srcTup[1], "dstX": toTup[0], "dstY": toTup[1]}
x = json.loads(requests.post(self.url + "move_worker", params=params).text)
def moveArmy(self, srcTup: tuple, toTup: tuple):
params = {"key": self.key, "srcX": srcTup[0], "srcY": srcTup[1], "dstX": toTup[0], "dstY": toTup[1]}
requests.post(self.url + "move_Army", params=params)
def endTurn(self):
requests.post(self.url + "end_turn", params={"key": self.key})
def setName(self, name: str):
requests.post(self.url + "set_name", params={"key": self.key, "name": name})
"""
x = Client("secret0","http://localhost:8080")
print(x.getPlayerIndex())
"""