/* Handle game over / scoreboard display */ /// <summary> /// Invoked by GameOver() in GameEngine.cs. /// </summary> public void ShowScoreboardMenu(ScoreboardStatePacket scorePacket, TeamRole myTeamRole) { foreach (ScoreboardSlot slot in mScoreboardSlots) { if (slot.teamRole == TeamRole.PurpleRunner) { slot.roleUsername.text = "Runner - " + scorePacket.PurpleRunner.Username; slot.summary.text = "Flags Captured: " + scorePacket.PurpleRunner.FlagsCaptured + "\n"; slot.summary.text += "Deaths: " + scorePacket.PurpleRunner.Deaths; } else if (slot.teamRole == TeamRole.PurpleBuilder) { slot.roleUsername.text = "Builder - " + scorePacket.PurpleBuilder.Username; slot.summary.text = "Blocks Placed: " + scorePacket.PurpleBuilder.BlocksPlaced + "\n"; } else if (slot.teamRole == TeamRole.YellowRunner) { slot.roleUsername.text = "Runner - " + scorePacket.YellowRunner.Username; slot.summary.text = "Flags Captured: " + scorePacket.YellowRunner.FlagsCaptured + "\n"; slot.summary.text += "Deaths: " + scorePacket.YellowRunner.Deaths; } else if (slot.teamRole == TeamRole.YellowBuilder) { slot.roleUsername.text = "Builder - " + scorePacket.YellowBuilder.Username; slot.summary.text = "Blocks Placed: " + scorePacket.YellowBuilder.BlocksPlaced + "\n"; } } mScoreboardMenu_purpleScoreText.text = scorePacket.PurpleRunner.FlagsCaptured.ToString(); mScoreboardMenu_yellowScoreText.text = scorePacket.YellowRunner.FlagsCaptured.ToString(); Team myTeam = Common.GetTeam(myTeamRole); bool isPurpleWin = (scorePacket.PurpleRunner.FlagsCaptured > scorePacket.YellowRunner.FlagsCaptured); bool isYellowWin = (scorePacket.YellowRunner.FlagsCaptured > scorePacket.PurpleRunner.FlagsCaptured); bool isTie = (scorePacket.PurpleRunner.FlagsCaptured == scorePacket.YellowRunner.FlagsCaptured); if (isTie) { mScoreboardMenu_youWinLoseText.text = "Draw Game!"; } else if (myTeam == Team.Purple && isPurpleWin || myTeam == Team.Yellow && isYellowWin) { mScoreboardMenu_youWinLoseText.text = "You Win!"; } else { mScoreboardMenu_youWinLoseText.text = "You Lose!"; } mScoreboardMenu_returnToLobbyBut.gameObject.SetActive(mIsHost); SwitchMenu(mScoreboardMenu); }
private void ReceiveScoreboardState() { // Only client can receive a score update. if (mIsHost) { return; } while (mNwMgr.PacketQueue.HasPacket <ScoreboardStatePacket>()) { mPacket = mNwMgr.PacketQueue.GetNextPacket <ScoreboardStatePacket>(); } }
/// <summary> /// Start the scoreboard to listen for game events (e.g. flag captured). Scores will be reset. If the host, /// this obj will handle synchronizing the server's truth score with the clients. /// </summary> /// /// <param name="playersInfo">Information about the current players</param> /// <param name="nwMgr">Network manager from the game engine</param> /// <param name="isHost">Am I the server?</param> public void Run(LobbyStatePacket playersInfo, NetworkManager nwMgr, bool isHost, TeamRole myTeamRole) { mNwMgr = nwMgr; mIsHost = isHost; mMyTeam = Common.GetTeam(myTeamRole); mMyRole = Common.GetRole(myTeamRole); mPacket = new ScoreboardStatePacket(true); mPacket.PurpleRunner.Username = playersInfo.Usernames[(int)TeamRole.PurpleRunner]; mPacket.PurpleBuilder.Username = playersInfo.Usernames[(int)TeamRole.PurpleBuilder]; mPacket.YellowRunner.Username = playersInfo.Usernames[(int)TeamRole.YellowRunner]; mPacket.YellowBuilder.Username = playersInfo.Usernames[(int)TeamRole.YellowBuilder]; mIsRunning = true; }