-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbomberbot.rb
More file actions
46 lines (39 loc) · 1.18 KB
/
bomberbot.rb
File metadata and controls
46 lines (39 loc) · 1.18 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
require 'socket'
require './Bot'
class BomberBot
def initialize
begin
self.conectar("rbBot", "984198716")
self.controlConexion()
rescue StandardError => e
puts e
end
end
def conectar user, token
@socket_cliente =TCPSocket::new('bomberbot.com', 5000)
bienvenida = @socket_cliente.recv(1279)
puts bienvenida
@socket_cliente.puts(user + "," + token)
@conectado = true
end
def controlConexion
response = nil
while @conectado do
puts "turno"
server_message = @socket_cliente.recv(511)
message = server_message.split(";")
if message[0] == "EMPEZO"
bot = Bot.new(message[2][0])
bot.update_map(message[1])
elsif message[0] == "TURNO"
puts "turno: " + message[1]
bot.update_map message[2]
msg = bot.move
@socket_cliente.puts(msg)
elsif message[0] == "PERDIO"
puts "perdi :("
end
end
end
end
bot = BomberBot.new