diff --git a/Vocaluxe/Base/CGame.cs b/Vocaluxe/Base/CGame.cs index 54df8b2c..f73ad6a8 100644 --- a/Vocaluxe/Base/CGame.cs +++ b/Vocaluxe/Base/CGame.cs @@ -108,41 +108,25 @@ namespace Vocaluxe.Base CConfig.UsePlayers(); } - public static void SetGameMode(EGameMode Mode) + public static void EnterNomalGame() { - switch (Mode) - { - case EGameMode.TR_GAMEMODE_NORMAL: - _GameMode = new CGameModeNormal(); - break; - case EGameMode.TR_GAMEMODE_MEDLEY: - _GameMode = new CGameModeMedley(); - break; - case EGameMode.TR_GAMEMODE_DUET: - _GameMode = new CGameModeDuet(); - break; - case EGameMode.TR_GAMEMODE_SHORTSONG: - _GameMode = new CGameModeShortSong(); - break; - default: - break; - } + _GameMode = new CGameModeNormal(); _GameMode.Init(); } public static EGameMode GameMode { - get { return _GameMode.GetGameMode(); } + get { return _GameMode.GetCurrentGameMode(); } } - public static bool AddVisibleSong(int VisibleIndex) + public static bool AddVisibleSong(int VisibleIndex, EGameMode GameMode) { - return _GameMode.AddVisibleSong(VisibleIndex); + return _GameMode.AddVisibleSong(VisibleIndex, GameMode); } - public static bool AddSong(int AbsoluteIndex) + public static bool AddSong(int AbsoluteIndex, EGameMode GameMode) { - return _GameMode.AddSong(AbsoluteIndex); + return _GameMode.AddSong(AbsoluteIndex, GameMode); } public static bool RemoveVisibleSong(int VisibleIndex) @@ -182,7 +166,7 @@ namespace Vocaluxe.Base public static int RoundNr { - get { return _GameMode.GetActualRoundNr(); } + get { return _GameMode.GetCurrentRoundNr(); } } public static CSong GetSong() diff --git a/Vocaluxe/GameModes/CGameMode.cs b/Vocaluxe/GameModes/CGameMode.cs index 2e1fbd2d..8af3ffbb 100644 --- a/Vocaluxe/GameModes/CGameMode.cs +++ b/Vocaluxe/GameModes/CGameMode.cs @@ -7,6 +7,18 @@ using Vocaluxe.Lib.Song; namespace Vocaluxe.GameModes { + struct SongQueque + { + public int SongID; + public EGameMode GameMode; + + public SongQueque(int songID, EGameMode gameMode) + { + SongID = songID; + GameMode = gameMode; + } + } + class CPoints { private SPlayer[,] _Rounds; @@ -90,40 +102,49 @@ namespace Vocaluxe.GameModes abstract class CGameMode : IGameMode { protected bool _Initialized = false; - protected EGameMode _GameMode; - protected List _Songs; - protected int _ActualSong; + protected List _SongQueque; + protected int _CurrentSong; protected CPoints _Points; #region Implementation public virtual void Init() { - _Songs = new List(); + _SongQueque = new List(); Reset(); } - public virtual EGameMode GetGameMode() + public virtual EGameMode GetCurrentGameMode() { - return _GameMode; + if (_CurrentSong >= 0 && _CurrentSong < _SongQueque.Count) + { + return _SongQueque[_CurrentSong].GameMode; + } + return EGameMode.TR_GAMEMODE_NORMAL; } - public virtual bool AddVisibleSong(int VisibleIndex) + public virtual bool AddVisibleSong(int VisibleIndex, EGameMode GameMode) { if (CSongs.VisibleSongs.Length > VisibleIndex) { - _Songs.Add(new CSong(CSongs.VisibleSongs[VisibleIndex])); - SongManipulation(_Songs.Count - 1); + int SongID = CSongs.VisibleSongs[VisibleIndex].ID; + if (GameMode == EGameMode.TR_GAMEMODE_DUET && !CSongs.GetSong(SongID).IsDuet) + return false; + + _SongQueque.Add(new SongQueque(SongID, GameMode)); return true; } return false; } - public virtual bool AddSong(int AbsoluteIndex) + public virtual bool AddSong(int AbsoluteIndex, EGameMode GameMode) { if (CSongs.AllSongs.Length > AbsoluteIndex) { - _Songs.Add(CSongs.AllSongs[AbsoluteIndex]); - SongManipulation(_Songs.Count - 1); + int SongID = CSongs.AllSongs[AbsoluteIndex].ID; + if (GameMode == EGameMode.TR_GAMEMODE_DUET && !CSongs.GetSong(SongID).IsDuet) + return false; + + _SongQueque.Add(new SongQueque(SongID, GameMode)); return true; } return false; @@ -133,24 +154,22 @@ namespace Vocaluxe.GameModes { if (CSongs.VisibleSongs.Length > VisibleIndex) { - int ID = CSongs.VisibleSongs[VisibleIndex].ID; int index = -1; - - for (int i = 0; i < _Songs.Count; i++) + int SongID = CSongs.VisibleSongs[VisibleIndex].ID; + for (int i = 0; i < _SongQueque.Count; i++) { - if (_Songs[i].ID == ID) + if (_SongQueque[i].SongID == SongID) { index = i; break; } } - if (index > -1) - { - _Songs.RemoveAt(index); - return true; - } - return false; + if (index == -1) + return false; + + _SongQueque.RemoveAt(index); + return true; } return false; } @@ -159,83 +178,85 @@ namespace Vocaluxe.GameModes { if (CSongs.AllSongs.Length > AbsoluteIndex) { - int ID = CSongs.AllSongs[AbsoluteIndex].ID; int index = -1; - - for (int i = 0; i < _Songs.Count; i++) + int SongID = CSongs.AllSongs[AbsoluteIndex].ID; + for (int i = 0; i < _SongQueque.Count; i++) { - if (_Songs[i].ID == ID) + if (_SongQueque[i].SongID == SongID) { index = i; break; } } + if (index == -1) + return false; - if (index > -1) - { - _Songs.RemoveAt(index); - return true; - } - return false; + _SongQueque.RemoveAt(index); + return true; } return false; } public virtual void ClearSongs() { - _Songs.Clear(); + _SongQueque.Clear(); } public virtual void Reset() { - _ActualSong = -1; + _CurrentSong = -1; } public virtual void Start(SPlayer[] Player) { - _Points = new CPoints(_Songs.Count, Player); + _Points = new CPoints(_SongQueque.Count, Player); } public virtual void NextRound(SPlayer[] Player) { - if (_ActualSong < _Songs.Count && _Songs.Count > 0) + if (_CurrentSong < _SongQueque.Count && _SongQueque.Count > 0) { - if (_ActualSong > -1) + if (_CurrentSong > -1) { - _Points.SetPoints(_ActualSong, _Songs[_ActualSong].ID, Player, _GameMode == EGameMode.TR_GAMEMODE_MEDLEY, _GameMode == EGameMode.TR_GAMEMODE_DUET); + _Points.SetPoints( + _CurrentSong, + _SongQueque[_CurrentSong].SongID, + Player, + _SongQueque[_CurrentSong].GameMode == EGameMode.TR_GAMEMODE_MEDLEY, + _SongQueque[_CurrentSong].GameMode == EGameMode.TR_GAMEMODE_DUET); } - _ActualSong++; + _CurrentSong++; } } public virtual bool IsFinished() { - return (_ActualSong == _Songs.Count || _Songs.Count == 0); + return (_CurrentSong == _SongQueque.Count || _SongQueque.Count == 0); } - public virtual int GetActualRoundNr() + public virtual int GetCurrentRoundNr() { - return _ActualSong + 1; + return _CurrentSong + 1; } public virtual CSong GetSong() { - if (_ActualSong >= 0 && _ActualSong < _Songs.Count) + if (_CurrentSong >= 0 && _CurrentSong < _SongQueque.Count) { - return _Songs[_ActualSong]; + return CSongs.GetSong(_SongQueque[_CurrentSong].SongID); } return null; } public virtual int GetNumSongs() { - return _Songs.Count; + return _SongQueque.Count; } public virtual CSong GetSong(int Num) { - if (Num - 1 < _Songs.Count) - return _Songs[Num - 1]; + if (Num - 1 < _SongQueque.Count) + return CSongs.GetSong(_SongQueque[Num - 1].SongID); return null; } diff --git a/Vocaluxe/GameModes/CGameModeDuet.cs b/Vocaluxe/GameModes/CGameModeDuet.cs index 09f64b95..70aa39c1 100644 --- a/Vocaluxe/GameModes/CGameModeDuet.cs +++ b/Vocaluxe/GameModes/CGameModeDuet.cs @@ -10,7 +10,6 @@ namespace Vocaluxe.GameModes { base.Init(); - _GameMode = EGameMode.TR_GAMEMODE_DUET; _Initialized = true; } } diff --git a/Vocaluxe/GameModes/CGameModeMedley.cs b/Vocaluxe/GameModes/CGameModeMedley.cs index 7257e86a..f0fca4f5 100644 --- a/Vocaluxe/GameModes/CGameModeMedley.cs +++ b/Vocaluxe/GameModes/CGameModeMedley.cs @@ -13,13 +13,12 @@ namespace Vocaluxe.GameModes { base.Init(); - _GameMode = EGameMode.TR_GAMEMODE_MEDLEY; _Initialized = true; } protected override void SongManipulation(int SongIndex) { - CSong song = _Songs[SongIndex]; + CSong song = CSongs.AllSongs[_SongQueque[SongIndex].SongID]; // set medley mode timings song.Start = CGame.GetTimeFromBeats(song.Medley.StartBeat, song.BPM) - song.Medley.FadeInTime + song.Gap; diff --git a/Vocaluxe/GameModes/CGameModeNormal.cs b/Vocaluxe/GameModes/CGameModeNormal.cs index 008d55cc..5f05bd6c 100644 --- a/Vocaluxe/GameModes/CGameModeNormal.cs +++ b/Vocaluxe/GameModes/CGameModeNormal.cs @@ -4,13 +4,13 @@ using System.Text; namespace Vocaluxe.GameModes { + // Nomal singing class CGameModeNormal : CGameMode { public override void Init() { base.Init(); - _GameMode = EGameMode.TR_GAMEMODE_NORMAL; _Initialized = true; } } diff --git a/Vocaluxe/GameModes/CGameModeShortSong.cs b/Vocaluxe/GameModes/CGameModeShortSong.cs index 18027a52..4bff1e4c 100644 --- a/Vocaluxe/GameModes/CGameModeShortSong.cs +++ b/Vocaluxe/GameModes/CGameModeShortSong.cs @@ -13,13 +13,12 @@ namespace Vocaluxe.GameModes { base.Init(); - _GameMode = EGameMode.TR_GAMEMODE_SHORTSONG; _Initialized = true; } protected override void SongManipulation(int SongIndex) { - CSong song = _Songs[SongIndex]; + CSong song = CSongs.AllSongs[_SongQueque[SongIndex].SongID]; song.Finish = CGame.GetTimeFromBeats(song.ShortEnd, song.BPM) + CSettings.DefaultMedleyFadeOutTime + song.Gap; diff --git a/Vocaluxe/GameModes/IGameMode.cs b/Vocaluxe/GameModes/IGameMode.cs index 3daba3a2..4d83391f 100644 --- a/Vocaluxe/GameModes/IGameMode.cs +++ b/Vocaluxe/GameModes/IGameMode.cs @@ -19,10 +19,10 @@ namespace Vocaluxe.GameModes { void Init(); - EGameMode GetGameMode(); + EGameMode GetCurrentGameMode(); - bool AddVisibleSong(int VisibleIndex); - bool AddSong(int AbsoluteIndex); + bool AddVisibleSong(int VisibleIndex, EGameMode GameMode); + bool AddSong(int AbsoluteIndex, EGameMode GameMode); bool RemoveVisibleSong(int VisibleIndex); bool RemoveSong(int AbsoluteIndex); void ClearSongs(); @@ -31,11 +31,12 @@ namespace Vocaluxe.GameModes void Start(SPlayer[] Player); void NextRound(SPlayer[] Player); bool IsFinished(); - int GetActualRoundNr(); - CSong GetSong(); + int GetCurrentRoundNr(); + CPoints GetPoints(); int GetNumSongs(); + CSong GetSong(); CSong GetSong(int Num); } } diff --git a/Vocaluxe/Screens/CPopupScreenPlayerControl.cs b/Vocaluxe/Screens/CPopupScreenPlayerControl.cs index cb21d9d4..e3d614d8 100644 --- a/Vocaluxe/Screens/CPopupScreenPlayerControl.cs +++ b/Vocaluxe/Screens/CPopupScreenPlayerControl.cs @@ -5,6 +5,7 @@ using System.Text; using System.Windows.Forms; using Vocaluxe.Base; +using Vocaluxe.GameModes; using Vocaluxe.Lib.Draw; using Vocaluxe.Menu; using Vocaluxe.Lib.Song; @@ -213,14 +214,14 @@ namespace Vocaluxe.Screens { if (SongNr >= 0 && CSongs.SongsLoaded) { - if (Duet) - CGame.SetGameMode(GameModes.EGameMode.TR_GAMEMODE_DUET); - else - CGame.SetGameMode(GameModes.EGameMode.TR_GAMEMODE_NORMAL); - CGame.Reset(); CGame.ClearSongs(); - CGame.AddSong(SongNr); + + EGameMode gm = EGameMode.TR_GAMEMODE_NORMAL; + if (CSongs.VisibleSongs[SongNr].IsDuet) + gm = EGameMode.TR_GAMEMODE_DUET; + + CGame.AddSong(SongNr, gm); CGraphics.FadeTo(EScreens.ScreenNames); } diff --git a/Vocaluxe/Screens/CScreenSong.cs b/Vocaluxe/Screens/CScreenSong.cs index a3edd9c9..27ac9cb8 100644 --- a/Vocaluxe/Screens/CScreenSong.cs +++ b/Vocaluxe/Screens/CScreenSong.cs @@ -7,6 +7,7 @@ using System.Text; using System.Windows.Forms; using Vocaluxe.Base; +using Vocaluxe.GameModes; using Vocaluxe.Lib.Draw; using Vocaluxe.Lib.Song; using Vocaluxe.Menu; @@ -265,7 +266,7 @@ namespace Vocaluxe.Screens public override void OnShow() { base.OnShow(); - + CGame.EnterNomalGame(); SongMenus[htSongMenus(SongMenu)].OnShow(); } @@ -327,22 +328,23 @@ namespace Vocaluxe.Screens { if ((CSongs.Category >= 0) && (SongNr >= 0)) { + EGameMode gm; if (_AvailableGameModes.Count >= SelectSlides[htSelectSlides(SelectSlideOptionsMode)].Selection) { - CGame.SetGameMode(_AvailableGameModes[SelectSlides[htSelectSlides(SelectSlideOptionsMode)].Selection]); + gm = _AvailableGameModes[SelectSlides[htSelectSlides(SelectSlideOptionsMode)].Selection]; } else { if (CSongs.VisibleSongs[SongNr].IsDuet) - CGame.SetGameMode(GameModes.EGameMode.TR_GAMEMODE_DUET); + gm = GameModes.EGameMode.TR_GAMEMODE_DUET; else - CGame.SetGameMode(GameModes.EGameMode.TR_GAMEMODE_NORMAL); + gm = GameModes.EGameMode.TR_GAMEMODE_NORMAL; } CGame.Reset(); CGame.ClearSongs(); - CGame.AddVisibleSong(SongNr); - //CGame.AddSong(SongNr+1); + + CGame.AddVisibleSong(SongNr, gm); CGraphics.FadeTo(EScreens.ScreenNames); } @@ -352,14 +354,15 @@ namespace Vocaluxe.Screens { if ((CSongs.Category >= 0) && (SongNr >= 0)) { + EGameMode gm; if (CSongs.VisibleSongs[SongNr].Medley.Source != EMedleySource.None) - CGame.SetGameMode(GameModes.EGameMode.TR_GAMEMODE_MEDLEY); + gm = GameModes.EGameMode.TR_GAMEMODE_MEDLEY; else return; CGame.Reset(); CGame.ClearSongs(); - CGame.AddVisibleSong(SongNr); + CGame.AddVisibleSong(SongNr, gm); CGraphics.FadeTo(EScreens.ScreenNames); } @@ -369,7 +372,6 @@ namespace Vocaluxe.Screens { CGame.Reset(); CGame.ClearSongs(); - CGame.SetGameMode(GameModes.EGameMode.TR_GAMEMODE_NORMAL); List IDs = new List(); for (int i = 0; i < CSongs.AllSongs.Length; i++) @@ -381,10 +383,11 @@ namespace Vocaluxe.Screens { int SongNr = IDs[CGame.Rand.Next(IDs.Count)]; - if (!CSongs.AllSongs[SongNr].IsDuet) - { - CGame.AddSong(SongNr); - } + EGameMode gm = EGameMode.TR_GAMEMODE_NORMAL; + if (CSongs.VisibleSongs[SongNr].IsDuet) + gm = EGameMode.TR_GAMEMODE_DUET; + CGame.AddSong(SongNr, gm); + IDs.Remove(SongNr); } @@ -396,7 +399,6 @@ namespace Vocaluxe.Screens { CGame.Reset(); CGame.ClearSongs(); - CGame.SetGameMode(GameModes.EGameMode.TR_GAMEMODE_NORMAL); List IDs = new List(); for (int i = 0; i < CSongs.VisibleSongs.Length; i++) @@ -408,10 +410,12 @@ namespace Vocaluxe.Screens { int SongNr = IDs[CGame.Rand.Next(IDs.Count)]; - if (!CSongs.AllSongs[SongNr].IsDuet) - { - CGame.AddSong(SongNr); - } + EGameMode gm = EGameMode.TR_GAMEMODE_NORMAL; + if (CSongs.VisibleSongs[SongNr].IsDuet) + gm = EGameMode.TR_GAMEMODE_DUET; + + CGame.AddSong(SongNr, gm); + IDs.Remove(SongNr); } diff --git a/Vocaluxe/Vocaluxe.csproj b/Vocaluxe/Vocaluxe.csproj index 3788a5be..b75ed99f 100644 --- a/Vocaluxe/Vocaluxe.csproj +++ b/Vocaluxe/Vocaluxe.csproj @@ -134,7 +134,9 @@ - + + Code + @@ -245,4 +247,4 @@ --> - \ No newline at end of file +