-
Notifications
You must be signed in to change notification settings - Fork 0
/
bomberbot.py
41 lines (35 loc) · 1.24 KB
/
bomberbot.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
import socket
from bot import Bot
class BomberBot():
def __init__(self):
try:
self.conectar("pyBot", "54654654645")
self.controlConexion()
except Exception as e:
print(e)
def conectar(self, user, token):
self.socket_cliente = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.socket_cliente.connect(("bomberbot.com", 5000))
bienvenida = self.socket_cliente.recv(1279)
print(bienvenida)
self.socket_cliente.send("%s,%s" % (user, token))
self.conectado = True
def controlConexion(self):
response = None
while self.conectado:
print("turno")
server_message = self.socket_cliente.recv(511)
message = server_message.split(";")
print(message[0])
if message[0] == "EMPEZO":
bot = Bot(message[2][0])
bot.update_map(message[1])
elif message[0] == "TURNO":
print("turno: %s" % message[1])
bot.update_map(message[2])
msg = bot.move()
self.socket_cliente.send(msg)
elif message[0] == "PERDIO":
print("perdi :(")
if __name__ == "__main__":
BomberBot()