public List <JoPlayer> GetUniques() { List <JoPlayer> goodPlayers = new List <JoPlayer>(); for (int i = 0; i < players.Count; i++) { JoPlayer comparePlayerA = players[i] as JoPlayer; if (comparePlayerA.isGuesser) { continue; } bool goodPlayer = true; for (int j = 0; j < players.Count; j++) { JoPlayer comparePlayerB = players[j] as JoPlayer; if (comparePlayerA != comparePlayerB && comparePlayerA.guessedWord == comparePlayerB.guessedWord) { goodPlayer = false; break; } } if (goodPlayer) { goodPlayers.Add(comparePlayerA); } } return(goodPlayers); }
public void ResetForRound() { for (int i = 0; i < players.Count; i++) { JoPlayer player = players[i] as JoPlayer; player.Reset(); } }
public override void AddPlayer(string name, PlayerColor color) { GameObject playerGo = Instantiate(playerPrefab); playerGo.GetComponent <RectTransform>().SetParent(transform, false); JoPlayer player = playerGo.GetComponent <JoPlayer>(); player.Setup(name, color, PopPosition()); player.Show(0); players.Add(player); }
public int PlayersSubmittedCount() { int count = 0; for (int i = 0; i < players.Count; i++) { JoPlayer player = players[i] as JoPlayer; if (!string.IsNullOrEmpty(player.guessedWord)) { count++; } } return(count); }
public void StartRound() { JOPlayers allPlayers = players as JOPlayers; allPlayers.ResetForRound(); allPlayers.ShufflePlayers(); guessingPlayer = allPlayers.SetNextGuesser(); guessingWord = allWords[0].ToUpper(); allWords.RemoveAt(0); JsonObject message = new JsonObject(); message.Add("gameType", "JO"); message.Add("messageType", "START_ROUND"); message.Add("player", guessingPlayer.name); message.Add("word", guessingWord); server.SendMessage(message); }
public override void RemovePlayer(string name) { JoPlayer player = null; for (int i = 0; i < players.Count; i++) { if (players[i].name == name) { player = players[i] as JoPlayer; break; } } if (player != null) { player.Hide(() => { PushPosition(player.GetPosition()); players.Remove(player); }); } }
public JoPlayer SetNextGuesser() { JoPlayer guesser = null; for (int i = 0; i < players.Count; i++) { JoPlayer player = players[i] as JoPlayer; if (!player.hasBeenGuesser) { guesser = player; break; } } if (guesser == null) { players.ShuffleList(); for (int i = 0; i < players.Count; i++) { JoPlayer player = players[i] as JoPlayer; player.hasBeenGuesser = false; } } guesser = players[0] as JoPlayer; guesser.SetAsGuesser(); for (int i = 0; i < players.Count; i++) { JoPlayer player = players[i] as JoPlayer; if (!player.isGuesser) { player.SetAsPlayer(); } } return(guesser); }
public void WordSubmitted(JsonNode message) { JOPlayers allPlayers = players as JOPlayers; JoPlayer player = allPlayers.GetPlayer(message["name"]) as JoPlayer; player.guessedWord = message["word"].ToString().ToUpper(); player.OffScreen(0, () => { int submittedCount = allPlayers.PlayersSubmittedCount(); int totalPlayers = allPlayers.PlayerCount(); if (allPlayers.PlayersSubmittedCount() == allPlayers.PlayerCount()) { // compare all words List <JoPlayer> uniques = allPlayers.GetUniques(); // show off the answers if (uniques.Count > 0) { float delay = 0; for (int i = 0; i < uniques.Count; i++) { JoPlayer uniquePlayer = uniques[i]; uniquePlayer.SetWord(uniquePlayer.guessedWord); uniquePlayer.Show(delay); delay += 0.3f; } } // tell guessing player we are ready for a guess JsonObject rtgMessage = new JsonObject(); rtgMessage.Add("gameType", "JO"); rtgMessage.Add("messageType", "READY_TO_GUESS"); rtgMessage.Add("player", guessingPlayer.name); server.SendMessage(rtgMessage); } }); }