-- Main loop for the entire game

while true do
	displayManager.updateStatus("Waiting for Players")
	
	displayManager.updateTime(0)
	
	repeat
		wait(1)
	until Players.NumPlayers >= gameSettings.minimumPlayers
	
	-- Actual Intermission
	displayManager.updateStatus("Intermission")
	gameTimer:start(gameSettings.intermissionDuration)
	displayManager.trackTimer(gameTimer)
	gameTimer.finished:Wait()
	
	roundManager.prepareGame()
	displayManager.updateStatus("Round in Progress")
	
	-- Waits until the roundEnd event has fired before continuing the script 
	local endState = roundEnd.Event:Wait()
	
	-- Displays how the game ended to the player's GUI. Ex: Winner found, time up ...
	local resultString = roundManager.endRound()
	displayRoundResult:FireAllClients(resultString)
	
	-- Starts the end intermission. Will remove player weapons if still actively in game. 
	displayManager.updateTime(0)
	wait(gameSettings.transitionEnd)
	roundManager.endGameIntermission()
	
	-- Resets the game by moving players back into the lobby and clearing used variables 
	roundManager.resetGame()
	
end

