示例#1
0
    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);
    }
示例#2
0
 public void ResetForRound()
 {
     for (int i = 0; i < players.Count; i++)
     {
         JoPlayer player = players[i] as JoPlayer;
         player.Reset();
     }
 }
示例#3
0
    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);
    }
示例#4
0
    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);
    }
示例#5
0
    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);
    }
示例#6
0
    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);
            });
        }
    }
示例#7
0
    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);
    }
示例#8
0
    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);
            }
        });
    }