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 | ||||
|  | ||||
| local deepCopy | ||||
| deepCopy = function(tbl, ...) | ||||
| local copyTable | ||||
| copyTable = function(tbl, ...) | ||||
| 	local output = {} | ||||
| 	for k,v in pairs(tbl) do | ||||
| 		if type(v) == "table" then | ||||
| 			output[k] = deepCopy(v) | ||||
| 			output[k] = copyTable(v) | ||||
| 		else | ||||
| 			output[k] = v | ||||
| 		end | ||||
| @@ -214,15 +214,12 @@ deepCopy = function(tbl, ...) | ||||
| 	return output | ||||
| end | ||||
|  | ||||
| grid = deepCopy(initGrid) | ||||
| grid = copyTable(initGrid) | ||||
|  | ||||
| local you = 1 | ||||
| local nou = 2 | ||||
| local you, nou = 1, 2 | ||||
|  | ||||
| local keysDown = {} | ||||
| local netKeysDown = {} | ||||
| local lastDirectionPressed | ||||
| local netLastDirectionPressed | ||||
| local keysDown, netKeysDown = {}, {} | ||||
| local lastDirectionPressed, netLastDirectionPressed | ||||
|  | ||||
| -- the scrolling of the screen | ||||
| local scrollX = 0 | ||||
| @@ -344,6 +341,44 @@ local images = { | ||||
| 			"   8    0  00  0 0     7", | ||||
| 			"   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 | ||||
| @@ -419,10 +454,6 @@ for k,v in pairs(control) do | ||||
| 	revControl[v] = k | ||||
| end | ||||
|  | ||||
| -- keeps track of where you are | ||||
| local gamemode = "" | ||||
|  | ||||
|  | ||||
| local gridFore, gridBack | ||||
| if squareGrid then | ||||
| 	gridFore = { | ||||
| @@ -894,12 +925,19 @@ end | ||||
|  | ||||
| local game = function() | ||||
| 	local outcome | ||||
| 	local p, np | ||||
| 	local p, np, timeoutID, tID, evt | ||||
| 	while true do | ||||
| 		if isHost then | ||||
| 			sleep(gameDelay) | ||||
| 		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 | ||||
| 		p = player[you] | ||||
| 		np = player[nou] | ||||
| @@ -960,7 +998,7 @@ local networking = function() | ||||
| 						isHost = false | ||||
| 						gamename = msg.gameID | ||||
| 						gameDelay = tonumber(msg.gameDelay) or gameDelayInit | ||||
| 						grid = msg.grid or deepCopy(initGrid) | ||||
| 						grid = msg.grid or copyTable(initGrid) | ||||
| 						player = msg.player or player | ||||
| 					else | ||||
| 						isHost = true | ||||
| @@ -1028,7 +1066,7 @@ local startGame = function() | ||||
| 	lastDirectionPressed = nil | ||||
| 	netLastDirectionPressed = nil | ||||
| 	gameDelay = gameDelayInit | ||||
|     grid = deepCopy(initGrid) | ||||
| 	grid = copyTable(initGrid) | ||||
| 	player = resetPlayers() | ||||
| 	you, nou = 1, 2 | ||||
| 	gamename = "" | ||||
| @@ -1046,7 +1084,6 @@ local startGame = function() | ||||
| 		grid = initGrid | ||||
| 	}) | ||||
| 	rVal = parallel.waitForAny( pleaseWait, networking ) | ||||
|      -- give time for skynet | ||||
| 	sleep(0.1) | ||||
| 	if rVal == 2 then | ||||
| 		startCountdown() | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 LDDestroier
					LDDestroier