mirror of
https://github.com/LDDestroier/CC/
synced 2025-10-31 23:43:00 +00:00
Update tron
This commit is contained in:
50
tron
50
tron
@@ -1,4 +1,8 @@
|
|||||||
local scr_x, scr_y = term.getSize()
|
local scr_x, scr_y = term.getSize()
|
||||||
|
local modemID = 712
|
||||||
|
local gamename = ""
|
||||||
|
|
||||||
|
waitingForGame = true
|
||||||
|
|
||||||
local grid = {
|
local grid = {
|
||||||
x1 = -80,
|
x1 = -80,
|
||||||
@@ -361,6 +365,7 @@ local evt
|
|||||||
local keysDown = {}
|
local keysDown = {}
|
||||||
|
|
||||||
local getInput = function()
|
local getInput = function()
|
||||||
|
os.pullEvent("new_game")
|
||||||
while true do
|
while true do
|
||||||
evt = {os.pullEvent()}
|
evt = {os.pullEvent()}
|
||||||
if lockInput then
|
if lockInput then
|
||||||
@@ -459,6 +464,7 @@ end
|
|||||||
local game = function()
|
local game = function()
|
||||||
local p = player[you]
|
local p = player[you]
|
||||||
local outcome
|
local outcome
|
||||||
|
os.pullEvent("new_game")
|
||||||
while true do
|
while true do
|
||||||
p.putTrail = not keysDown[control.release]
|
p.putTrail = not keysDown[control.release]
|
||||||
if keysDown[control.left] and p.direction ~= 0 then
|
if keysDown[control.left] and p.direction ~= 0 then
|
||||||
@@ -488,6 +494,7 @@ local game = function()
|
|||||||
scrollAdjY = scrollAdjY * 0.8
|
scrollAdjY = scrollAdjY * 0.8
|
||||||
|
|
||||||
outcome = moveTick()
|
outcome = moveTick()
|
||||||
|
sendInfo(gameID)
|
||||||
|
|
||||||
if outcome == "end" then
|
if outcome == "end" then
|
||||||
return
|
return
|
||||||
@@ -502,6 +509,38 @@ local game = function()
|
|||||||
end
|
end
|
||||||
|
|
||||||
local decision
|
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
|
while true do
|
||||||
decision = titleScreen()
|
decision = titleScreen()
|
||||||
@@ -509,7 +548,16 @@ while true do
|
|||||||
if decision == "start" then
|
if decision == "start" then
|
||||||
trail = {}
|
trail = {}
|
||||||
resetPlayers()
|
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
|
elseif decision == "demo" then
|
||||||
parallel.waitForAny(getInput, gridDemo)
|
parallel.waitForAny(getInput, gridDemo)
|
||||||
elseif decision == "exit" then
|
elseif decision == "exit" then
|
||||||
|
|||||||
Reference in New Issue
Block a user