function GameManager.Initialize(Q)MapManager:SaveMap()end function GameManager.RunIntermission(Q)IntermissionRunning=true TimeManager:StartTimer(Configurations.MainGameConfig["\073\110\116\101\114\109\105\115\115\105\111\110 \068\117\114\097\116\105\111\110"])DisplayManager:StartIntermission()EnoughPlayers=Players.NumPlayers>=Configurations.MainGameConfig["\077\105\110\105\109\117\109 \080\108\097\121\101\114\115"]DisplayManager:UpdateTimerInfo(true,not EnoughPlayers)spawn(function()repeat if EnoughPlayers and Players.NumPlayers<Configurations.MainGameConfig["\077\105\110\105\109\117\109 \080\108\097\121\101\114\115"]then EnoughPlayers=false elseif not EnoughPlayers and Players.NumPlayers>=Configurations.MainGameConfig["\077\105\110\105\109\117\109 \080\108\097\121\101\114\115"]then EnoughPlayers=true end DisplayManager:UpdateTimerInfo(true,not EnoughPlayers)task.wait(.5)until IntermissionRunning==false end)task.wait(Configurations.MainGameConfig["\073\110\116\101\114\109\105\115\115\105\111\110 \068\117\114\097\116\105\111\110"])IntermissionRunning=false end function GameManager.StopIntermission(Q)DisplayManager:UpdateTimerInfo(false,false)DisplayManager:StopIntermission()end function GameManager.GameReady(Q)return Players.NumPlayers>=Configurations.MainGameConfig["\077\105\110\105\109\117\109 \080\108\097\121\101\114\115"]end function GameManager.StartRound(Q)TeamManager:ClearTeamScores()PlayerManager:AllowPlayerSpawn(true)PlayerManager:LoadPlayers()GameRunning=true PlayerManager:SetGameRunning(true)TimeManager:StartTimer(Configurations.MainGameConfig["\082\111\117\110\100 \068\117\114\097\116\105\111\110"])end function GameManager.Update(Q) end function GameManager.RoundOver(Q)local x=TeamManager:HasTeamWon()if x then DisplayManager:DisplayVictory(x)return true end if TimeManager:TimerDone()then if TeamManager:AreTeamsTied()then DisplayManager:DisplayVictory("\084\105\101")else x=TeamManager:GetWinningTeam()DisplayManager:DisplayVictory(x)end return true end return false end function GameManager.RoundCleanup(Q)PlayerManager:SetGameRunning(false)task.wait(Configurations.MainGameConfig["\069\110\100 \071\097\109\101 \087\097\105\116"])PlayerManager:AllowPlayerSpawn(false)PlayerManager:DestroyPlayers()DisplayManager:DisplayVictory(nil)TeamManager:ClearTeamScores()TeamManager:ShuffleTeams()MapManager:ClearMap()MapManager:LoadMap()end
-- Public Functions
function GameManager:Initialize()
	MapManager:SaveMap()
end

function GameManager:RunIntermission()
	IntermissionRunning = true
	TimeManager:StartTimer(Configurations.MainGameConfig["Intermission Duration"])
	DisplayManager:StartIntermission()
	EnoughPlayers = Players.NumPlayers >= Configurations.MainGameConfig["Minimum Players"]
	DisplayManager:UpdateTimerInfo(true, not EnoughPlayers)
	spawn(function()
		repeat
			if EnoughPlayers and Players.NumPlayers < Configurations.MainGameConfig["Minimum Players"] then
				EnoughPlayers = false
			elseif not EnoughPlayers and Players.NumPlayers >= Configurations.MainGameConfig["Minimum Players"] then
				EnoughPlayers = true
			end
			DisplayManager:UpdateTimerInfo(true, not EnoughPlayers)
			task.wait(0.5)
		until IntermissionRunning == false
	end)

	task.wait(Configurations.MainGameConfig["Intermission Duration"])
	IntermissionRunning = false
end

function GameManager:StopIntermission()
	--IntermissionRunning = false
	DisplayManager:UpdateTimerInfo(false, false)
	DisplayManager:StopIntermission()
end

function GameManager:GameReady()
	return Players.NumPlayers >= Configurations.MainGameConfig["Minimum Players"]
end

function GameManager:StartRound()
	TeamManager:ClearTeamScores()

	PlayerManager:AllowPlayerSpawn(true)
	PlayerManager:LoadPlayers()

	GameRunning = true
	PlayerManager:SetGameRunning(true)
	TimeManager:StartTimer(Configurations.MainGameConfig["Round Duration"])
end

function GameManager:Update()
	--TODO: Add custom custom game code here
end

function GameManager:RoundOver()
	local winningTeam = TeamManager:HasTeamWon()
	if winningTeam then
		DisplayManager:DisplayVictory(winningTeam)
		return true
	end
	if TimeManager:TimerDone() then
		if TeamManager:AreTeamsTied() then
			DisplayManager:DisplayVictory("Tie")
		else
			winningTeam = TeamManager:GetWinningTeam()
			DisplayManager:DisplayVictory(winningTeam)
		end
		return true
	end
	return false
end

function GameManager:RoundCleanup()
	PlayerManager:SetGameRunning(false)
	task.wait(Configurations.MainGameConfig["End Game Wait"])
	PlayerManager:AllowPlayerSpawn(false)
	PlayerManager:DestroyPlayers()
	DisplayManager:DisplayVictory(nil)
	TeamManager:ClearTeamScores()
	TeamManager:ShuffleTeams()
	MapManager:ClearMap()
	MapManager:LoadMap()
end
