浏览代码

moving prototype

Phil 2 年之前
父节点
当前提交
5a7e21cdb6
共有 2 个文件被更改,包括 33 次插入12 次删除
  1. 4 4
      config.store
  2. 29 8
      lib/tron.rb

+ 4 - 4
config.store

@@ -1,5 +1,5 @@
 ---
-name: <name>
-password: <password>
-host: <host>
-port: <port>
+name: TST
+password: tst
+host: 94.45.236.110
+port: 4000

+ 29 - 8
lib/tron.rb

@@ -1,7 +1,7 @@
 require 'socket'
 require 'yaml/store'
 
-config = YAML::Store.new "config.store"
+config = YAML::Store.new "../config.store"
 config.transaction do
   $name =  config["name"]
   $password = config["password"]
@@ -12,38 +12,59 @@ end
 
 def connect(host,port)
   $sock = TCPSocket.new(host,port)
-  msg = sock.read()
-  puts msg
-  parse(msg)
+  #join($name,$password)
+  while line = $sock.gets
+    puts line
+    parse(line)
+  end
 end
 
 def join(name,password)
-
+  send("join",name,password)
 end
 
 def parse(message)
   parts = message.split('|')
   case parts[0]
   when "error"
+    puts "error occured " + parts[1]
 
   when "game"
+    $gameW = parts[1]
+    $gameH = parts[2]
+    $id = parts[3]
+    
   when "pos"
   when "tick"
+    decide()
   when "die"
+
   when "message"
 
   when "win", "lose"
-
-
+    reset()
+  when "motd"
+    join($name,$password)
+  end
 end
 
 def decide()
-
+  send("up")
 end
 
 def chat(message)
 
 end
 
+def reset()
+end
+
+def send(msg,*param)
+
+  snd = "#{msg}|#{param.join("|")}"
+  $sock.puts(snd)
+  puts(snd)
+end
+
 connect($host,$port)