联网推进48,增加准备按钮和开房按钮
This commit is contained in:
@@ -93,6 +93,8 @@ return{
|
|||||||
wsError="WebSocket error: ",
|
wsError="WebSocket error: ",
|
||||||
waitNetTask="Connecting, please wait",
|
waitNetTask="Connecting, please wait",
|
||||||
|
|
||||||
|
createRoomTooFast="Create room too fast!",
|
||||||
|
createRoomSuccessed="Room successfully created!",
|
||||||
joinRoom="joined the room.",
|
joinRoom="joined the room.",
|
||||||
leaveRoom="left the room.",
|
leaveRoom="left the room.",
|
||||||
notReady="Waiting",
|
notReady="Waiting",
|
||||||
@@ -244,10 +246,14 @@ return{
|
|||||||
},
|
},
|
||||||
net_rooms={
|
net_rooms={
|
||||||
fresh="Fresh",
|
fresh="Fresh",
|
||||||
|
new="New room",
|
||||||
join="Join",
|
join="Join",
|
||||||
up="↑",
|
up="↑",
|
||||||
down="↓",
|
down="↓",
|
||||||
},
|
},
|
||||||
|
net_game={
|
||||||
|
ready="Ready",
|
||||||
|
},
|
||||||
net_chat={
|
net_chat={
|
||||||
send="Send",
|
send="Send",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -95,6 +95,8 @@ return{
|
|||||||
-- wsError="WebSocket error: ",
|
-- wsError="WebSocket error: ",
|
||||||
-- waitNetTask="Connecting, please wait",
|
-- waitNetTask="Connecting, please wait",
|
||||||
|
|
||||||
|
-- createRoomTooFast="Create room too fast!",
|
||||||
|
-- createRoomSuccessed="Room successfully created!",
|
||||||
-- joinRoom="joined the room.",
|
-- joinRoom="joined the room.",
|
||||||
-- leaveRoom="left the room.",
|
-- leaveRoom="left the room.",
|
||||||
-- notReady="Waiting",
|
-- notReady="Waiting",
|
||||||
@@ -222,10 +224,14 @@ return{
|
|||||||
},
|
},
|
||||||
net_rooms={
|
net_rooms={
|
||||||
-- fresh="Fresh",
|
-- fresh="Fresh",
|
||||||
|
-- new="New room",
|
||||||
-- join="Join",
|
-- join="Join",
|
||||||
up="↑",
|
up="↑",
|
||||||
down="↓",
|
down="↓",
|
||||||
},
|
},
|
||||||
|
net_game={
|
||||||
|
-- ready="Ready",
|
||||||
|
},
|
||||||
net_chat={
|
net_chat={
|
||||||
-- send="Send",
|
-- send="Send",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -93,6 +93,8 @@ return{
|
|||||||
wsError="WebSocket error: ",
|
wsError="WebSocket error: ",
|
||||||
waitNetTask="Conectando, aguarde",
|
waitNetTask="Conectando, aguarde",
|
||||||
|
|
||||||
|
-- createRoomTooFast="Create room too fast!",
|
||||||
|
-- createRoomSuccessed="Room successfully created!",
|
||||||
joinRoom="Entrou a sala.",
|
joinRoom="Entrou a sala.",
|
||||||
leaveRoom="Saiu da sala.",
|
leaveRoom="Saiu da sala.",
|
||||||
-- notReady="Waiting",
|
-- notReady="Waiting",
|
||||||
@@ -244,10 +246,14 @@ return{
|
|||||||
},
|
},
|
||||||
net_rooms={
|
net_rooms={
|
||||||
fresh="Fresh",
|
fresh="Fresh",
|
||||||
|
-- new="New room",
|
||||||
-- join="Join",
|
-- join="Join",
|
||||||
up="↑",
|
up="↑",
|
||||||
down="↓",
|
down="↓",
|
||||||
},
|
},
|
||||||
|
net_game={
|
||||||
|
-- ready="Ready",
|
||||||
|
},
|
||||||
net_chat={
|
net_chat={
|
||||||
send="Mandar",
|
send="Mandar",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -96,6 +96,8 @@ return{
|
|||||||
-- wsError="WebSocket error: ",
|
-- wsError="WebSocket error: ",
|
||||||
-- waitNetTask="Connecting, please wait",
|
-- waitNetTask="Connecting, please wait",
|
||||||
|
|
||||||
|
-- createRoomTooFast="Create room too fast!",
|
||||||
|
-- createRoomSuccessed="Room successfully created!",
|
||||||
-- joinRoom="joined the room.",
|
-- joinRoom="joined the room.",
|
||||||
-- leaveRoom="left the room.",
|
-- leaveRoom="left the room.",
|
||||||
-- notReady="Waiting",
|
-- notReady="Waiting",
|
||||||
@@ -224,10 +226,14 @@ return{
|
|||||||
},
|
},
|
||||||
net_rooms={
|
net_rooms={
|
||||||
-- fresh="Fresh",
|
-- fresh="Fresh",
|
||||||
|
-- new="New room",
|
||||||
-- join="Join",
|
-- join="Join",
|
||||||
up="↑",
|
up="↑",
|
||||||
down="↓",
|
down="↓",
|
||||||
},
|
},
|
||||||
|
net_game={
|
||||||
|
-- ready="Ready",
|
||||||
|
},
|
||||||
net_chat={
|
net_chat={
|
||||||
-- send="Send",
|
-- send="Send",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -40,6 +40,9 @@ return{
|
|||||||
diffPassword="字不认识?",
|
diffPassword="字不认识?",
|
||||||
|
|
||||||
ranks={"菜","可","好","强","您"},
|
ranks={"菜","可","好","强","您"},
|
||||||
|
|
||||||
|
createRoomTooFast="手痒要开这么多房间?",
|
||||||
|
createRoomSuccessed="创好了",
|
||||||
notReady="没有准备好",
|
notReady="没有准备好",
|
||||||
beReady="准备好了",
|
beReady="准备好了",
|
||||||
|
|
||||||
|
|||||||
@@ -94,6 +94,8 @@ return{
|
|||||||
wsError="WS错误: ",
|
wsError="WS错误: ",
|
||||||
waitNetTask="正在连接,请稍候",
|
waitNetTask="正在连接,请稍候",
|
||||||
|
|
||||||
|
createRoomTooFast="创建房间太快啦,等等吧",
|
||||||
|
createRoomSuccessed="创建房间成功!",
|
||||||
joinRoom="进入房间",
|
joinRoom="进入房间",
|
||||||
leaveRoom="离开房间",
|
leaveRoom="离开房间",
|
||||||
notReady="等待中",
|
notReady="等待中",
|
||||||
@@ -245,10 +247,14 @@ return{
|
|||||||
},
|
},
|
||||||
net_rooms={
|
net_rooms={
|
||||||
fresh="刷新",
|
fresh="刷新",
|
||||||
|
new="创建房间",
|
||||||
join="加入",
|
join="加入",
|
||||||
up="↑",
|
up="↑",
|
||||||
down="↓",
|
down="↓",
|
||||||
},
|
},
|
||||||
|
net_game={
|
||||||
|
ready="准备",
|
||||||
|
},
|
||||||
net_chat={
|
net_chat={
|
||||||
send="发送",
|
send="发送",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -452,6 +452,7 @@ function scene.draw()
|
|||||||
end
|
end
|
||||||
scene.widgetList={
|
scene.widgetList={
|
||||||
textBox,
|
textBox,
|
||||||
|
WIDGET.newKey{name="ready",x=640,y=440,w=200,h=80,color="yellow",font=40,code=pressKey("space"),hide=function()return playing or PLAYERS[1].ready end},
|
||||||
WIDGET.newKey{name="hideChat",fText="...",x=410,y=40,w=60,font=35,code=switchChat},
|
WIDGET.newKey{name="hideChat",fText="...",x=410,y=40,w=60,font=35,code=switchChat},
|
||||||
WIDGET.newKey{name="quit",fText="X",x=870,y=40,w=60,font=40,code=pressKey"escape"},
|
WIDGET.newKey{name="quit",fText="X",x=870,y=40,w=60,font=40,code=pressKey"escape"},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,41 @@ local min=math.min
|
|||||||
local rooms
|
local rooms
|
||||||
local scrollPos,selected
|
local scrollPos,selected
|
||||||
local lastfreshTime
|
local lastfreshTime
|
||||||
|
local lastCreateRoomTime=0
|
||||||
|
|
||||||
|
local function task_enterRoom(task)
|
||||||
|
local time=0
|
||||||
|
while true do
|
||||||
|
coroutine.yield()
|
||||||
|
local wsconn,connErr=client.poll(task)
|
||||||
|
if wsconn then
|
||||||
|
WSCONN=wsconn
|
||||||
|
loadGame("netBattle",true,true)
|
||||||
|
LOG.print(text.wsSuccessed,"warn")
|
||||||
|
return
|
||||||
|
elseif connErr then
|
||||||
|
LOG.print(text.wsFailed..": "..connErr,"warn")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
time=time+1
|
||||||
|
if time>360 then
|
||||||
|
LOG.print(text.wsFailed..": "..text.httpTimeout,"message")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local function enterRoom(roomID)
|
||||||
|
coroutine.yield()
|
||||||
|
wsConnect(
|
||||||
|
task_enterRoom,
|
||||||
|
PATH.socket..PATH.onlinePlay..
|
||||||
|
"?email="..urlEncode(USER.email)..
|
||||||
|
"&token="..urlEncode(USER.access_token)..
|
||||||
|
"&id="..urlEncode(roomID)..
|
||||||
|
"&conf="..urlEncode(dumpBasicConfig())
|
||||||
|
-- "&password="..urlEncode(password),
|
||||||
|
)
|
||||||
|
end
|
||||||
local function task_fetchRooms(task)
|
local function task_fetchRooms(task)
|
||||||
local time=0
|
local time=0
|
||||||
while true do
|
while true do
|
||||||
@@ -29,7 +63,7 @@ local function task_fetchRooms(task)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local function task_createRooms(task)
|
local function task_createRoom(task)
|
||||||
local time=0
|
local time=0
|
||||||
while true do
|
while true do
|
||||||
coroutine.yield()
|
coroutine.yield()
|
||||||
@@ -37,7 +71,8 @@ local function task_createRooms(task)
|
|||||||
if response then
|
if response then
|
||||||
local res=json.decode(response.body)
|
local res=json.decode(response.body)
|
||||||
if response.code==200 and res.message=="OK"then
|
if response.code==200 and res.message=="OK"then
|
||||||
LOG.print("OK")
|
LOG.print(text.createRoomSuccessed)
|
||||||
|
TASK.newNet(enterRoom,res.room.id)
|
||||||
else
|
else
|
||||||
LOG.print(text.httpCode..response.code..": "..res.message,"warn")
|
LOG.print(text.httpCode..response.code..": "..res.message,"warn")
|
||||||
end
|
end
|
||||||
@@ -53,27 +88,6 @@ local function task_createRooms(task)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local function task_enterRoom(task)
|
|
||||||
local time=0
|
|
||||||
while true do
|
|
||||||
coroutine.yield()
|
|
||||||
local wsconn,connErr=client.poll(task)
|
|
||||||
if wsconn then
|
|
||||||
WSCONN=wsconn
|
|
||||||
loadGame("netBattle",true,true)
|
|
||||||
LOG.print(text.wsSuccessed,"warn")
|
|
||||||
return
|
|
||||||
elseif connErr then
|
|
||||||
LOG.print(text.wsFailed..": "..connErr,"warn")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
time=time+1
|
|
||||||
if time>360 then
|
|
||||||
LOG.print(text.wsFailed..": "..text.httpTimeout,"message")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
local function fresh()
|
local function fresh()
|
||||||
lastfreshTime=TIME()
|
lastfreshTime=TIME()
|
||||||
rooms=nil
|
rooms=nil
|
||||||
@@ -107,18 +121,23 @@ function scene.keyDown(k)
|
|||||||
fresh()
|
fresh()
|
||||||
end
|
end
|
||||||
elseif k=="n"then
|
elseif k=="n"then
|
||||||
httpRequest(
|
if TIME()-lastCreateRoomTime>26 then
|
||||||
task_createRooms,
|
httpRequest(
|
||||||
PATH.http..PATH.onlinePlay.."/classic",
|
task_createRoom,
|
||||||
"POST",
|
PATH.http..PATH.onlinePlay.."/classic",
|
||||||
{["Content-Type"]="application/json"},
|
"POST",
|
||||||
json.encode{
|
{["Content-Type"]="application/json"},
|
||||||
email=USER.email,
|
json.encode{
|
||||||
access_token=USER.access_token,
|
email=USER.email,
|
||||||
room_name="Test Room "..math.random(26,626),
|
access_token=USER.access_token,
|
||||||
room_password=nil,
|
room_name="Test Room "..math.random(26,626),
|
||||||
}
|
room_password=nil,
|
||||||
)
|
}
|
||||||
|
)
|
||||||
|
lastCreateRoomTime=TIME()
|
||||||
|
else
|
||||||
|
LOG.print(text.createRoomTooFast,"warn")
|
||||||
|
end
|
||||||
elseif k=="escape"then
|
elseif k=="escape"then
|
||||||
SCN.back()
|
SCN.back()
|
||||||
elseif rooms and #rooms>0 then
|
elseif rooms and #rooms>0 then
|
||||||
@@ -141,15 +160,7 @@ function scene.keyDown(k)
|
|||||||
LOG.print("Can't enter private room now")
|
LOG.print("Can't enter private room now")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
wsConnect(
|
enterRoom(rooms[selected].id)
|
||||||
task_enterRoom,
|
|
||||||
PATH.socket..PATH.onlinePlay..
|
|
||||||
"?email="..urlEncode(USER.email)..
|
|
||||||
"&token="..urlEncode(USER.access_token)..
|
|
||||||
"&id="..urlEncode(rooms[selected].id)..
|
|
||||||
"&conf="..urlEncode(dumpBasicConfig())
|
|
||||||
-- "&password="..urlEncode(password),
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -162,7 +173,7 @@ end
|
|||||||
|
|
||||||
function scene.draw()
|
function scene.draw()
|
||||||
gc.setColor(1,1,1,.26)
|
gc.setColor(1,1,1,.26)
|
||||||
gc.arc("fill","pie",440,620,60,-1.5708,-1.5708+1.2566*(TIME()-lastfreshTime))
|
gc.arc("fill","pie",240,620,60,-1.5708,-1.5708+1.2566*(TIME()-lastfreshTime))
|
||||||
if rooms then
|
if rooms then
|
||||||
gc.setColor(1,1,1)
|
gc.setColor(1,1,1)
|
||||||
if #rooms>0 then
|
if #rooms>0 then
|
||||||
@@ -193,7 +204,8 @@ function scene.draw()
|
|||||||
end
|
end
|
||||||
|
|
||||||
scene.widgetList={
|
scene.widgetList={
|
||||||
WIDGET.newKey{name="fresh", x=440,y=620,w=140,h=140,font=40,code=fresh,hide=function()return TIME()-lastfreshTime<1.26 end},
|
WIDGET.newKey{name="fresh", x=240,y=620,w=140,h=140,font=40,code=fresh,hide=function()return TIME()-lastfreshTime<1.26 end},
|
||||||
|
WIDGET.newKey{name="new", x=440,y=620,w=140,h=140,font=25,code=pressKey("n")},
|
||||||
WIDGET.newKey{name="join", x=640,y=620,w=140,h=140,font=40,code=pressKey"return",hide=function()return not rooms end},
|
WIDGET.newKey{name="join", x=640,y=620,w=140,h=140,font=40,code=pressKey"return",hide=function()return not rooms end},
|
||||||
WIDGET.newKey{name="up", x=840,y=585,w=140,h=70,font=40,code=pressKey"up",hide=function()return not rooms end},
|
WIDGET.newKey{name="up", x=840,y=585,w=140,h=70,font=40,code=pressKey"up",hide=function()return not rooms end},
|
||||||
WIDGET.newKey{name="down", x=840,y=655,w=140,h=70,font=40,code=pressKey"down",hide=function()return not rooms end},
|
WIDGET.newKey{name="down", x=840,y=655,w=140,h=70,font=40,code=pressKey"down",hide=function()return not rooms end},
|
||||||
|
|||||||
Reference in New Issue
Block a user