More refactoring and small fixes

This commit is contained in:
Flamefire committed 2013-04-23 14:22:42 +02:00
1 parent dcbbc5caf3
commit 1540be9120
46 files changed
+205 -526

No files matched your search

@@ -19,6 +19,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace VocaluxeLib.PartyModes.Challenge
{
@@ -27,7 +28,7 @@ namespace VocaluxeLib.PartyModes.Challenge
private readonly Random _Rand;
private readonly int _NumPlayer;
public List<CCombination> Rounds;
public readonly List<CCombination> Rounds;
public CChallengeRounds(int numRounds, int numPlayer, int numPlayerAtOnce)
{
@@ -60,7 +61,7 @@ namespace VocaluxeLib.PartyModes.Challenge
Rounds.Add(combinations.GetNextCombination(_GetPlayerDemand(i)));
}
private List<int> _GetPlayerDemand(int roundIndex)
private IEnumerable<int> _GetPlayerDemand(int roundIndex)
{
List<int> numPlayed = new List<int>(_NumPlayer);
for (int i = 0; i < _NumPlayer; i++)
@@ -72,12 +73,7 @@ namespace VocaluxeLib.PartyModes.Challenge
numPlayed[playerIndex]++;
}
int max = 0;
foreach (int p in numPlayed)
{
if (p > max)
max = p;
}
int max = numPlayed.Max();
int num = Rounds[0].Player.Count;
List<int> result = new List<int>();
@@ -150,13 +146,11 @@ namespace VocaluxeLib.PartyModes.Challenge
_Rand = rand;
}
public CCombination GetNextCombination(List<int> playerNrDemand)
public CCombination GetNextCombination(IEnumerable<int> playerNrDemand)
{
if (_Combs.Count == 0)
_Create();
CCombination combs = new CCombination();
if (_NumPlayer == _NumMics)
return _Combs[0];
@@ -164,28 +158,19 @@ namespace VocaluxeLib.PartyModes.Challenge
List<CCombination> combsFiltered = new List<CCombination>();
if (playerNrDemand != null)
{
for (int i = 0; i < _Combs.Count; i++)
{
if (_Combs[i].IsAvailableAll(playerNrDemand))
combsFiltered.Add(_Combs[i]);
}
combsFiltered.AddRange(_Combs.Where(t => t.IsAvailableAll(playerNrDemand)));
}
//1st fallback
if (playerNrDemand != null && combsFiltered.Count == 0)
{
for (int i = 0; i < _Combs.Count; i++)
{
if (_Combs[i].IsAvailableSomeone(playerNrDemand))
combsFiltered.Add(_Combs[i]);
}
combsFiltered.AddRange(_Combs.Where(t => t.IsAvailableSomeone(playerNrDemand)));
}
//2nd fallback
if (combsFiltered.Count == 0)
{
for (int i = 0; i < _Combs.Count; i++)
combsFiltered.Add(_Combs[i]);
combsFiltered.AddRange(_Combs);
}
int num = combsFiltered.Count;
@@ -222,7 +207,7 @@ namespace VocaluxeLib.PartyModes.Challenge
public class CCombination
{
public List<int> Player;
public readonly List<int> Player;
public CCombination()
{
@@ -231,28 +216,17 @@ namespace VocaluxeLib.PartyModes.Challenge
public bool IsAvailable(int playerIndex)
{
foreach (int p in Player)
{
if (p == playerIndex)
return true;
}
return false;
return Player.Any(p => p == playerIndex);
}
public bool IsAvailableAll(List<int> playerIndices)
public bool IsAvailableAll(IEnumerable<int> playerIndices)
{
bool result = true;
foreach (int p in playerIndices)
result &= IsAvailable(p);
return result;
return playerIndices.All(IsAvailable);
}
public bool IsAvailableSomeone(List<int> playerIndices)
public bool IsAvailableSomeone(IEnumerable<int> playerIndices)
{
bool result = false;
foreach (int p in playerIndices)
result |= IsAvailable(p);
return result;
return playerIndices.Any(IsAvailable);
}
}
}
@@ -58,17 +58,15 @@ namespace VocaluxeLib.PartyModes.Challenge
public int Position;
public int PlayerID;
public int NumPlayed;
public int NumRounds;
public int NumWon;
public int NumSingPoints;
public int NumGamePoints;
public int CompareTo(object obj)
{
if (obj is CResultTableRow)
CResultTableRow row = obj as CResultTableRow;
if (row != null)
{
CResultTableRow row = (CResultTableRow)obj;
int res = row.NumGamePoints.CompareTo(NumGamePoints);
if (res == 0)
{
@@ -101,8 +99,7 @@ namespace VocaluxeLib.PartyModes.Challenge
public struct SFromScreenNames
{
public bool FadeToConfig;
public bool FadeToMain;
public bool FadeBack;
public List<int> ProfileIDs;
}
@@ -236,7 +233,7 @@ namespace VocaluxeLib.PartyModes.Challenge
try
{
dataFrom = (SDataFromScreen)data;
if (dataFrom.ScreenNames.FadeToConfig)
if (dataFrom.ScreenNames.FadeBack)
_Stage = EStage.NotStarted;
else
{
@@ -590,13 +587,7 @@ namespace VocaluxeLib.PartyModes.Challenge
{
for (int i = 0; i < _GameData.NumPlayer; i++)
{
CResultTableRow row = new CResultTableRow();
row.PlayerID = _GameData.ProfileIDs[i];
row.NumPlayed = 0;
row.NumRounds = 0;
row.NumWon = 0;
row.NumSingPoints = 0;
row.NumGamePoints = 0;
CResultTableRow row = new CResultTableRow {PlayerID = _GameData.ProfileIDs[i], NumPlayed = 0, NumWon = 0, NumSingPoints = 0, NumGamePoints = 0};
_GameData.ResultTable.Add(row);
}
@@ -633,18 +624,16 @@ namespace VocaluxeLib.PartyModes.Challenge
}
}
if (index != -1)
{
CResultTableRow row = _GameData.ResultTable[index];
if (index == -1)
continue;
CResultTableRow row = _GameData.ResultTable[index];
row.NumPlayed++;
row.NumWon += points[i].Won;
row.NumRounds += 1;
row.NumSingPoints += points[i].SingPoints;
row.NumGamePoints += points[i].GamePoints;
row.NumPlayed++;
row.NumWon += points[i].Won;
row.NumSingPoints += points[i].SingPoints;
row.NumGamePoints += points[i].GamePoints;
_GameData.ResultTable[index] = row;
}
_GameData.ResultTable[index] = row;
}
}
@@ -23,7 +23,9 @@ using VocaluxeLib.Menu;
namespace VocaluxeLib.PartyModes.Challenge
{
// ReSharper disable UnusedMember.Global
public class CPartyScreenChallengeConfig : CMenuParty
// ReSharper restore UnusedMember.Global
{
// Version number for theme files. Increment it, if you've changed something on the theme files!
protected override int _ScreenVersion
@@ -41,7 +41,9 @@ namespace VocaluxeLib.PartyModes.Challenge
public List<CText> TextScores;
}
// ReSharper disable UnusedMember.Global
public class CPartyScreenChallengeMain : CMenuParty
// ReSharper restore UnusedMember.Global
{
// Version number for theme files. Increment it, if you've changed something on the theme files!
protected override int _ScreenVersion
@@ -350,9 +352,9 @@ namespace VocaluxeLib.PartyModes.Challenge
private void _UpdateNextPlayerPositions()
{
float x = CBase.Settings.GetRenderW() / 2 - ((_GameState.NumPlayerAtOnce * _Statics[_StaticNextPlayer].Rect.W) + ((_GameState.NumPlayerAtOnce - 1) * 15)) / 2;
float staticY = 590;
float textY = 550;
float x = (float) CBase.Settings.GetRenderW() / 2 - ((_GameState.NumPlayerAtOnce * _Statics[_StaticNextPlayer].Rect.W) + ((_GameState.NumPlayerAtOnce - 1) * 15)) / 2;
const float staticY = 590;
const float textY = 550;
for (int i = 0; i < _GameState.NumPlayerAtOnce; i++)
{
//static
@@ -606,7 +608,7 @@ namespace VocaluxeLib.PartyModes.Challenge
row.Pos.Text = _GameState.ResultTable[i + _PlayerTableOffset].Position + ".";
row.Name.Text = profiles[_GameState.ResultTable[i + _PlayerTableOffset].PlayerID].PlayerName;
row.Rounds.Text = _GameState.ResultTable[i + _PlayerTableOffset].NumRounds.ToString();
row.Rounds.Text = _GameState.ResultTable[i + _PlayerTableOffset].NumPlayed.ToString();
row.Won.Text = _GameState.ResultTable[i + _PlayerTableOffset].NumWon.ToString();
row.SingPoints.Text = _GameState.ResultTable[i + _PlayerTableOffset].NumSingPoints.ToString();
row.GamePoints.Text = _GameState.ResultTable[i + _PlayerTableOffset].NumGamePoints.ToString();
@@ -89,7 +89,7 @@ namespace VocaluxeLib.PartyModes.Challenge
_ThemeButtons = new string[] {_ButtonBack, _ButtonNext, _ButtonPlayerDestination, _ButtonPlayerChoose};
_Data = new SDataFromScreen();
SFromScreenNames names = new SFromScreenNames {FadeToConfig = false, FadeToMain = false, ProfileIDs = new List<int>()};
SFromScreenNames names = new SFromScreenNames {FadeBack = false, ProfileIDs = new List<int>()};
_Data.ScreenNames = names;
}
@@ -485,15 +485,13 @@ namespace VocaluxeLib.PartyModes.Challenge
private void _Back()
{
_Data.ScreenNames.FadeToConfig = true;
_Data.ScreenNames.FadeToMain = false;
_Data.ScreenNames.FadeBack = true;
_PartyMode.DataFromScreen(ThemeName, _Data);
}
private void _Next()
{
_Data.ScreenNames.FadeToConfig = false;
_Data.ScreenNames.FadeToMain = true;
_Data.ScreenNames.FadeBack = false;
_PartyMode.DataFromScreen(ThemeName, _Data);
}
}
@@ -66,10 +66,9 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley
public int CompareTo(object obj)
{
if (obj is CResultTableRow)
CResultTableRow row = obj as CResultTableRow;
if (row != null)
{
CResultTableRow row = (CResultTableRow)obj;
int res = row.NumGamePoints.CompareTo(NumGamePoints);
if (res == 0)
{
@@ -23,7 +23,9 @@ using VocaluxeLib.Menu;
namespace VocaluxeLib.PartyModes.ChallengeMedley
{
// ReSharper disable UnusedMember.Global
public class CPartyScreenChallengeMedleyConfig : CMenuParty
// ReSharper restore UnusedMember.Global
{
// Version number for theme files. Increment it, if you've changed something on the theme files!
protected override int _ScreenVersion
@@ -41,7 +41,9 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley
public List<CText> TextScores;
}
// ReSharper disable UnusedMember.Global
public class CPartyScreenChallengeMedleyMain : CMenuParty
// ReSharper restore UnusedMember.Global
{
// Version number for theme files. Increment it, if you've changed something on the theme files!
protected override int _ScreenVersion
@@ -350,9 +352,9 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley
private void _UpdateNextPlayerPositions()
{
float x = CBase.Settings.GetRenderW() / 2 - ((_GameState.NumPlayerAtOnce * _Statics[_StaticNextPlayer].Rect.W) + ((_GameState.NumPlayerAtOnce - 1) * 15)) / 2;
float staticY = 590;
float textY = 550;
float x = (float) CBase.Settings.GetRenderW() / 2 - ((_GameState.NumPlayerAtOnce * _Statics[_StaticNextPlayer].Rect.W) + ((_GameState.NumPlayerAtOnce - 1) * 15)) / 2;
const float staticY = 590;
const float textY = 550;
for (int i = 0; i < _GameState.NumPlayerAtOnce; i++)
{
//static
@@ -24,7 +24,9 @@ using VocaluxeLib.Menu;
namespace VocaluxeLib.PartyModes.ChallengeMedley
{
// ReSharper disable UnusedMember.Global
public class CPartyScreenChallengeMedleyNames : CMenuParty
// ReSharper restore UnusedMember.Global
{
// Version number for theme files. Increment it, if you've changed something on the theme files!
protected override int _ScreenVersion
@@ -18,12 +18,15 @@
#endregion
using System;
using System.Linq;
using System.Windows.Forms;
using VocaluxeLib.Menu;
namespace VocaluxeLib.PartyModes.TicTacToe
{
// ReSharper disable UnusedMember.Global
public class CPartyScreenTicTacToeConfig : CMenuParty
// ReSharper restore UnusedMember.Global
{
// Version number for theme files. Increment it, if you've changed something on the theme files!
protected override int _ScreenVersion
@@ -57,14 +60,16 @@ namespace VocaluxeLib.PartyModes.TicTacToe
_ThemeButtons = new string[] {_ButtonNext, _ButtonBack};
_Data = new SDataFromScreen();
SFromScreenConfig config = new SFromScreenConfig();
config.PlaylistID = 0;
config.NumFields = 9;
config.NumPlayerTeam1 = 2;
config.NumPlayerTeam2 = 2;
config.GameMode = EPartyGameMode.TR_GAMEMODE_NORMAL;
config.CategoryID = 0;
config.SongSource = ESongSource.TR_ALLSONGS;
SFromScreenConfig config = new SFromScreenConfig
{
PlaylistID = 0,
NumFields = 9,
NumPlayerTeam1 = 2,
NumPlayerTeam2 = 2,
GameMode = EPartyGameMode.TR_GAMEMODE_NORMAL,
CategoryID = 0,
SongSource = ESongSource.TR_ALLSONGS
};
_Data.ScreenConfig = config;
}
@@ -263,14 +268,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe
for (int i = 0; i < CBase.Playlist.GetPlaylistSongCount(_Data.ScreenConfig.PlaylistID); i++)
{
int id = CBase.Playlist.GetPlaylistSong(_Data.ScreenConfig.PlaylistID, i).SongID;
foreach (EGameMode mode in CBase.Songs.GetSongByID(id).AvailableGameModes)
{
if (mode == gm)
{
_ConfigOk = true;
break;
}
}
_ConfigOk = CBase.Songs.GetSongByID(id).AvailableGameModes.Any(mode => mode == gm);
if (_ConfigOk)
break;
}
@@ -291,14 +289,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe
_ConfigOk = false;
for (int i = 0; i < CBase.Songs.NumSongsInCategory(_Data.ScreenConfig.CategoryID); i++)
{
foreach (EGameMode mode in CBase.Songs.GetVisibleSong(i).AvailableGameModes)
{
if (mode == gm)
{
_ConfigOk = true;
break;
}
}
_ConfigOk=CBase.Songs.GetVisibleSong(i).AvailableGameModes.Any(mode => mode == gm);
if (_ConfigOk)
break;
}
@@ -316,14 +307,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe
{
for (int i = 0; i < CBase.Songs.GetNumSongs(); i++)
{
foreach (EGameMode mode in CBase.Songs.GetSongByID(i).AvailableGameModes)
{
if (mode == gm)
{
_ConfigOk = true;
break;
}
}
_ConfigOk = CBase.Songs.GetSongByID(i).AvailableGameModes.Any(mode => mode == gm);
if (_ConfigOk)
break;
}
@@ -400,13 +400,10 @@ namespace VocaluxeLib.PartyModes.TicTacToe
private void _UpdateFields()
{
int numOneRow = (int)Math.Sqrt(_GameData.NumFields);
float fieldSizeY = (CBase.Settings.GetRenderH() - 150 - numOneRow * _FieldSpace) / numOneRow;
float fieldSizeX = (CBase.Settings.GetRenderW() - 300 - numOneRow * _FieldSpace) / numOneRow;
if (fieldSizeX < fieldSizeY)
_FieldSize = fieldSizeX;
else
_FieldSize = fieldSizeY;
_FieldFirstX = CBase.Settings.GetRenderW() / 2 - (numOneRow * _FieldSize + (numOneRow - 1) * _FieldSpace) / 2;
float fieldSizeY = ((float)CBase.Settings.GetRenderH() - 150 - numOneRow * _FieldSpace) / numOneRow;
float fieldSizeX = ((float)CBase.Settings.GetRenderW() - 300 - numOneRow * _FieldSpace) / numOneRow;
_FieldSize = Math.Min(fieldSizeX, fieldSizeY);
_FieldFirstX = (float)CBase.Settings.GetRenderW() / 2 - (numOneRow * _FieldSize + (numOneRow - 1) * _FieldSpace) / 2;
_FieldFirstY = 140 + (CBase.Settings.GetRenderH() - 140) / 2 - (numOneRow * _FieldSize + numOneRow * _FieldSpace) / 2;
int row = 0;
int column = 0;
@@ -24,7 +24,9 @@ using VocaluxeLib.Menu;
namespace VocaluxeLib.PartyModes.TicTacToe
{
// ReSharper disable UnusedMember.Global
public class CPartyScreenTicTacToeNames : CMenuParty
// ReSharper restore UnusedMember.Global
{
// Version number for theme files. Increment it, if you've changed something on the theme files!
protected override int _ScreenVersion