1
0
mirror of https://github.com/LDDestroier/CC/ synced 2025-10-14 15:17:43 +00:00

Update tron

This commit is contained in:
LDDestroier
2018-11-13 23:29:59 -05:00
committed by GitHub
parent 5d4d78e89b
commit d79bf6cf5e

27
tron
View File

@@ -16,6 +16,9 @@ local grid = {
edgecol = "0"
}
local you = 1
local nou = 2
local scrollX = 0
local scrollY = 0
@@ -120,9 +123,6 @@ local toblit = {
[colors.black] = "f"
}
local you = 1
local nou = 2
local control = {
up = keys.up,
down = keys.down,
@@ -245,6 +245,8 @@ end
local render = function()
local p = player[you]
drawGrid(scrollX + scrollAdjX, scrollY + scrollAdjY)
term.setCursorPos(1,1)
term.write(gamename)
end
local deepCopy
@@ -481,9 +483,9 @@ local sendInfo = function(gameID)
end
local game = function()
local p = player[you]
local outcome
os.pullEvent("new_game")
local p = player[you]
while true do
p.putTrail = not keysDown[control.release]
if keysDown[control.left] and p.direction ~= 0 then
@@ -535,14 +537,26 @@ local networking = function()
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
local time = os.time()
if msg.new < time then
you, nou = nou, you
gamename = msg.gameID
--error("okay what")
end
you, nou = nou, you
modem.transmit(modemID, modemID, {
player = player,
gameID = gamename,
new = (msg.new < time) and (os.time() + 10) or (os.time() - 10)
})
waitingForGame = false
os.queueEvent("new_game", gameID)
elseif msg.gameID == gamename then
player[nou] = msg.player[nou]
end
end
end
end
@@ -558,6 +572,7 @@ while true do
for i = 1, 32 do
gamename = gamename .. string.char(math.random(1,126))
end
waitingForGame = true
modem.transmit(modemID, modemID, {
player = player,
gameID = gamename,