/// <summary> /// Konstruktor spinnera /// </summary> /// <param name="reels">Walce do kręcenia</param> public Spinner(SpinnerConfig config) { Ensure.ParamNotNull(config, nameof(config)); _spin = config.Spin; _linesSearcher = new LinesSearcher(config.Lines); this.Lines = config.Lines; this.Rno = config.Rno; _reels = config.Reels; _payLinesQuantity = config.PayLines; this.PayLines = this.CreateInitialWinningLine(config); }
/// <summary> /// Helper tworzący początkowe ustawienia walców. Początkowa pozycja brana jest z <see cref="SpinnerConfig.Rno"/> /// </summary> /// <param name="config">Konfiguracja spinnera</param> /// <returns>Linie ustalane na początku gry.</returns> private PayLine[] CreateInitialWinningLine(SpinnerConfig config) { PayLine[] winningLines = new PayLine[config.PayLines]; Dictionary <int, Dictionary <int, int> > reelSymbolsOccurance = this.CreateSymbolsOccurancesTable(); int[] previousLine = null; for (int lineIndex = config.Rno, done = 0, maxAttemptesAfterFail = config.Lines.Length; done < config.PayLines && maxAttemptesAfterFail > 0; lineIndex++, done++) { if (lineIndex > config.Lines.Length - 1) { //Przekręcamy licznik lineIndex = 0; } int[] line = config.Lines[lineIndex]; if (this.IsLineValid(reelSymbolsOccurance, line, previousLine) == false) { done--; // Podejmiemy tyle prób, ile jest linii maxAttemptesAfterFail--; // Przechodzimy do następnej linii, bo tej wziąć nie możemy continue; } // Dodajemy do wyników nową linię winningLines[done] = new PayLine(lineIndex, line); // Podbijamy occurance dla każdego symbolu for (int reel = 0; reel < line.Length; reel++) { int reelSymbol = line[reel]; reelSymbolsOccurance[reel][reelSymbol]++; } previousLine = line; } return(winningLines); }
public void Spinner_Create() { const int initialRno = 3; const int initialPayLinesCount = 1; int[] reel1 = new int[] { 4, 5, 6 }; int[] reel2 = new int[] { 7, 9 }; int[] reel3 = new int[] { 10, 11, 12, 15 }; Reel[] reels = new Reel[] { new Reel(reel1, 1), new Reel(reel2, 1), new Reel(reel3, 1) }; SpinnerConfig config = new SpinnerConfig(reels, new RnoConfig(initialRno), initialPayLinesCount); Spinner spinner = new Spinner(config); Assert.AreEqual(initialRno, spinner.Rno, "Wrong number of RNO"); Assert.AreEqual(initialPayLinesCount, spinner.PayLines.Count(), "Invalid number of paylines."); Assert.AreEqual(config.Lines.Length, spinner.Lines.Length, "Spinner should have the same amunt of lines as config."); }