mirror of
				https://github.com/LDDestroier/CC/
				synced 2025-10-31 15:32:59 +00:00 
			
		
		
		
	Added timeout exit for player 2
This commit is contained in:
		
							
								
								
									
										75
									
								
								tron.lua
									
									
									
									
									
								
							
							
						
						
									
										75
									
								
								tron.lua
									
									
									
									
									
								
							| @@ -198,12 +198,12 @@ local tsv = function(visible) | |||||||
| 	end | 	end | ||||||
| end | end | ||||||
|  |  | ||||||
| local deepCopy | local copyTable | ||||||
| deepCopy = function(tbl, ...) | copyTable = function(tbl, ...) | ||||||
| 	local output = {} | 	local output = {} | ||||||
| 	for k,v in pairs(tbl) do | 	for k,v in pairs(tbl) do | ||||||
| 		if type(v) == "table" then | 		if type(v) == "table" then | ||||||
| 			output[k] = deepCopy(v) | 			output[k] = copyTable(v) | ||||||
| 		else | 		else | ||||||
| 			output[k] = v | 			output[k] = v | ||||||
| 		end | 		end | ||||||
| @@ -214,15 +214,12 @@ deepCopy = function(tbl, ...) | |||||||
| 	return output | 	return output | ||||||
| end | end | ||||||
|  |  | ||||||
| grid = deepCopy(initGrid) | grid = copyTable(initGrid) | ||||||
|  |  | ||||||
| local you = 1 | local you, nou = 1, 2 | ||||||
| local nou = 2 |  | ||||||
|  |  | ||||||
| local keysDown = {} | local keysDown, netKeysDown = {}, {} | ||||||
| local netKeysDown = {} | local lastDirectionPressed, netLastDirectionPressed | ||||||
| local lastDirectionPressed |  | ||||||
| local netLastDirectionPressed |  | ||||||
|  |  | ||||||
| -- the scrolling of the screen | -- the scrolling of the screen | ||||||
| local scrollX = 0 | local scrollX = 0 | ||||||
| @@ -344,6 +341,44 @@ local images = { | |||||||
| 			"   8    0  00  0 0     7", | 			"   8    0  00  0 0     7", | ||||||
| 			"   8    00000000 0888877", | 			"   8    00000000 0888877", | ||||||
| 		}, | 		}, | ||||||
|  | 	}, | ||||||
|  | 	timeout = { | ||||||
|  | 		{ | ||||||
|  | 			"", | ||||||
|  | 			"
", | ||||||
|  | 			" 
", | ||||||
|  | 			" ", | ||||||
|  | 			" ", | ||||||
|  | 			"   ", | ||||||
|  | 			"   ", | ||||||
|  | 			"   
 ", | ||||||
|  | 			"    ", | ||||||
|  | 			"   ", | ||||||
|  | 		}, | ||||||
|  | 		{ | ||||||
|  | 			"00000000000000ff0000000f", | ||||||
|  | 			"0fff000fff000ff0ff00f000", | ||||||
|  | 			"0ffffffffff00f000f00ffff", | ||||||
|  | 			" fffff0ffff00f0f0f00ffff", | ||||||
|  | 			" 000ff000000000f00000000", | ||||||
|  | 			"   000000f0ff0ff0000f", | ||||||
|  | 			"   0f00f0ffffff000f00", | ||||||
|  | 			"   0ff0f0ffffff7f0f0", | ||||||
|  | 			"   0ffff0ffffff7f0f0", | ||||||
|  | 			"   000000000000ff000", | ||||||
|  | 		}, | ||||||
|  | 		{ | ||||||
|  | 			"ffffffffffffff00fffffff0", | ||||||
|  | 			" 0f0fff0f0ffffffffffffff", | ||||||
|  | 			" 0f0ff00f00ffffffffff000", | ||||||
|  | 			" 0f0fffffffffffffffffff0", | ||||||
|  | 			" fffffffffffffffffffffff", | ||||||
|  | 			"   ffffff0f00f00ffff0", | ||||||
|  | 			"   ffffff0f00f0ffffff", | ||||||
|  | 			"   ff0fff0f00f0fffff", | ||||||
|  | 			"   ffffff0ffff0fffff", | ||||||
|  | 			"   fffffffffffffffff", | ||||||
|  | 		}, | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| for k,v in pairs(images) do | for k,v in pairs(images) do | ||||||
| @@ -419,10 +454,6 @@ for k,v in pairs(control) do | |||||||
| 	revControl[v] = k | 	revControl[v] = k | ||||||
| end | end | ||||||
|  |  | ||||||
| -- keeps track of where you are |  | ||||||
| local gamemode = "" |  | ||||||
|  |  | ||||||
|  |  | ||||||
| local gridFore, gridBack | local gridFore, gridBack | ||||||
| if squareGrid then | if squareGrid then | ||||||
| 	gridFore = { | 	gridFore = { | ||||||
| @@ -894,12 +925,19 @@ end | |||||||
|  |  | ||||||
| local game = function() | local game = function() | ||||||
| 	local outcome | 	local outcome | ||||||
| 	local p, np | 	local p, np, timeoutID, tID, evt | ||||||
| 	while true do | 	while true do | ||||||
| 		if isHost then | 		if isHost then | ||||||
| 			sleep(gameDelay) | 			sleep(gameDelay) | ||||||
| 		else | 		else | ||||||
| 			os.pullEvent("move_tick") | 			timeoutID = os.startTimer(3) | ||||||
|  | 			repeat | ||||||
|  | 				evt, tID = os.pullEvent() | ||||||
|  | 			until evt == "move_tick" or (evt == "timer" and tID == timeoutID) | ||||||
|  | 			if evt == "timer" then | ||||||
|  | 				parallel.waitForAny(function() imageAnim(images.timeout) end, waitForKey) | ||||||
|  | 				return | ||||||
|  | 			end | ||||||
| 		end | 		end | ||||||
| 		p = player[you] | 		p = player[you] | ||||||
| 		np = player[nou] | 		np = player[nou] | ||||||
| @@ -960,7 +998,7 @@ local networking = function() | |||||||
| 						isHost = false | 						isHost = false | ||||||
| 						gamename = msg.gameID | 						gamename = msg.gameID | ||||||
| 						gameDelay = tonumber(msg.gameDelay) or gameDelayInit | 						gameDelay = tonumber(msg.gameDelay) or gameDelayInit | ||||||
| 						grid = msg.grid or deepCopy(initGrid) | 						grid = msg.grid or copyTable(initGrid) | ||||||
| 						player = msg.player or player | 						player = msg.player or player | ||||||
| 					else | 					else | ||||||
| 						isHost = true | 						isHost = true | ||||||
| @@ -1028,7 +1066,7 @@ local startGame = function() | |||||||
| 	lastDirectionPressed = nil | 	lastDirectionPressed = nil | ||||||
| 	netLastDirectionPressed = nil | 	netLastDirectionPressed = nil | ||||||
| 	gameDelay = gameDelayInit | 	gameDelay = gameDelayInit | ||||||
|     grid = deepCopy(initGrid) | 	grid = copyTable(initGrid) | ||||||
| 	player = resetPlayers() | 	player = resetPlayers() | ||||||
| 	you, nou = 1, 2 | 	you, nou = 1, 2 | ||||||
| 	gamename = "" | 	gamename = "" | ||||||
| @@ -1046,7 +1084,6 @@ local startGame = function() | |||||||
| 		grid = initGrid | 		grid = initGrid | ||||||
| 	}) | 	}) | ||||||
| 	rVal = parallel.waitForAny( pleaseWait, networking ) | 	rVal = parallel.waitForAny( pleaseWait, networking ) | ||||||
|      -- give time for skynet |  | ||||||
| 	sleep(0.1) | 	sleep(0.1) | ||||||
| 	if rVal == 2 then | 	if rVal == 2 then | ||||||
| 		startCountdown() | 		startCountdown() | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 LDDestroier
					LDDestroier