void Update() { //Write condition to end the game List <RpsAgent> activePlayers = players.FindAll(player => !(player.CardCount() == 0 || player.stars <= 0)); Debug.Log(activePlayers.Count); if (activePlayers.Count <= 1 && !matchEnded && players.Count >= 2) { matchEnded = true; List <RpsAgent> winners = players.FindAll(player => (player.CardCount() == 0 && player.stars >= 0)); List <RpsAgent> losers = players.FindAll(player => (player.stars <= 0)); EndMatchPanel panel = GameObject.Instantiate <EndMatchPanel>(endMatchPanelPrefab); panel.transform.SetParent(this.transform, false); string endingMessage = "Game ended! Here are the winners and losers \n"; endingMessage += "[WINNERS]: "; foreach (RpsAgent winner in winners) { endingMessage += winner.AgentName + ", "; } endingMessage += "\n [LOSERS]: "; foreach (RpsAgent loser in losers) { endingMessage += loser.AgentName + ", "; } panel.SetText(endingMessage); panel.OnReturnButtonClick += disconnect; panel.transform.SetParent(GameObject.FindObjectOfType <MatchPlayerUI>().transform, false); } }
public void DisplayHumanMatchUI(RpsAgent opponent) { ExitObserveMatch(); EndMatchPanel remnantPanel = this.GetComponentInChildren <EndMatchPanel>(); if (remnantPanel != null) { Destroy(remnantPanel.gameObject); } PrepareHumanHand(); PrepareNorthHand(opponent); SetMatchUIActive(true); }
public void DisplayObservationMatch(bool existsMatch, RpsAgent p1, RpsAgent p2) { if (!existsMatch) { EndMatchPanel panel = GameObject.Instantiate <EndMatchPanel>(endMatchPanelPrefab); panel.transform.SetParent(this.transform, false); panel.SetText("Unable to observe match."); } else { PrepareNorthHand(p2); PrepareSouthHand(p1); SetMatchUIActive(true); isSpectating = true; } }
public void ExitResultScreen() { humanHand.gameObject.SetActive(false); northHand.Hide(); SetMatchUIActive(false); if (player.stars == 0) { EndMatchPanel panel = GameObject.Instantiate <EndMatchPanel>(endMatchPanelPrefab); panel.transform.SetParent(this.transform, false); panel.SetText("You have no stars left! Wait until the game ends..."); } else if (player.stars > 0 && player.CardCount() == 0) { EndMatchPanel panel = GameObject.Instantiate <EndMatchPanel>(endMatchPanelPrefab); panel.transform.SetParent(this.transform, false); panel.SetText("You've won the game, wait until the end of collect your prize!"); } }
public void CreateResultScreen() { EndMatchPanel panel = GameObject.Instantiate <EndMatchPanel>(endMatchPanelPrefab); panel.transform.SetParent(this.transform, false); panel.OnReturnButtonClick += ExitResultScreen; switch (lastMatchResult) { case MatchResult.Lose: panel.SetText("You lost!\nYou have lost " + RpsAgent.DEFAULT_STAR_CHANGE + " stars..."); break; case MatchResult.Tie: panel.SetText("You tied!\nYou get to keep your wagered stars."); break; case MatchResult.Win: panel.SetText("You won!\nYou have gained " + RpsAgent.DEFAULT_STAR_CHANGE + " stars."); break; } }
// Update is called once per frame // If the parent doesn't have local player authority, return immediately. void Update() { if (matchResultAnimation > 0.0f) { if (Input.GetMouseButtonUp(0)) { matchResultAnimation = 0.0f; } matchResultAnimation -= Time.deltaTime; if (matchResultAnimation <= 0.0f) { CreateResultScreen(); } } if (isSpectating) { if (spectatingAfterEndTimer > 0.0f) { spectatingAfterEndTimer -= Time.deltaTime; if (spectatingAfterEndTimer <= 0.0f) { EndMatchPanel panel = GameObject.Instantiate <EndMatchPanel>(endMatchPanelPrefab); panel.transform.SetParent(this.transform, false); panel.SetText("Return to lobby?"); panel.OnReturnButtonClick += ExitObserveMatch; isSpectating = false; } } else if (northHand.player.hasSelectedCardForMatch && southHand.player.hasSelectedCardForMatch) { northHand.SetAndRevealCard(northHand.player.CardAt(northHand.player.selectedCard)); southHand.SetAndRevealCard(southHand.player.CardAt(southHand.player.selectedCard)); spectatingAfterEndTimer = REVEAL_ANIMATION_LEGNTH; } } }