private void ModelBlockChangedEventHandler(object sender, BlockChangedEventArgs e) { if (!e.Disappeared) { if (!_blocksByPosition.Keys.Contains(e.BlockUpdated.Position)) { // Create a new BlockControl. var blockControl = TetrisControlHelper.BlockControlFactory(e.BlockUpdated, Scale); _blocksByPosition.Add(e.BlockUpdated.Position, blockControl); _sprites.Add(blockControl); } else { // In this case we come across a overdrawn block, that is, has been called 'appeared' twice. // Should this scenario happen, we simply ignore this. // TODO: Check if this scenario is reasonable. } } else { if (_blocksByPosition.Keys.Contains(e.BlockUpdated.Position)) { _sprites.Remove(_blocksByPosition[e.BlockUpdated.Position]); _blocksByPosition.Remove(e.BlockUpdated.Position); } } }
private void RecreateAssistGrids() { foreach (var line in _assistGridLines) { if (_sprites.Contains(line)) { _sprites.Remove(line); } } _assistGridLines.Clear(); if (!RenderGridAssistance) { return; } for (var x = 0; x < TetrisConst.PlayAreaWidth; x++) { var scanLine = TetrisControlHelper.VerticalAssistGridLineFactory( x, TetrisConst.PlayAreaHeight, Scale); _assistGridLines.Add(scanLine); _sprites.Add(scanLine); } for (var y = 0; y < TetrisConst.PlayAreaHeight; y++) { var scanLine = TetrisControlHelper.HorizontalAssistGridLineFactory( y, TetrisConst.PlayAreaWidth, Scale); _assistGridLines.Add(scanLine); _sprites.Add(scanLine); } }
private void ModelBlockChangedEventHandler(object sender, BlockChangedEventArgs e) { if (!e.Disappeared) { if (!_blocksByPosition.Keys.Contains(e.BlockUpdated.Position)) { // Create a new BlockControl. var blockControl = TetrisControlHelper.AnnotatedBlockControlFactory(e.BlockUpdated, RenderColors, Scale); _blocksByPosition.Add(e.BlockUpdated.Position, blockControl); _sprites.Add(blockControl); } } else { if (_blocksByPosition.Keys.Contains(e.BlockUpdated.Position)) { _sprites.Remove(_blocksByPosition[e.BlockUpdated.Position]); _blocksByPosition.Remove(e.BlockUpdated.Position); } } }