private void _mouseClick(object s, MouseEventArgs e) { if (EditingMode && e.Button == MouseButtons.Left) { var block = new Block(_board, Toolbox.Orientation, Toolbox.Length, new Point(e.X / Board.BOX_SQUARE_SIZE, e.Y / Board.BOX_SQUARE_SIZE)); _board.BlockList.Add(block); Controls.Add(new BlockControl(_board, block, this)); } }
public BlockControl(Board board, Block block, BoardControl boardControl) { Id = block.Id; _board = board; _block = block; _boardControl = boardControl; BackColor = Color.Transparent; InitializeComponent(); _blockControlInit(); }
private void _addBlockToMatrix(Block block) { if (block.Orientation == Orientation.Horizontal) for (int i = 0; i < block.Size; i++) Matrix[block.Postition.Y, block.Postition.X + i] = block.Id; else for (int i = 0; i < block.Size; i++) Matrix[block.Postition.Y + i, block.Postition.X] = block.Id; }
public static Board ReadFile(string filename) { var reader = new StreamReader(filename); string line = null; var sizePtrn = @"SIZE: (\d), (\d)"; var endPtrn = @"END: (\d), (\d)"; var blockCountPtrn = @"BLOCKS: (\d)"; var blockPtrn = @"(\d),([a-zA-Z]+),(\d),(\d)\|(\d),(\d)"; Size boardSize = new Size(); Point boardEndPoint = new Point(); int boardBlockCount = 0; var blocks = new List<Block>(); int lineNum = 1; int headerLine = 0; int blockLine = 0; do { line = reader.ReadLine(); if (line == null) break; if (headerLine < 3) { if (Regex.IsMatch(line, sizePtrn)) { var groups = new Regex(sizePtrn).Match(line).Groups; boardSize = new Size(int.Parse(groups[1].Value), int.Parse(groups[2].Value)); headerLine++; } if (Regex.IsMatch(line, endPtrn)) { var groups = new Regex(endPtrn).Match(line).Groups; boardEndPoint = new Point(int.Parse(groups[1].Value), int.Parse(groups[2].Value)); headerLine++; } if (Regex.IsMatch(line, blockCountPtrn)) { var groups = new Regex(blockCountPtrn).Match(line).Groups; boardBlockCount = int.Parse(groups[1].Value); headerLine++; } } // Read the blocks else if (blockLine < boardBlockCount) { var groups = new Regex(blockPtrn).Match(line).Groups; Orientation orientation = (groups[2].Value == "Horizontal") ? Orientation.Horizontal : Orientation.Vertical; var block = new Block( null, orientation, int.Parse(groups[4].Value), new Point(int.Parse(groups[5].Value), int.Parse(groups[6].Value)), int.Parse(groups[3].Value) ); blocks.Add(block); blockLine++; } lineNum++; } while (line != null); reader.Close(); return new Board(boardSize.Width, boardSize.Height, blocks, boardEndPoint); }
private void _addBlock(Block block) { var b = new Block(this, block.Orientation, block.Size, block.Postition, block.Type); BlockList.Add(b); if (b.Type == 1) _blockOne = b; }