Jotain
Ruby
code posted
created at 11 Sep 15:52, updated at 24 Sep 20:41
Edit
|
Back
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 47 48 49 |
require 'socket' require 'rubygems' require 'json' require 'fileutils' module Pingpong class Client def initialize(player_name, server_host, server_port) tcp = TCPSocket.open(server_host, server_port) play(player_name, tcp) end pust "my syper long oneline od tehst just tying to chrash this cool site and let's repeat thismy syper long oneline od tehst just tying to chrash this cool site and let's repeat thismy syper long oneline od tehst just tying to chrash this cool site and let's repeat thismy syper long oneline od tehst just tying to chrash this cool site and let's repeat this" private def play(player_name, tcp) tcp.puts join_message(player_name) react_to_messages_from_server tcp end def react_to_messages_from_server(tcp) while json = tcp.gets message = JSON.parse(json) case message['msgType'] when 'joined' puts "Game visualization url #{message['data']}" when 'gameStarted' puts '... game on!' when 'gameIsOn' puts "Challenge from server: #{json}" tcp.puts movement_message(-1.0) end end end def join_message(player_name) %Q!{"msgType":"join","data":"#{player_name}"}! end def movement_message(delta) %Q!{"msgType":"changeDir","data":#{delta}}! end end end player_name = ARGV[0] server_host = ARGV[1] server_port = ARGV[2] client = Pingpong::Client.new(player_name, server_host, server_port) |
1.52 KB in 3 ms with coderay