예제 #1
0
        private int GetPlayerInitialRank(int playerID)
        {
            foreach (clsPlayerRanking rank in initialRankings)
            {
                if (rank.PlayerID == playerID)
                {
                    return(rank.Rank);
                }
            }
            clsPlayerRanking newRank = new clsPlayerRanking();

            newRank.PlayerID = playerID;
            newRank.Rank     = initialRankings.Count;

            foreach (clsMeetingAttendee attendee in listMeetingAttendees)
            {
                if (attendee.Player.PlayerID == playerID)
                {
                    newRank.PlayerFullName = attendee.Player.FullName;
                    break;
                }
            }
            initialRankings.Add(newRank);
            return(newRank.Rank);
        }
예제 #2
0
        public void SetRankings()
        {
            List <clsPlayer> playerList = dataStore.LoadPlayersFromDataStore();

            initialRankings.Clear();
            finalRankings.Clear();
            foreach (clsPlayer player in playerList)
            {
                clsPlayerRanking newRank = new clsPlayerRanking();
                newRank.PlayerID       = player.PlayerID;
                newRank.Rank           = player.Rank;
                newRank.PlayerFullName = player.FullName;
                initialRankings.Add(newRank);
                finalRankings.Add(newRank);
            }
            initialRankings.Sort(rankComparer);
            finalRankings.Sort(rankComparer);


            foreach (clsChallengeGame game in listChallengeGames)
            {
                if (game.GameResult != "None")
                {
                    int blackPlayerRank = GetPlayerInitialRank(game.BlackPlayerID);
                    int whitePlayerRank = GetPlayerInitialRank(game.WhitePlayerID);

                    if (game.GameResult == "Draw")
                    {
                        if ((blackPlayerRank < whitePlayerRank) && (blackPlayerRank < whitePlayerRank - 1))
                        {
                            SetPlayerRank(game.WhitePlayerID, blackPlayerRank + 1);
                        }
                        else if ((whitePlayerRank < blackPlayerRank) && (whitePlayerRank < blackPlayerRank - 1))
                        {
                            SetPlayerRank(game.BlackPlayerID, whitePlayerRank + 1);
                        }
                    }
                    else if (game.GameResult == "White")
                    {
                        if (blackPlayerRank < whitePlayerRank)
                        {
                            SetPlayerRank(game.WhitePlayerID, blackPlayerRank);
                        }
                    }
                    else if (game.GameResult == "Black")
                    {
                        if (whitePlayerRank < blackPlayerRank)
                        {
                            SetPlayerRank(game.BlackPlayerID, whitePlayerRank);
                        }
                    }
                }
            }

            foreach (clsPlayerRanking ranking in finalRankings)
            {
                clsPlayer player = playerList.Find(x => x.PlayerID == ranking.PlayerID);
                player.Rank = ranking.Rank;
            }
            dataStore.SavePlayersToDataStore(playerList);
        }