added points calculation to challenge mode

This commit is contained in:
Alexander Eckart committed 2012-12-18 22:25:18 +01:00
1 parent 4fd98ee1a3
commit 8cbccc7f95
2 files changed
+148 -11

No files matched your search

+9 -9
View File
@@ -9,13 +9,13 @@ namespace Vocaluxe.PartyModes
public class ChallengeRounds public class ChallengeRounds
{ {
private Random _Rand; private Random _Rand;
private List<Combination> _Rounds;
private int _NumPlayer; private int _NumPlayer;
public List<Combination> Rounds;
public ChallengeRounds(int NumRounds, int NumPlayer, int NumPlayerAtOnce) public ChallengeRounds(int NumRounds, int NumPlayer, int NumPlayerAtOnce)
{ {
_Rounds = new List<Combination>(); Rounds = new List<Combination>();
_Rand = new Random(System.DateTime.Now.Millisecond); _Rand = new Random(System.DateTime.Now.Millisecond);
if (NumPlayerAtOnce < 1 || NumRounds < 1 || NumPlayer == 0) if (NumPlayerAtOnce < 1 || NumRounds < 1 || NumPlayer == 0)
@@ -29,21 +29,21 @@ namespace Vocaluxe.PartyModes
public Combination GetRound(int RoundNr) public Combination GetRound(int RoundNr)
{ {
if (RoundNr >= _Rounds.Count || _NumPlayer == 0 || _Rounds.Count == 0) if (RoundNr >= Rounds.Count || _NumPlayer == 0 || Rounds.Count == 0)
return null; return null;
return _Rounds[RoundNr]; return Rounds[RoundNr];
} }
private void BuildRounds(int NumRounds, int NumPlayerAtOnce, Random Rand) private void BuildRounds(int NumRounds, int NumPlayerAtOnce, Random Rand)
{ {
Combinations Combinations = new Combinations(_NumPlayer, NumPlayerAtOnce, Rand); Combinations Combinations = new Combinations(_NumPlayer, NumPlayerAtOnce, Rand);
_Rounds.Add(Combinations.GetNextCombination(null)); Rounds.Add(Combinations.GetNextCombination(null));
for (int i = 1; i < NumRounds; i++) for (int i = 1; i < NumRounds; i++)
{ {
_Rounds.Add(Combinations.GetNextCombination(GetPlayerDemand(i))); Rounds.Add(Combinations.GetNextCombination(GetPlayerDemand(i)));
} }
} }
@@ -57,7 +57,7 @@ namespace Vocaluxe.PartyModes
for (int i = 0; i < RoundIndex; i++) for (int i = 0; i < RoundIndex; i++)
{ {
foreach (int PlayerIndex in _Rounds[i].Player) foreach (int PlayerIndex in Rounds[i].Player)
{ {
NumPlayed[PlayerIndex]++; NumPlayed[PlayerIndex]++;
} }
@@ -70,7 +70,7 @@ namespace Vocaluxe.PartyModes
max = p; max = p;
} }
int num = _Rounds[0].Player.Count; int num = Rounds[0].Player.Count;
List<int> result = new List<int>(); List<int> result = new List<int>();
List<int> other = new List<int>(); List<int> other = new List<int>();
List<int> last = new List<int>(); List<int> last = new List<int>();
@@ -83,7 +83,7 @@ namespace Vocaluxe.PartyModes
{ {
if (RoundIndex > 0) if (RoundIndex > 0)
{ {
if (!_Rounds[RoundIndex - 1].IsAvailable(i)) if (!Rounds[RoundIndex - 1].IsAvailable(i))
other.Add(i); other.Add(i);
else else
last.Add(i); last.Add(i);
+139 -2
View File
@@ -24,8 +24,20 @@ namespace Vocaluxe.PartyModes
public struct DataToScreenMain public struct DataToScreenMain
{ {
public int CurrentRoundNr; public int CurrentRoundNr;
public List<Combination> Combs;
public List<ResultTableRow> ResultTable;
} }
public struct ResultTableRow
{
public int PlayerID;
public int NumWon;
public int NumDrawn;
public int NumLost;
public int SumSingPoints;
public int NumGamePoints;
}
#endregion ToScreen #endregion ToScreen
#region FromScreen #region FromScreen
@@ -82,10 +94,21 @@ namespace Vocaluxe.PartyModes
public List<int> ProfileIDs; public List<int> ProfileIDs;
public ChallengeRounds Rounds; public ChallengeRounds Rounds;
public List<ResultTableRow> ResultTable;
public int CurrentRoundNr; public int CurrentRoundNr;
} }
struct Stats
{
public int ProfileID;
public int SingPoints;
public int GamePoints;
public int Won;
public int Drawn;
public int Lost;
}
private DataToScreenConfig ToScreenConfig; private DataToScreenConfig ToScreenConfig;
private DataToScreenNames ToScreenNames; private DataToScreenNames ToScreenNames;
private DataToScreenMain ToScreenMain; private DataToScreenMain ToScreenMain;
@@ -126,6 +149,9 @@ namespace Vocaluxe.PartyModes
_ScreenSongOptions.Sorting.SongSorting = ESongSorting.TR_CONFIG_FOLDER; _ScreenSongOptions.Sorting.SongSorting = ESongSorting.TR_CONFIG_FOLDER;
_ScreenSongOptions.Sorting.Tabs = EOffOn.TR_CONFIG_ON; _ScreenSongOptions.Sorting.Tabs = EOffOn.TR_CONFIG_ON;
ToScreenMain.ResultTable = new List<ResultTableRow>();
GameData.ResultTable = new List<ResultTableRow>();
return true; return true;
} }
@@ -234,7 +260,10 @@ namespace Vocaluxe.PartyModes
if (_Screens != null) if (_Screens != null)
{ {
GameData.Rounds = new ChallengeRounds(GameData.NumRounds, GameData.NumPlayer, GameData.NumPlayerAtOnce); GameData.Rounds = new ChallengeRounds(GameData.NumRounds, GameData.NumPlayer, GameData.NumPlayerAtOnce);
GameData.CurrentRoundNr = 0; GameData.CurrentRoundNr = 1;
ToScreenMain.CurrentRoundNr = 1;
ToScreenMain.Combs = GameData.Rounds.Rounds;
UpdateScores();
Screen.DataToScreen(ToScreenMain); Screen.DataToScreen(ToScreenMain);
} }
break; break;
@@ -244,7 +273,13 @@ namespace Vocaluxe.PartyModes
case EStage.Singing: case EStage.Singing:
_Screens.TryGetValue("PartyScreenChallengeMain", out Screen); _Screens.TryGetValue("PartyScreenChallengeMain", out Screen);
if (_Screens != null) if (_Screens != null)
{
UpdateScores();
ToScreenMain.CurrentRoundNr = GameData.CurrentRoundNr;
ToScreenMain.Combs = GameData.Rounds.Rounds;
Screen.DataToScreen(ToScreenMain); Screen.DataToScreen(ToScreenMain);
}
break; break;
default: default:
break; break;
@@ -443,5 +478,107 @@ namespace Vocaluxe.PartyModes
_ScreenSongOptions.Selection.TeamNames[i] = "foobar"; _ScreenSongOptions.Selection.TeamNames[i] = "foobar";
} }
} }
private void UpdateScores()
{
if (GameData.ResultTable.Count == 0)
{
for (int i = 0; i < GameData.NumPlayer; i++)
{
ResultTableRow row = new ResultTableRow();
row.PlayerID = GameData.ProfileIDs[i];
row.NumWon = 0;
row.NumDrawn = 0;
row.NumLost = 0;
row.SumSingPoints = 0;
row.NumGamePoints = 0;
GameData.ResultTable.Add(row);
}
}
else
{
SPlayer[] results = _Base.Game.GetPlayer();
if (results == null)
return;
if (results.Length < GameData.NumPlayerAtOnce)
return;
List<Stats> points = GetPointsForPlayer(results);
for (int i = 0; i < GameData.NumPlayerAtOnce; i++)
{
int index = -1;
for (int j = 0; j < GameData.ResultTable.Count; j++)
{
if (results[i].ProfileID == GameData.ResultTable[i].PlayerID)
{
index = j;
break;
}
}
if (index != -1)
{
ResultTableRow row = GameData.ResultTable[index];
row.NumWon += points[i].Won;
row.NumDrawn += points[i].Drawn;
row.NumLost += points[i].Lost;
row.SumSingPoints += points[i].SingPoints;
row.NumGamePoints += points[i].GamePoints;
GameData.ResultTable[index] = row;
}
}
}
}
private List<Stats> GetPointsForPlayer(SPlayer[] Results)
{
List<Stats> result = new List<Stats>();
for(int i = 0; i < GameData.NumPlayerAtOnce; i++)
{
Stats stat = new Stats();
stat.ProfileID = Results[i].ProfileID;
stat.SingPoints = (int)Results[i].Points;
stat.Won = 0;
stat.Drawn = 0;
stat.Lost = 0;
stat.GamePoints = 0;
result.Add(stat);
}
result.Sort(delegate(Stats s1, Stats s2) { return s1.SingPoints.CompareTo(s2.SingPoints); });
int current = result[result.Count - 1].SingPoints;
int points = result.Count;
for (int i = result.Count - 1; i >= 0; i--)
{
Stats res = result[i];
if (i < result.Count - 1)
{
if (current > res.SingPoints)
{
res.GamePoints = i * 2;
}
else
res.GamePoints = points;
}
else
res.GamePoints = i * 2;
current = res.SingPoints;
points = res.GamePoints;
result[i] = res;
}
return result;
}
} }
} }