|
@@ -14,7 +14,6 @@ def connect(host, port)
|
|
|
$sock = TCPSocket.new(host, port)
|
|
$sock = TCPSocket.new(host, port)
|
|
|
# join($name,$password)
|
|
# join($name,$password)
|
|
|
while line = $sock.gets
|
|
while line = $sock.gets
|
|
|
- puts line
|
|
|
|
|
parse(line)
|
|
parse(line)
|
|
|
end
|
|
end
|
|
|
end
|
|
end
|
|
@@ -30,6 +29,7 @@ def parse(message)
|
|
|
puts "error occured " + parts[1]
|
|
puts "error occured " + parts[1]
|
|
|
|
|
|
|
|
when "game"
|
|
when "game"
|
|
|
|
|
+ puts message
|
|
|
$gameW = parts[1].to_i
|
|
$gameW = parts[1].to_i
|
|
|
$gameH = parts[2].to_i
|
|
$gameH = parts[2].to_i
|
|
|
$id = parts[3].to_i
|
|
$id = parts[3].to_i
|
|
@@ -43,14 +43,18 @@ def parse(message)
|
|
|
$myY = parts[3].to_i
|
|
$myY = parts[3].to_i
|
|
|
end
|
|
end
|
|
|
when "tick"
|
|
when "tick"
|
|
|
|
|
+ puts message
|
|
|
decide()
|
|
decide()
|
|
|
when "die"
|
|
when "die"
|
|
|
|
|
+ puts message
|
|
|
parts.drop(1).each { |player| cleanup(player) }
|
|
parts.drop(1).each { |player| cleanup(player) }
|
|
|
when "message"
|
|
when "message"
|
|
|
-
|
|
|
|
|
|
|
+ puts message
|
|
|
when "win", "lose"
|
|
when "win", "lose"
|
|
|
|
|
+ puts message
|
|
|
reset()
|
|
reset()
|
|
|
when "motd"
|
|
when "motd"
|
|
|
|
|
+ puts message
|
|
|
join($name, $password)
|
|
join($name, $password)
|
|
|
end
|
|
end
|
|
|
|
|
|
|
@@ -173,17 +177,31 @@ end
|
|
|
|
|
|
|
|
def decide()
|
|
def decide()
|
|
|
|
|
|
|
|
|
|
+ lastdirection = $direction
|
|
|
# check area left
|
|
# check area left
|
|
|
left = check_area("left")
|
|
left = check_area("left")
|
|
|
# check area right
|
|
# check area right
|
|
|
right = check_area("right")
|
|
right = check_area("right")
|
|
|
|
|
|
|
|
if check_front > -1 && !$dead.include?(check_front) || check_area("front") < 10
|
|
if check_front > -1 && !$dead.include?(check_front) || check_area("front") < 10
|
|
|
|
|
+
|
|
|
if left > right
|
|
if left > right
|
|
|
$direction = turn_direction("left")
|
|
$direction = turn_direction("left")
|
|
|
else
|
|
else
|
|
|
- $direction = turn_direction("right")
|
|
|
|
|
|
|
+ if left == right
|
|
|
|
|
+ case $lastturn
|
|
|
|
|
+ when "left"
|
|
|
|
|
+ $direction = turn_direction("right")
|
|
|
|
|
+ $lastturn = "right"
|
|
|
|
|
+ when "right"
|
|
|
|
|
+ $direction = turn_direction("left")
|
|
|
|
|
+ $lastturn = "left"
|
|
|
|
|
+ end
|
|
|
|
|
+ else
|
|
|
|
|
+ $direction = turn_direction("right")
|
|
|
|
|
+ end
|
|
|
end
|
|
end
|
|
|
|
|
+
|
|
|
puts "#{left} > #{right}: turned #{$direction}"
|
|
puts "#{left} > #{right}: turned #{$direction}"
|
|
|
end
|
|
end
|
|
|
# $direction = new_direction()
|
|
# $direction = new_direction()
|
|
@@ -192,6 +210,11 @@ def decide()
|
|
|
# end
|
|
# end
|
|
|
# end
|
|
# end
|
|
|
|
|
|
|
|
|
|
+ if check_front > -1 && !$dead.include?(check_front)
|
|
|
|
|
+ chat("To honor the Fallen")
|
|
|
|
|
+ $direction = lastdirection
|
|
|
|
|
+ end
|
|
|
|
|
+
|
|
|
send("move", $direction)
|
|
send("move", $direction)
|
|
|
end
|
|
end
|
|
|
|
|
|
|
@@ -218,6 +241,7 @@ end
|
|
|
def initmap()
|
|
def initmap()
|
|
|
$map = Array.new($gameH) { Array.new($gameW) { -1 } }
|
|
$map = Array.new($gameH) { Array.new($gameW) { -1 } }
|
|
|
$direction = "up"
|
|
$direction = "up"
|
|
|
|
|
+ $lastturn = "left"
|
|
|
$dead = Array.new(0)
|
|
$dead = Array.new(0)
|
|
|
|
|
|
|
|
chat("Rock and Stone!")
|
|
chat("Rock and Stone!")
|