Update tron

This commit is contained in:
LDDestroier 2018-11-13 23:01:14 -05:00 committed by GitHub
parent 3873ba0e2e
commit 81b28e6015
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 49 additions and 1 deletions

50
tron
View File

@ -1,4 +1,8 @@
local scr_x, scr_y = term.getSize()
local modemID = 712
local gamename = ""
waitingForGame = true
local grid = {
x1 = -80,
@ -361,6 +365,7 @@ local evt
local keysDown = {}
local getInput = function()
os.pullEvent("new_game")
while true do
evt = {os.pullEvent()}
if lockInput then
@ -459,6 +464,7 @@ end
local game = function()
local p = player[you]
local outcome
os.pullEvent("new_game")
while true do
p.putTrail = not keysDown[control.release]
if keysDown[control.left] and p.direction ~= 0 then
@ -488,6 +494,7 @@ local game = function()
scrollAdjY = scrollAdjY * 0.8
outcome = moveTick()
sendInfo(gameID)
if outcome == "end" then
return
@ -502,6 +509,38 @@ local game = function()
end
local decision
local modem = peripheral.find("modem")
if modem then
modem.open(modemID)
else
error("You need a modem.")
end
local sendInfo = function(gameID)
modem.transmit(modemID, modemID, {
player = player,
gameID = gameID
})
end
local networking = function()
local evt, side, channel, repchannel, msg, distance
while true do
evt, side, channel, repchannel, msg, distance = os.pullEvent("modem_message")
if channel == modemID and repchannel == modemID and type(msg) == "table" then
if type(msg.player) == "table" and type(msg.gameID) == "string" then
if waitingForGame and (type(msg.new) == "number") then
if msg.new < os.time() then
you, nou = you, nou
gamename = msg.gameID
end
waitingForGame = false
os.queueEvent("new_game", gameID)
end
end
end
end
end
while true do
decision = titleScreen()
@ -509,7 +548,16 @@ while true do
if decision == "start" then
trail = {}
resetPlayers()
parallel.waitForAny(getInput, game)
gamename = ""
for i = 1, 32 do
gamename = gamename .. string.char(math.random(1,126))
end
modem.transmit(modemID, modemID, {
player = player,
gameID = gamename,
new = os.time()
})
parallel.waitForAny(getInput, game, networking)
elseif decision == "demo" then
parallel.waitForAny(getInput, gridDemo)
elseif decision == "exit" then