예제 #1
0
        private void _UpdateScores()
        {
            //Prepare results table
            if (GameData.ResultTable.Count == 0)
            {
                for (int i = 0; i < GameData.NumPlayer; i++)
                {
                    var row = new CResultTableRow {
                        PlayerID = GameData.ProfileIDs[i], NumPlayed = 0, NumWon = 0, NumSingPoints = 0, NumGamePoints = 0
                    };
                    GameData.ResultTable.Add(row);
                }

                GameData.Results = new int[GameData.NumRounds, GameData.NumPlayerAtOnce];
                for (int i = 0; i < GameData.NumRounds; i++)
                {
                    for (int j = 0; j < GameData.NumPlayerAtOnce; j++)
                    {
                        GameData.Results[i, j] = 0;
                    }
                }
            }

            //Get points from game
            CPoints points = CBase.Game.GetPoints();

            SPlayer[] players = CBase.Game.GetPlayers();

            //Go over all rounds and sum up points
            for (int round = 0; round < points.NumRounds; round++)
            {
                SPlayer[] res = points.GetPlayer(round, GameData.NumPlayerAtOnce);

                if (res == null || res.Length < GameData.NumPlayerAtOnce)
                {
                    return;
                }

                for (int p = 0; p < GameData.NumPlayerAtOnce; p++)
                {
                    players[p].Points            += res[p].Points;
                    players[p].PointsGoldenNotes += res[p].PointsGoldenNotes;
                    players[p].PointsLineBonus   += res[p].PointsLineBonus;
                }
            }
            //Calculate average points
            for (int p = 0; p < GameData.NumPlayerAtOnce; p++)
            {
                players[p].Points            /= points.NumRounds;
                players[p].PointsGoldenNotes /= points.NumRounds;
                players[p].PointsLineBonus   /= points.NumRounds;

                //Save points in GameData
                GameData.Results[GameData.CurrentRoundNr - 2, p] = (int)Math.Round(players[p].Points);
            }

            List <SStats> stats = _GetPointsForPlayer(players);

            for (int i = 0; i < GameData.NumPlayerAtOnce; i++)
            {
                //Find matching row in results table
                int index = -1;
                for (int j = 0; j < GameData.ResultTable.Count; j++)
                {
                    if (stats[i].ProfileID == GameData.ResultTable[j].PlayerID)
                    {
                        index = j;
                        break;
                    }
                }

                if (index == -1)
                {
                    continue;
                }
                CResultTableRow row = GameData.ResultTable[index];

                //Update results entry
                row.NumPlayed++;
                row.NumWon        += stats[i].Won;
                row.NumSingPoints += stats[i].SingPoints;
                row.NumGamePoints += stats[i].GamePoints;

                GameData.ResultTable[index] = row;
            }

            GameData.ResultTable.Sort();

            //Update position-number
            int pos            = 1;
            int lastPoints     = 0;
            int lastSingPoints = 0;

            foreach (CResultTableRow resultRow in GameData.ResultTable)
            {
                if (lastPoints > resultRow.NumGamePoints || lastSingPoints > resultRow.NumSingPoints)
                {
                    pos++;
                }
                resultRow.Position = pos;
                lastPoints         = resultRow.NumGamePoints;
                lastSingPoints     = resultRow.NumSingPoints;
            }
        }
예제 #2
0
        private void _UpdateScores()
        {
            if (GameData.ResultTable.Count == 0)
            {
                for (int i = 0; i < GameData.NumPlayer; i++)
                {
                    var row = new CResultTableRow {
                        PlayerID = GameData.ProfileIDs[i], NumPlayed = 0, NumWon = 0, NumSingPoints = 0, NumGamePoints = 0
                    };
                    GameData.ResultTable.Add(row);
                }

                GameData.Results = new int[GameData.NumRounds, GameData.NumPlayerAtOnce];
                for (int i = 0; i < GameData.NumRounds; i++)
                {
                    for (int j = 0; j < GameData.NumPlayerAtOnce; j++)
                    {
                        GameData.Results[i, j] = 0;
                    }
                }
            }
            SPlayer[] results = CBase.Game.GetPlayers();
            if (results == null)
            {
                return;
            }

            if (results.Length < GameData.NumPlayerAtOnce)
            {
                return;
            }

            for (int j = 0; j < GameData.NumPlayerAtOnce; j++)
            {
                GameData.Results[GameData.CurrentRoundNr - 2, j] = (int)Math.Round(results[j].Points);
            }

            List <SStats> points = _GetPointsForPlayer(results);

            for (int i = 0; i < GameData.NumPlayerAtOnce; i++)
            {
                int index = -1;
                for (int j = 0; j < GameData.ResultTable.Count; j++)
                {
                    if (points[i].ProfileID == GameData.ResultTable[j].PlayerID)
                    {
                        index = j;
                        break;
                    }
                }

                if (index == -1)
                {
                    continue;
                }
                CResultTableRow row = GameData.ResultTable[index];

                row.NumPlayed++;
                row.NumWon        += points[i].Won;
                row.NumSingPoints += points[i].SingPoints;
                row.NumGamePoints += points[i].GamePoints;

                GameData.ResultTable[index] = row;
            }


            GameData.ResultTable.Sort();

            //Update position-number
            int pos            = 1;
            int lastPoints     = 0;
            int lastSingPoints = 0;

            foreach (CResultTableRow resultRow in GameData.ResultTable)
            {
                if (lastPoints > resultRow.NumGamePoints || lastSingPoints > resultRow.NumSingPoints)
                {
                    pos++;
                }
                resultRow.Position = pos;
                lastPoints         = resultRow.NumGamePoints;
                lastSingPoints     = resultRow.NumSingPoints;
            }
        }