用这些东西可以用Lua实现画面菜单保持可选同时连接socket

function addBuffer1()                                       -- 循环检测和补充buffer1
    while true do                                                 -- 主循环
        if getColor(100, 100) ~= 0x000000 then  -- 如果没有buffer1
            touchDown(0, 100, 100);                       -- 释放buffer1
            touchUp(0);
        end
        mSleep(500);
        coroutine.yield();                                       -- 主动挂起自己
    end
end


function addBuffer2()                                       -- 循环检测和补充buffer2
    while true do                                                 -- 主循环
        if getColor(200, 200) ~= 0x000000 then  -- 如果没有buffer2
            touchDown(0, 200, 200);                       -- 释放buffer2
            touchUp(0);
        end
        mSleep(500);
        coroutine.yield();                                       -- 主动挂起自己
    end
end


function addBuffer3()                                       -- 循环检测和补充buffer3
    while true do                                                 -- 主循环
        if getColor(300, 300) ~= 0x000000 then  -- 如果没有buffer3
            touchDown(0, 300, 300);                       -- 释放buffer3
            touchUp(0);
        end
        mSleep(500);
        coroutine.yield();                                       -- 主动挂起自己
    end
end


function addBuffer4()                                       -- 循环检测和补充buffer4
    while true do                                                 -- 主循环
        if getColor(400, 400) ~= 0x000000 then  -- 如果没有buffer4
            touchDown(0, 400, 400);                       -- 释放buffer4
            touchUp(0);
        end
        mSleep(500);
        coroutine.yield();                                        -- 主动挂起自己
    end     
end


function addBuffer5()                                        -- 循环检测和补充buffer5
    while true do                                                  -- 主循环
         if getColor(500, 500) ~= 0x000000 then  -- 如果没有buffer5
            touchDown(0, 500, 500);                        -- 释放buffer5
            touchUp(0);
        end
        mSleep(500);
        coroutine.yield();                                        -- 主动挂起自己
    end
end


function kill()                                                     -- 循环打怪一直到怪物死亡
    while true do
        if getColor(600, 600) ~= 0x000000 then  -- 如果怪物没死
           touchDown(0, 1000, 1000);                    -- 释放一次技能
           touchUp(0);
        end
        mSleep(500);
        coroutine.yield();                                       -- 主动挂起自己
    end
end


function main()
    co1 = coroutine.create(addBuffer1);
    co2 = coroutine.create(addBuffer2);
    co3 = coroutine.create(addBuffer3);
    co4 = coroutine.create(addBuffer4);
    co5 = coroutine.create(addBuffer5);
    co6 = coroutine.create(kill);


    while true do
        coroutine.resume(co1);
        coroutine.resume(co2);
        coroutine.resume(co3);
        coroutine.resume(co4);
        coroutine.resume(co5);
        coroutine.resume(co6);
    end

end























LuaSocket和Lua Loop
Lua Loop: http://loop.luaforge.net/
LuaSocket: http://www.tecgraf.puc-rio.br/~diego/professional/luasocket/
感觉用这个写个简单的聊天服务器,或者写个文字Mud的网络小游戏挺方便
运行很简单,只要将LuaSocket放在下面代码说在的路径,然后用lua5.0运行。

   --  server端Lua代码
  
   socket  =  require( " socket " );
   host  =  host or  " localhost " ;
   port  =  port or  " 8383 " ;
   server  =  assert(socket.bind(host, port,  1000 ))
   server:settimeout(  0  )
  
   local client  =  {}
  print( " server: waiting for client connection " )
  local clientcount     =   0
  while   1   do
      control                 =  server:accept()
      
       if  control  ~=  nil then
          client[control]  =  control 
          clientcount         =  clientcount  +   1     
          print(  " 有新客户端连入链接总数为: "  .. clientcount ..  " \n "  )
      end
      
 
       for  user  in  pairs( client )  do
          command             =   user:receive();
           if  command  ~=  nil then 
              print( command )    
          end
      end
      
  end

   --  Client端Lua代码
   local MaxLink      =   220
   local socket     =  require( " socket " )
   local c  =  {}
  
   host  =  host or  " localhost "
   port  =  port or  8383
   if  arg then
       host  =  arg[ 1 ] or host
      port  =  arg[ 2 ] or port
  end
  print( " Attempting connection to host ' "  ..host..  " ' and port  "  ..port..  " " )
  for  i  =   1 , MaxLink  do
      c[i]  =  assert(socket.connect(host, port))
      c[i]:settimeout(  0  )
  end
 
  print( " Connected! Please type stuff (empty line to stop): " )
  =  io.read()
  for  i  =   1 , MaxLink  do
      assert( c[i]:send(l ..  " \n " ) )
      assert( c[i]:send( " test "  .. i ..  " \n " ) ) 
      print(  " test "  .. i ..  " \n "  )
  end
 
  while   1   do     
       for  i  =   1 , MaxLink  do
          command  =  c[i]:receive()
           if  command  ~=  nil then 
              print(command)
          end
      end
  end
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

FocusOneThread

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值