From 143b3303f004284c8862e190eedc32da2ad8e242 Mon Sep 17 00:00:00 2001 From: Damien LAGUERRE Date: Fri, 22 Dec 2023 12:24:54 +0100 Subject: [PATCH 1/5] Improvements to TicTacToe : + Fix teams limited to 2 players + Add the possibility of changing players --- .../TicTacToe/Languages/English.xml | 3 +- .../PartyModes/TicTacToe/Languages/French.xml | 1 + .../Screens/PartyScreenTicTacToeConfig.xml | 58 ++++++++- .../Screens/PartyScreenTicTacToeMain.xml | 58 +++++++++ .../PartyModeTicTacToe/CPartyModeTicTacToe.cs | 1 + .../CPartyScreenTicTacToeConfig.cs | 7 +- .../CPartyScreenTicTacToeMain.cs | 118 +++++++++++++----- .../CPartyScreenTicTacToeNames.cs | 9 +- 8 files changed, 218 insertions(+), 37 deletions(-) diff --git a/Output/PartyModes/TicTacToe/Languages/English.xml b/Output/PartyModes/TicTacToe/Languages/English.xml index 0066f864..1581f008 100644 --- a/Output/PartyModes/TicTacToe/Languages/English.xml +++ b/Output/PartyModes/TicTacToe/Languages/English.xml @@ -17,7 +17,8 @@ Number of players in team 1 Number of players in team 2 Number of fields - Refill jokers every round + Refill jokers every round + Switch player Tic-Tac-Toe: Choose Player Selected players for this team: Team 1 diff --git a/Output/PartyModes/TicTacToe/Languages/French.xml b/Output/PartyModes/TicTacToe/Languages/French.xml index 67f9cd54..e37c90ab 100644 --- a/Output/PartyModes/TicTacToe/Languages/French.xml +++ b/Output/PartyModes/TicTacToe/Languages/French.xml @@ -18,6 +18,7 @@ Nombre de joueurs dans l'Equipe 2 Nombre de champs Recharger les jokers a chaque tour + Changement de joueur Tic-Tac-Toe: Choix des joueurs Equipe 1 Equipe 2 diff --git a/Output/PartyModes/TicTacToe/Themes/Default/Screens/PartyScreenTicTacToeConfig.xml b/Output/PartyModes/TicTacToe/Themes/Default/Screens/PartyScreenTicTacToeConfig.xml index a5ad9fa9..5d645321 100644 --- a/Output/PartyModes/TicTacToe/Themes/Default/Screens/PartyScreenTicTacToeConfig.xml +++ b/Output/PartyModes/TicTacToe/Themes/Default/Screens/PartyScreenTicTacToeConfig.xml @@ -2,7 +2,7 @@ PartyScreenTicTacToeConfig - 2 + 3 @@ -69,6 +69,20 @@ Outline TR_SCREENCONFIG_REFILLJOKERS + + 75 + 210 + 0 + 27 + 0 + + + Left + Center + + Outline + TR_SCREENCONFIG_SWITCH_PLAYER + + + diff --git a/PartyModes/PartyModeTicTacToe/CPartyModeTicTacToe.cs b/PartyModes/PartyModeTicTacToe/CPartyModeTicTacToe.cs index 321586c9..c1dab85b 100644 --- a/PartyModes/PartyModeTicTacToe/CPartyModeTicTacToe.cs +++ b/PartyModes/PartyModeTicTacToe/CPartyModeTicTacToe.cs @@ -127,6 +127,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe public int[] NumJokerRandom; public int[] NumJokerRetry; public EOffOn RefillJokers; + public EOffOn SwitchPlayer; } public SData GameData; diff --git a/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeConfig.cs b/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeConfig.cs index 640fffbf..16fd7836 100644 --- a/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeConfig.cs +++ b/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeConfig.cs @@ -31,11 +31,12 @@ namespace VocaluxeLib.PartyModes.TicTacToe // Version number for theme files. Increment it, if you've changed something on the theme files! protected override int _ScreenVersion { - get { return 2; } + get { return 3; } } private const string _SelectSlideNumFields = "SelectSlideNumFields"; private const string _SelectSlideRefillJokers = "SelectSlideRefillJokers"; + private const string _SelectSlideSwitchPlayer = "SelectSlideSwitchPlayer"; private const string _ButtonNext = "ButtonNext"; private const string _ButtonBack = "ButtonBack"; @@ -133,12 +134,16 @@ namespace VocaluxeLib.PartyModes.TicTacToe _SelectSlides[_SelectSlideRefillJokers].AddValues(Enum.GetNames(typeof(EOffOn))); _SelectSlides[_SelectSlideRefillJokers].Selection = (int)_PartyMode.GameData.RefillJokers; + + _SelectSlides[_SelectSlideSwitchPlayer].AddValues(Enum.GetNames(typeof(EOffOn))); + _SelectSlides[_SelectSlideSwitchPlayer].Selection = (int)_PartyMode.GameData.SwitchPlayer; } private void _UpdateSlides() { _PartyMode.GameData.NumFields = _SelectSlides[_SelectSlideNumFields].SelectedTag; _PartyMode.GameData.RefillJokers = (EOffOn)_SelectSlides[_SelectSlideRefillJokers].Selection; + _PartyMode.GameData.SwitchPlayer = (EOffOn)_SelectSlides[_SelectSlideSwitchPlayer].Selection; } } } \ No newline at end of file diff --git a/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeMain.cs b/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeMain.cs index a2722ed4..6143e9c4 100644 --- a/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeMain.cs +++ b/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeMain.cs @@ -17,6 +17,7 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Windows.Forms; using VocaluxeLib.Menu; using VocaluxeLib.Songs; @@ -33,7 +34,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe // ReSharper disable UnusedMember.Global public class CPartyScreenTicTacToeMain : CPartyScreenTicTacToe - // ReSharper restore UnusedMember.Global + // ReSharper restore UnusedMember.Global { // Version number for theme files. Increment it, if you've changed something on the theme files! protected override int _ScreenVersion @@ -60,6 +61,8 @@ namespace VocaluxeLib.PartyModes.TicTacToe private const string _ButtonJokerRandomT2 = "ButtonJokerRandomT2"; private const string _ButtonJokerRetryT1 = "ButtonJokerRetryT1"; private const string _ButtonJokerRetryT2 = "ButtonJokerRetryT2"; + private const string _ButtonSwitchPlayerT1 = "ButtonSwitchPlayerT1"; + private const string _ButtonSwitchPlayerT2 = "ButtonSwitchPlayerT2"; private const string _StaticPopupBG = "StaticPopupBG"; private const string _StaticAvatarT1 = "StaticAvatarT1"; @@ -78,6 +81,9 @@ namespace VocaluxeLib.PartyModes.TicTacToe private const int _FieldSpace = 10; private float _FieldSize = 100; + int idPlayer1 = 0; + int idPlayer2 = 0; + private int _OldSelectedField = -1; private int[,] _Possibilities; @@ -94,7 +100,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe _ButtonNextRound, _ButtonBack, _ButtonExit, _ButtonPopupYes, _ButtonPopupNo, _ButtonField, _ButtonJokerRandomT1, _ButtonJokerRandomT2, _ButtonJokerRetryT1, _ButtonJokerRetryT2 }; - _ThemeStatics = new string[] {_StaticPopupBG, _StaticAvatarT1, _StaticAvatarT2, _StaticTeam1, _StaticTeam2}; + _ThemeStatics = new string[] { _StaticPopupBG, _StaticAvatarT1, _StaticAvatarT2, _StaticTeam1, _StaticTeam2 }; var texts = new List(); texts.AddRange(_EqualizerTeam); @@ -116,7 +122,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe { base.HandleInput(keyEvent); - if (keyEvent.KeyPressed) {} + if (keyEvent.KeyPressed) { } else { switch (keyEvent.Key) @@ -243,6 +249,10 @@ namespace VocaluxeLib.PartyModes.TicTacToe _UseJoker(0, 1); if (_Buttons[_ButtonJokerRetryT2].Selected) _UseJoker(1, 1); + if (_Buttons[_ButtonSwitchPlayerT1].Selected) + _ChangePlayer(0, true); + if (_Buttons[_ButtonSwitchPlayerT2].Selected) + _ChangePlayer(1, true); } } else @@ -269,7 +279,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe _ShowPopup(false); } - if (mouseEvent.Wheel != 0) {} + if (mouseEvent.Wheel != 0) { } return true; } @@ -323,6 +333,8 @@ namespace VocaluxeLib.PartyModes.TicTacToe _Buttons[_ButtonJokerRandomT2].Visible = false; _Buttons[_ButtonJokerRetryT1].Visible = false; _Buttons[_ButtonJokerRetryT2].Visible = false; + _Buttons[_ButtonSwitchPlayerT1].Visible = false; + _Buttons[_ButtonSwitchPlayerT2].Visible = false; _Buttons[_ButtonNextRound].Visible = false; _Texts[_TextFinishMessage].Visible = false; } @@ -357,9 +369,9 @@ namespace VocaluxeLib.PartyModes.TicTacToe for (int i = 0; i < 2; i++) { CBase.Record.AnalyzeBuffer(i); - _Equalizers["EqualizerTeam" + (i+1)].Update(CBase.Record.ToneWeigth(i), CBase.Record.GetMaxVolume(i)); + _Equalizers["EqualizerTeam" + (i + 1)].Update(CBase.Record.ToneWeigth(i), CBase.Record.GetMaxVolume(i)); } - + return true; } @@ -453,38 +465,22 @@ namespace VocaluxeLib.PartyModes.TicTacToe { if (!jokerUsed) { - int singerTeam1 = 0; - int singerTeam2 = 0; - - if (_PartyMode.GameData.PlayerTeam1.Count > 0) - { - singerTeam1 = _PartyMode.GameData.PlayerTeam1[0]; - _PartyMode.GameData.PlayerTeam1.RemoveAt(0); - } - - if (_PartyMode.GameData.PlayerTeam2.Count > 0) - { - singerTeam2 = _PartyMode.GameData.PlayerTeam2[0]; - _PartyMode.GameData.PlayerTeam2.RemoveAt(0); - } - _PartyMode.GameData.Rounds[_PartyMode.GameData.FieldNr].SingerTeam1 = singerTeam1; - _PartyMode.GameData.Rounds[_PartyMode.GameData.FieldNr].SingerTeam2 = singerTeam2; - - _UpdatePlayerInformation(); + _ChangePlayer(); } _PartyMode.UpdateSongList(); int[] songIDs = new int[_PartyMode.GameData.GameMode == EGameMode.TR_GAMEMODE_MEDLEY ? _PartyMode.GameData.NumMedleySongs : 1]; - for(int i = 0; i < songIDs.Length; i++) + for (int i = 0; i < songIDs.Length; i++) { songIDs[i] = _PartyMode.GameData.Songs[0]; _PartyMode.GameData.Songs.RemoveAt(0); - } + } _StartPreview(songIDs[0]); _Status = EStatus.FieldSelected; _PartyMode.GameData.Rounds[_PartyMode.GameData.FieldNr].SongIDs = songIDs; _UpdateFieldContents(); _UpdateJokerButtons(); + _UpdateSwitchPlayerButtons(); _Buttons[_ButtonNextRound].Visible = true; _Buttons[_ButtonExit].Visible = true; @@ -519,6 +515,60 @@ namespace VocaluxeLib.PartyModes.TicTacToe CBase.BackgroundMusic.LoadPreview(song); } + private int _GetRamdom(int max) + { + var rnd = new Random(); + return Enumerable + .Range(1, max) + .OrderBy(x => rnd.Next()) + .ToArray()[0]; + } + + private void _ChangePlayer(int teamNr = -1, bool next = false) + { + int singerTeam1 = 0; + int singerTeam2 = 0; + + if (_PartyMode.GameData.PlayerTeam1.Count > 0 && (teamNr == 0 || teamNr == -1)) + { + if (next == true) + { + idPlayer1++; + if (idPlayer1 >= _PartyMode.GameData.PlayerTeam1.Count) + { + idPlayer1 = 0; + } + } + else + { + idPlayer1 = _GetRamdom(_PartyMode.GameData.PlayerTeam1.Count - 1); + } + + singerTeam1 = _PartyMode.GameData.PlayerTeam1[idPlayer1]; + _PartyMode.GameData.Rounds[_PartyMode.GameData.FieldNr].SingerTeam1 = singerTeam1; + } + + if (_PartyMode.GameData.PlayerTeam2.Count > 0 && (teamNr == 1 || teamNr == -1)) + { + if (next == true) + { + idPlayer2++; + if (idPlayer2 >= _PartyMode.GameData.PlayerTeam2.Count) + { + idPlayer2 = 0; + } + } + else + { + idPlayer2 = _GetRamdom(_PartyMode.GameData.PlayerTeam2.Count - 1); + } + singerTeam2 = _PartyMode.GameData.PlayerTeam2[idPlayer2]; + _PartyMode.GameData.Rounds[_PartyMode.GameData.FieldNr].SingerTeam2 = singerTeam2; + } + + _UpdatePlayerInformation(); + } + private void _UpdatePlayerInformation() { _Texts[_TextNextPlayerT1].Visible = true; @@ -543,7 +593,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe { switch (jokerNum) { - //Random-Joker + //Random-Joker case 0: if (_PartyMode.GameData.NumJokerRandom[teamNr] > 0) { @@ -552,7 +602,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe } break; - //Retry-Joker + //Retry-Joker case 1: if (_PartyMode.GameData.NumJokerRetry[teamNr] > 0 && _PartyMode.GameData.CurrentRoundNr > 1) { @@ -596,6 +646,16 @@ namespace VocaluxeLib.PartyModes.TicTacToe _Buttons[_ButtonJokerRetryT2].Selectable = _PartyMode.GameData.NumJokerRetry[1] > 0 && _PartyMode.GameData.CurrentRoundNr > 1; } + private void _UpdateSwitchPlayerButtons() + { + if (_PartyMode.GameData.SwitchPlayer == EOffOn.TR_CONFIG_ON) + { + _Buttons[_ButtonSwitchPlayerT1].Visible = true; + _Buttons[_ButtonSwitchPlayerT2].Visible = true; + } + + } + private void _NextRound() { _PartyMode.Next(); @@ -627,7 +687,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe private void _BuildWinnerPossibilities() { var numOneRow = (int)Math.Sqrt(_PartyMode.GameData.NumFields); - _Possibilities = new int[(numOneRow * 2) + 2,numOneRow]; + _Possibilities = new int[(numOneRow * 2) + 2, numOneRow]; for (int i = 0; i < _Possibilities.GetLength(0); i++) { if (i < numOneRow) diff --git a/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeNames.cs b/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeNames.cs index 49241507..04e8b91f 100644 --- a/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeNames.cs +++ b/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeNames.cs @@ -17,6 +17,7 @@ using System; using System.Collections.Generic; +using System.Linq; using VocaluxeLib.Menu; namespace VocaluxeLib.PartyModes.TicTacToe @@ -76,11 +77,9 @@ namespace VocaluxeLib.PartyModes.TicTacToe _PartyMode.GameData.ProfileIDsTeam1 = _TeamList[0]; _PartyMode.GameData.ProfileIDsTeam2 = _TeamList[1]; } - if (_NumPlayerTeams.Length == 2) - { - _PartyMode.GameData.NumPlayerTeam1 = _NumPlayerTeams[0]; - _PartyMode.GameData.NumPlayerTeam2 = _NumPlayerTeams[1]; - } + _PartyMode.GameData.NumPlayerTeam1 = _PartyMode.GameData.ProfileIDsTeam1.Count(); + _PartyMode.GameData.NumPlayerTeam2 = _PartyMode.GameData.ProfileIDsTeam2.Count(); + _PartyMode.Next(); } } From cfca322fcdc999509b4e7a4fa250e1e596136643 Mon Sep 17 00:00:00 2001 From: Damien LAGUERRE Date: Fri, 22 Dec 2023 15:47:15 +0100 Subject: [PATCH 2/5] Improves the random choice of players. --- .../PartyModeTicTacToe/CPartyModeTicTacToe.cs | 111 ------------------ .../CPartyScreenTicTacToeMain.cs | 35 +++--- 2 files changed, 17 insertions(+), 129 deletions(-) diff --git a/PartyModes/PartyModeTicTacToe/CPartyModeTicTacToe.cs b/PartyModes/PartyModeTicTacToe/CPartyModeTicTacToe.cs index c1dab85b..2ec3499c 100644 --- a/PartyModes/PartyModeTicTacToe/CPartyModeTicTacToe.cs +++ b/PartyModes/PartyModeTicTacToe/CPartyModeTicTacToe.cs @@ -107,8 +107,6 @@ namespace VocaluxeLib.PartyModes.TicTacToe public int Team; public List ProfileIDsTeam1; public List ProfileIDsTeam2; - public List PlayerTeam1; - public List PlayerTeam2; public ESongSource SongSource; public ESongSorting Sorting; @@ -152,8 +150,6 @@ namespace VocaluxeLib.PartyModes.TicTacToe NumFields = 9, ProfileIDsTeam1 = new List(), ProfileIDsTeam2 = new List(), - PlayerTeam1 = new List(), - PlayerTeam2 = new List(), CurrentRoundNr = 0, FieldNr = 0, Sorting = CBase.Config.GetSongSorting(), @@ -184,8 +180,6 @@ namespace VocaluxeLib.PartyModes.TicTacToe GameData.Songs.Clear(); GameData.Rounds.Clear(); - GameData.PlayerTeam1.Clear(); - GameData.PlayerTeam2.Clear(); } public override bool Init() @@ -248,7 +242,6 @@ namespace VocaluxeLib.PartyModes.TicTacToe GameData.CurrentRoundNr = 1; _CreateRounds(); _SetNumJokers(); - _PreparePlayerList(0); break; case EStage.Main: _Stage = EStage.Singing; @@ -257,7 +250,6 @@ namespace VocaluxeLib.PartyModes.TicTacToe case EStage.Singing: _Stage = EStage.Main; GameData.Team = GameData.Team == 1 ? 0 : 1; - _UpdatePlayerList(); if (GameData.RefillJokers == EOffOn.TR_CONFIG_ON) _SetNumJokers(); break; @@ -338,101 +330,6 @@ namespace VocaluxeLib.PartyModes.TicTacToe } } - private void _PreparePlayerList(int team) - { - switch (team) - { - case 0: - { - GameData.PlayerTeam1 = new List(); - GameData.PlayerTeam2 = new List(); - - //Prepare Player-IDs - var ids1 = new List(); - var ids2 = new List(); - //Add IDs to team-list - while (GameData.PlayerTeam1.Count < GameData.NumFields + GameData.NumJokerRetry[0] && - GameData.PlayerTeam2.Count < GameData.NumFields + GameData.NumJokerRetry[1]) - { - if (ids1.Count == 0) - { - for (int i = 0; i < GameData.NumPlayerTeam1; i++) - ids1.Add(i); - } - if (ids2.Count == 0) - { - for (int i = 0; i < GameData.NumPlayerTeam2; i++) - ids2.Add(i); - } - int num; - if (GameData.PlayerTeam1.Count < GameData.NumFields + GameData.NumJokerRetry[0]) - { - num = CBase.Game.GetRandom(ids1.Count); - if (num >= ids1.Count) - num = ids1.Count - 1; - GameData.PlayerTeam1.Add(ids1[num]); - ids1.RemoveAt(num); - } - if (GameData.PlayerTeam2.Count < GameData.NumFields + GameData.NumJokerRetry[1]) - { - num = CBase.Game.GetRandom(ids2.Count); - if (num >= ids2.Count) - num = ids2.Count - 1; - GameData.PlayerTeam2.Add(ids2[num]); - ids2.RemoveAt(num); - } - } - } - break; - case 1: - { - //Prepare Player-IDs - var ids = new List(); - //Add IDs to team-list - while (GameData.PlayerTeam1.Count < GameData.NumFields + GameData.NumJokerRetry[0] && ids.Count == 0) - { - if (ids.Count == 0) - { - for (int i = 0; i < GameData.NumPlayerTeam1; i++) - ids.Add(i); - } - if (GameData.PlayerTeam1.Count < GameData.NumFields + GameData.NumJokerRetry[0]) - { - int num = CBase.Game.GetRandom(ids.Count); - if (num >= ids.Count) - num = ids.Count - 1; - GameData.PlayerTeam1.Add(ids[num]); - ids.RemoveAt(num); - } - } - } - break; - case 2: - { - //Prepare Player-IDs - var ids = new List(); - //Add IDs to team-list - while (GameData.PlayerTeam2.Count < GameData.NumFields + GameData.NumJokerRetry[1] && ids.Count == 0) - { - if (ids.Count == 0) - { - for (int i = 0; i < GameData.NumPlayerTeam2; i++) - ids.Add(i); - } - if (GameData.PlayerTeam2.Count < GameData.NumFields + GameData.NumJokerRetry[1]) - { - int num = CBase.Game.GetRandom(ids.Count); - if (num >= ids.Count) - num = ids.Count - 1; - GameData.PlayerTeam2.Add(ids[num]); - ids.RemoveAt(num); - } - } - } - break; - } - } - public void UpdateSongList() { if (GameData.Songs.Count > 0) @@ -466,14 +363,6 @@ namespace VocaluxeLib.PartyModes.TicTacToe GameData.Songs.Shuffle(); } - private void _UpdatePlayerList() - { - if (GameData.PlayerTeam1.Count == 0) - _PreparePlayerList(1); - if (GameData.PlayerTeam2.Count == 0) - _PreparePlayerList(2); - } - private void _StartRound(int roundNr) { CBase.Game.Reset(); diff --git a/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeMain.cs b/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeMain.cs index 6143e9c4..72f46d68 100644 --- a/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeMain.cs +++ b/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeMain.cs @@ -84,6 +84,9 @@ namespace VocaluxeLib.PartyModes.TicTacToe int idPlayer1 = 0; int idPlayer2 = 0; + private static readonly Random random = new Random(); + private static readonly object syncLock = new object(); + private int _OldSelectedField = -1; private int[,] _Possibilities; @@ -98,7 +101,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe _ThemeButtons = new string[] { _ButtonNextRound, _ButtonBack, _ButtonExit, _ButtonPopupYes, _ButtonPopupNo, _ButtonField, _ButtonJokerRandomT1, _ButtonJokerRandomT2, _ButtonJokerRetryT1, - _ButtonJokerRetryT2 + _ButtonJokerRetryT2, _ButtonSwitchPlayerT1, _ButtonSwitchPlayerT2 }; _ThemeStatics = new string[] { _StaticPopupBG, _StaticAvatarT1, _StaticAvatarT2, _StaticTeam1, _StaticTeam2 }; @@ -517,53 +520,49 @@ namespace VocaluxeLib.PartyModes.TicTacToe private int _GetRamdom(int max) { - var rnd = new Random(); - return Enumerable - .Range(1, max) - .OrderBy(x => rnd.Next()) - .ToArray()[0]; + lock (syncLock) + { + return random.Next(max+1); + } } private void _ChangePlayer(int teamNr = -1, bool next = false) { - int singerTeam1 = 0; - int singerTeam2 = 0; - if (_PartyMode.GameData.PlayerTeam1.Count > 0 && (teamNr == 0 || teamNr == -1)) + if (_PartyMode.GameData.ProfileIDsTeam1.Count > 0 && (teamNr == 0 || teamNr == -1)) { if (next == true) { idPlayer1++; - if (idPlayer1 >= _PartyMode.GameData.PlayerTeam1.Count) + if (idPlayer1 >= _PartyMode.GameData.ProfileIDsTeam1.Count) { idPlayer1 = 0; } } else { - idPlayer1 = _GetRamdom(_PartyMode.GameData.PlayerTeam1.Count - 1); + idPlayer1 = _GetRamdom(_PartyMode.GameData.ProfileIDsTeam1.Count - 1); } - singerTeam1 = _PartyMode.GameData.PlayerTeam1[idPlayer1]; - _PartyMode.GameData.Rounds[_PartyMode.GameData.FieldNr].SingerTeam1 = singerTeam1; + _PartyMode.GameData.Rounds[_PartyMode.GameData.FieldNr].SingerTeam1 = idPlayer1; } - if (_PartyMode.GameData.PlayerTeam2.Count > 0 && (teamNr == 1 || teamNr == -1)) + if (_PartyMode.GameData.ProfileIDsTeam2.Count > 0 && (teamNr == 1 || teamNr == -1)) { if (next == true) { idPlayer2++; - if (idPlayer2 >= _PartyMode.GameData.PlayerTeam2.Count) + if (idPlayer2 >= _PartyMode.GameData.ProfileIDsTeam2.Count) { idPlayer2 = 0; } } else { - idPlayer2 = _GetRamdom(_PartyMode.GameData.PlayerTeam2.Count - 1); + idPlayer2 = _GetRamdom(_PartyMode.GameData.ProfileIDsTeam2.Count - 1); } - singerTeam2 = _PartyMode.GameData.PlayerTeam2[idPlayer2]; - _PartyMode.GameData.Rounds[_PartyMode.GameData.FieldNr].SingerTeam2 = singerTeam2; + + _PartyMode.GameData.Rounds[_PartyMode.GameData.FieldNr].SingerTeam2 = idPlayer2; } _UpdatePlayerInformation(); From 5360b997454bde2fee419eaf8c9be73c4a78a575 Mon Sep 17 00:00:00 2001 From: Damien LAGUERRE Date: Fri, 22 Dec 2023 17:16:18 +0100 Subject: [PATCH 3/5] Add number of jocker as game parameter. + Missing input handler for player switch action. --- .../PartyModeTicTacToe/CPartyModeTicTacToe.cs | 12 ++++++------ .../CPartyScreenTicTacToeConfig.cs | 13 ++++++++++++- .../PartyModeTicTacToe/CPartyScreenTicTacToeMain.cs | 4 ++++ 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/PartyModes/PartyModeTicTacToe/CPartyModeTicTacToe.cs b/PartyModes/PartyModeTicTacToe/CPartyModeTicTacToe.cs index 2ec3499c..6a911fcd 100644 --- a/PartyModes/PartyModeTicTacToe/CPartyModeTicTacToe.cs +++ b/PartyModes/PartyModeTicTacToe/CPartyModeTicTacToe.cs @@ -104,6 +104,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe public int NumPlayerTeam1; public int NumPlayerTeam2; public int NumFields; + public int NumJockers; public int Team; public List ProfileIDsTeam1; public List ProfileIDsTeam2; @@ -148,6 +149,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe NumPlayerTeam1 = 2, NumPlayerTeam2 = 2, NumFields = 9, + NumJockers = 1, ProfileIDsTeam1 = new List(), ProfileIDsTeam2 = new List(), CurrentRoundNr = 0, @@ -395,25 +397,23 @@ namespace VocaluxeLib.PartyModes.TicTacToe private void _SetNumJokers() { + + GameData.NumJokerRandom[0] = GameData.NumJockers; + GameData.NumJokerRandom[1] = GameData.NumJockers; + switch (GameData.NumFields) { case 9: - GameData.NumJokerRandom[0] = 1; - GameData.NumJokerRandom[1] = 1; GameData.NumJokerRetry[0] = 0; GameData.NumJokerRetry[1] = 0; break; case 16: - GameData.NumJokerRandom[0] = 2; - GameData.NumJokerRandom[1] = 2; GameData.NumJokerRetry[0] = 1; GameData.NumJokerRetry[1] = 1; break; case 25: - GameData.NumJokerRandom[0] = 3; - GameData.NumJokerRandom[1] = 3; GameData.NumJokerRetry[0] = 2; GameData.NumJokerRetry[1] = 2; break; diff --git a/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeConfig.cs b/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeConfig.cs index 16fd7836..8e0fdc8a 100644 --- a/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeConfig.cs +++ b/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeConfig.cs @@ -35,7 +35,9 @@ namespace VocaluxeLib.PartyModes.TicTacToe } private const string _SelectSlideNumFields = "SelectSlideNumFields"; + private const string _SelectSlideNumJockers = "SelectSlideNumJockers"; private const string _SelectSlideRefillJokers = "SelectSlideRefillJokers"; + private const string _SelectSlideNumJokers = "SelectSlideNumJokers"; private const string _SelectSlideSwitchPlayer = "SelectSlideSwitchPlayer"; private const string _ButtonNext = "ButtonNext"; @@ -47,7 +49,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe { base.Init(); - _ThemeSelectSlides = new string[] { _SelectSlideNumFields }; + _ThemeSelectSlides = new string[] { _SelectSlideNumFields, _SelectSlideNumJokers, _SelectSlideRefillJokers, _SelectSlideSwitchPlayer }; _ThemeButtons = new string[] {_ButtonNext, _ButtonBack}; } @@ -132,6 +134,14 @@ namespace VocaluxeLib.PartyModes.TicTacToe _SelectSlides[_SelectSlideNumFields].SelectedTag = _PartyMode.GameData.NumFields; + _SelectSlides[_SelectSlideNumJockers].Clear(); + _SelectSlides[_SelectSlideNumJockers].AddValue(0); + _SelectSlides[_SelectSlideNumJockers].AddValue(1); + _SelectSlides[_SelectSlideNumJockers].AddValue(2); + _SelectSlides[_SelectSlideNumJockers].AddValue(3); + + _SelectSlides[_SelectSlideNumJockers].SelectedTag = _PartyMode.GameData.NumJockers; + _SelectSlides[_SelectSlideRefillJokers].AddValues(Enum.GetNames(typeof(EOffOn))); _SelectSlides[_SelectSlideRefillJokers].Selection = (int)_PartyMode.GameData.RefillJokers; @@ -142,6 +152,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe private void _UpdateSlides() { _PartyMode.GameData.NumFields = _SelectSlides[_SelectSlideNumFields].SelectedTag; + _PartyMode.GameData.NumJockers = _SelectSlides[_SelectSlideNumJockers].Selection; _PartyMode.GameData.RefillJokers = (EOffOn)_SelectSlides[_SelectSlideRefillJokers].Selection; _PartyMode.GameData.SwitchPlayer = (EOffOn)_SelectSlides[_SelectSlideSwitchPlayer].Selection; } diff --git a/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeMain.cs b/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeMain.cs index 72f46d68..b52671e1 100644 --- a/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeMain.cs +++ b/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeMain.cs @@ -187,6 +187,10 @@ namespace VocaluxeLib.PartyModes.TicTacToe _UseJoker(0, 1); if (_Buttons[_ButtonJokerRetryT2].Selected) _UseJoker(1, 1); + if (_Buttons[_ButtonSwitchPlayerT1].Selected) + _ChangePlayer(0, true); + if (_Buttons[_ButtonSwitchPlayerT2].Selected) + _ChangePlayer(1, true); } } else From fddd2f3f2fdd40dfa75aa859b9fe6884396ebc6a Mon Sep 17 00:00:00 2001 From: Damien LAGUERRE Date: Fri, 22 Dec 2023 17:46:03 +0100 Subject: [PATCH 4/5] TicTacToe: Add jockers select to config screen. + Translation. --- .../TicTacToe/Languages/English.xml | 1 + .../PartyModes/TicTacToe/Languages/French.xml | 1 + .../Screens/PartyScreenTicTacToeConfig.xml | 68 +++++++++++++++++-- 3 files changed, 64 insertions(+), 6 deletions(-) diff --git a/Output/PartyModes/TicTacToe/Languages/English.xml b/Output/PartyModes/TicTacToe/Languages/English.xml index 1581f008..49e44511 100644 --- a/Output/PartyModes/TicTacToe/Languages/English.xml +++ b/Output/PartyModes/TicTacToe/Languages/English.xml @@ -18,6 +18,7 @@ Number of players in team 2 Number of fields Refill jokers every round + Number of jokers Switch player Tic-Tac-Toe: Choose Player Selected players for this team: diff --git a/Output/PartyModes/TicTacToe/Languages/French.xml b/Output/PartyModes/TicTacToe/Languages/French.xml index e37c90ab..73413bae 100644 --- a/Output/PartyModes/TicTacToe/Languages/French.xml +++ b/Output/PartyModes/TicTacToe/Languages/French.xml @@ -18,6 +18,7 @@ Nombre de joueurs dans l'Equipe 2 Nombre de champs Recharger les jokers a chaque tour + Nombre de jokers Changement de joueur Tic-Tac-Toe: Choix des joueurs Equipe 1 diff --git a/Output/PartyModes/TicTacToe/Themes/Default/Screens/PartyScreenTicTacToeConfig.xml b/Output/PartyModes/TicTacToe/Themes/Default/Screens/PartyScreenTicTacToeConfig.xml index 5d645321..c879b56a 100644 --- a/Output/PartyModes/TicTacToe/Themes/Default/Screens/PartyScreenTicTacToeConfig.xml +++ b/Output/PartyModes/TicTacToe/Themes/Default/Screens/PartyScreenTicTacToeConfig.xml @@ -55,7 +55,7 @@ Outline TR_SCREENCONFIG_NUMFIELDS - + 75 165 0 @@ -67,11 +67,25 @@ Center Outline + TR_SCREENCONFIG_NUMJOKERS + + + 75 + 225 + 0 + 27 + 0 + + + Left + Center + + Outline TR_SCREENCONFIG_REFILLJOKERS 75 - 210 + 285 0 27 0 @@ -201,7 +215,7 @@ Bold 3 - + SelectSlideArrowLeft SelectSlideArrowRight @@ -241,6 +255,48 @@ 205.33 Outline Bold + 3 + + + + SelectSlideArrowLeft + SelectSlideArrowRight + SelectSlide + SelectSlideArrowLeft + SelectSlideArrowRight + + 500 + 220 + 700 + 50 + 0 + + + 505 + 225 + 40 + 40 + 0 + + + 1155 + 225 + 40 + 40 + 0 + + + + + + + + 27 + 50 + 0 + 205.33 + Outline + Bold 2 @@ -252,21 +308,21 @@ SelectSlideArrowRight 500 - 210 + 270 700 50 0 505 - 215 + 275 40 40 0 1155 - 215 + 275 40 40 0 From b7938ba71cd1790e62f18ff57a0b8b86a5a02c02 Mon Sep 17 00:00:00 2001 From: Damien LAGUERRE Date: Sat, 23 Dec 2023 19:50:07 +0100 Subject: [PATCH 5/5] TicTacToe: Optimisation and code compliance --- .../CPartyScreenTicTacToeConfig.cs | 12 ++--- .../CPartyScreenTicTacToeMain.cs | 49 ++++++++----------- .../CPartyScreenTicTacToeNames.cs | 4 +- 3 files changed, 28 insertions(+), 37 deletions(-) diff --git a/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeConfig.cs b/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeConfig.cs index 8e0fdc8a..0d68bb52 100644 --- a/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeConfig.cs +++ b/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeConfig.cs @@ -26,7 +26,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe { // ReSharper disable UnusedMember.Global public class CPartyScreenTicTacToeConfig : CPartyScreenTicTacToe - // ReSharper restore UnusedMember.Global + // ReSharper restore UnusedMember.Global { // Version number for theme files. Increment it, if you've changed something on the theme files! protected override int _ScreenVersion @@ -50,14 +50,14 @@ namespace VocaluxeLib.PartyModes.TicTacToe base.Init(); _ThemeSelectSlides = new string[] { _SelectSlideNumFields, _SelectSlideNumJokers, _SelectSlideRefillJokers, _SelectSlideSwitchPlayer }; - _ThemeButtons = new string[] {_ButtonNext, _ButtonBack}; + _ThemeButtons = new string[] { _ButtonNext, _ButtonBack }; } public override bool HandleInput(SKeyEvent keyEvent) { base.HandleInput(keyEvent); - if (keyEvent.KeyPressed) {} + if (keyEvent.KeyPressed) { } else { switch (keyEvent.Key) @@ -135,10 +135,8 @@ namespace VocaluxeLib.PartyModes.TicTacToe _SelectSlides[_SelectSlideNumFields].SelectedTag = _PartyMode.GameData.NumFields; _SelectSlides[_SelectSlideNumJockers].Clear(); - _SelectSlides[_SelectSlideNumJockers].AddValue(0); - _SelectSlides[_SelectSlideNumJockers].AddValue(1); - _SelectSlides[_SelectSlideNumJockers].AddValue(2); - _SelectSlides[_SelectSlideNumJockers].AddValue(3); + for (int i = 0; i <= 3; i++) + _SelectSlides[_SelectSlideNumJockers].AddValue(i); _SelectSlides[_SelectSlideNumJockers].SelectedTag = _PartyMode.GameData.NumJockers; diff --git a/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeMain.cs b/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeMain.cs index b52671e1..9f04452d 100644 --- a/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeMain.cs +++ b/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeMain.cs @@ -81,8 +81,8 @@ namespace VocaluxeLib.PartyModes.TicTacToe private const int _FieldSpace = 10; private float _FieldSize = 100; - int idPlayer1 = 0; - int idPlayer2 = 0; + private int idPlayer1 = 0; + private int idPlayer2 = 0; private static readonly Random random = new Random(); private static readonly object syncLock = new object(); @@ -535,43 +535,36 @@ namespace VocaluxeLib.PartyModes.TicTacToe if (_PartyMode.GameData.ProfileIDsTeam1.Count > 0 && (teamNr == 0 || teamNr == -1)) { - if (next == true) - { - idPlayer1++; - if (idPlayer1 >= _PartyMode.GameData.ProfileIDsTeam1.Count) - { - idPlayer1 = 0; - } - } - else - { - idPlayer1 = _GetRamdom(_PartyMode.GameData.ProfileIDsTeam1.Count - 1); - } - + idPlayer1 = _GetTeamPlayer(idPlayer1, _PartyMode.GameData.ProfileIDsTeam1.Count, next); _PartyMode.GameData.Rounds[_PartyMode.GameData.FieldNr].SingerTeam1 = idPlayer1; } if (_PartyMode.GameData.ProfileIDsTeam2.Count > 0 && (teamNr == 1 || teamNr == -1)) { - if (next == true) - { - idPlayer2++; - if (idPlayer2 >= _PartyMode.GameData.ProfileIDsTeam2.Count) - { - idPlayer2 = 0; - } - } - else - { - idPlayer2 = _GetRamdom(_PartyMode.GameData.ProfileIDsTeam2.Count - 1); - } - + idPlayer2 = _GetTeamPlayer(idPlayer2, _PartyMode.GameData.ProfileIDsTeam2.Count, next); _PartyMode.GameData.Rounds[_PartyMode.GameData.FieldNr].SingerTeam2 = idPlayer2; } _UpdatePlayerInformation(); } + private int _GetTeamPlayer(int idPlayer, int teamCount, bool next) + { + if (next) + { + idPlayer++; + if (idPlayer >= _PartyMode.GameData.ProfileIDsTeam1.Count) + { + idPlayer = 0; + } + } + else + { + idPlayer = _GetRamdom(_PartyMode.GameData.ProfileIDsTeam1.Count - 1); + } + return idPlayer; + } + private void _UpdatePlayerInformation() { _Texts[_TextNextPlayerT1].Visible = true; diff --git a/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeNames.cs b/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeNames.cs index 04e8b91f..875000e7 100644 --- a/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeNames.cs +++ b/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeNames.cs @@ -77,8 +77,8 @@ namespace VocaluxeLib.PartyModes.TicTacToe _PartyMode.GameData.ProfileIDsTeam1 = _TeamList[0]; _PartyMode.GameData.ProfileIDsTeam2 = _TeamList[1]; } - _PartyMode.GameData.NumPlayerTeam1 = _PartyMode.GameData.ProfileIDsTeam1.Count(); - _PartyMode.GameData.NumPlayerTeam2 = _PartyMode.GameData.ProfileIDsTeam2.Count(); + _PartyMode.GameData.NumPlayerTeam1 = _PartyMode.GameData.ProfileIDsTeam1.Count; + _PartyMode.GameData.NumPlayerTeam2 = _PartyMode.GameData.ProfileIDsTeam2.Count; _PartyMode.Next(); }