protected List <BlockType> _blockTypeQueue; // Queue is one way /// <summary> /// Setups the randomizer /// </summary> protected void SetupBlockGenerator(Boolean level_reset = false) { // Create empty Queue if (level_reset) { _blockTypeQueue.Clear(); } else { _blockTypeQueue = new List <BlockType>(); } GenerateNextPermutation(); // First block of first bag is always I J L or T var firstAllowed = new BlockType[] { BlockType.IBlock, BlockType.JBlock, BlockType.LBlock, BlockType.TBlock }; while (!firstAllowed.Contains(_blockTypeQueue.First())) { _blockTypeQueue.Push(_blockTypeQueue.UnShift <BlockType>()); } // Generate as a block if (level_reset) { this.CurrentBlock.Block.SetBlockType(_blockTypeQueue.UnShift <BlockType>()); } else { this.CurrentBlock = new FallingBlock(this.Game, new Block(_blockTypeQueue.UnShift <BlockType>()), this); } this.CurrentBlock.Replace( (this.Width - this.CurrentBlock.Block.Width) / 2 + Block.GetBaseXPosition(this.CurrentBlock.Block.Type), this.CurrentBlock.Field.Height - 1, Block.GetStartRotation(this.CurrentBlock.Block.Type) ); // Set next block if (level_reset) { this.NextBlock.SetBlockType(_blockTypeQueue.UnShift <BlockType>()); } else { this.NextBlock = new Block(_blockTypeQueue.UnShift <BlockType>()); } this.NextBlock.Rotation = Block.GetStartRotation(this.NextBlock.Type); }
/// <summary> /// Setups the randomizer /// </summary> protected void SetupBlockGenerator(Boolean level_reset = false) { // Create empty Queue if (level_reset) _blockTypeQueue.Clear(); else _blockTypeQueue = new List<BlockType>(); GenerateNextPermutation(); // First block of first bag is always I J L or T var firstAllowed = new BlockType[] { BlockType.IBlock, BlockType.JBlock, BlockType.LBlock, BlockType.TBlock }; while (!firstAllowed.Contains(_blockTypeQueue.First())) _blockTypeQueue.Push(_blockTypeQueue.UnShift<BlockType>()); // Generate as a block if (level_reset) this.CurrentBlock.Block.SetBlockType(_blockTypeQueue.UnShift<BlockType>()); else this.CurrentBlock = new FallingBlock(this.Game, new Block(_blockTypeQueue.UnShift<BlockType>()), this); this.CurrentBlock.Replace( (this.Width - this.CurrentBlock.Block.Width) / 2 + Block.GetBaseXPosition(this.CurrentBlock.Block.Type), this.CurrentBlock.Field.Height - 1, Block.GetStartRotation(this.CurrentBlock.Block.Type) ); // Set next block if (level_reset) this.NextBlock.SetBlockType(_blockTypeQueue.UnShift<BlockType>()); else this.NextBlock = new Block(_blockTypeQueue.UnShift<BlockType>()); this.NextBlock.Rotation = Block.GetStartRotation(this.NextBlock.Type); }