Commits

makestory committed 45ee1f5

init flow for snake

Comments (0)

Files changed (1)

examples/makestory/musashi.rb

 @http = Net::HTTP.new("50.56.97.47", 80)
 @room_id = ARGV[0] || 0
 @user_name = ARGV[1] || 'Musashi'
+@direction_hash = {0 => 'left',1 => 'up',2 => 'right',3 => 'down'}
 
 def map
   request = Net::HTTP::Get.new("/room/#{@room_id}/map")
   @next = rand(3)
 end
 
+map
 add
+while @info['status'] == 'waitplayer'
+  p 'Waiting Player...' 
+  info
+  sleep 0.5
+end
+puts 'Game started'
 while @info['status'] == 'running'
- sleep 0.2
- turn
+  think
+  turn
+  puts "#{@direction_hash[@next]}"
 end
+
+puts "Total Round #{@info['round']}"
+puts "Score:"
+@info['snakes'].each do |s|
+  puts " #{s['name']}[#{s['alive'] ? 'alive' : 'dead'}]: #{s['body'].size} "
+end
+puts 'Game Over'