private void InitializeBlocks() { int blockCount = 1; PuzzleBlock block; for (int row = 1; row < 5; row++) { for (int col = 1; col < 5; col++) { block = new PuzzleBlock() { Top = row * 84, Left = col * 84, Text = blockCount.ToString(), Name = "Block" + blockCount.ToString() }; block.Click += Block_Click; initialLocations.Add(block.Location); if (blockCount == 16) { block.Name = "EmptyBlock"; block.Text = string.Empty; block.BackColor = Color.Yellow; block.FlatStyle = FlatStyle.Flat; block.FlatAppearance.BorderSize = 0; } blockCount++; this.Controls.Add(block); } } }
private void AddButtons() { int blockCount = 1; PuzzleBlock block; for (int row = 1; row < 5; row++) { for (int col = 1; col < 5; col++) { block = new PuzzleBlock(); block.Top = row * 85; block.Left = col * 85; block.Text = blockCount.ToString(); block.Name = "Block" + blockCount.ToString(); //block.Click += new EventHandler(Block_Click); block.Click += Block_Click; initializeLocations.Add(block.Location); if (blockCount == 16) { block.Name = "EmptyBlock"; block.Text = string.Empty; block.BackColor = Color.Lime; block.FlatStyle = FlatStyle.Flat; block.FlatAppearance.BorderSize = 0; } blockCount++; this.Controls.Add(block); } } }
private void InitializeBlocks() { int blockCount = 1; for (int row = 1; row < 5; row++) { for (int col = 1; col < 5; col++) { block = new PuzzleBlock(); block.Text = blockCount.ToString(); block.Name = "block" + blockCount.ToString(); block.FlatStyle = FlatStyle.Flat; block.FlatAppearance.BorderSize = 0; block.Top = betweenBlocks + (block.Width + betweenBlocks) * (row - 1); block.Left = betweenBlocks + (block.Width + betweenBlocks) * (col - 1); block.Click += new EventHandler(Block_Click); if (blockCount == 16) { block.Name = "EmptyBlock"; block.Text = ""; block.BackColor = Color.LightGoldenrodYellow; } blockCount++; this.Controls.Add(block); } } }
private void InitializeBLocks() { int blockCount = 1; PuzzleBlock block; for (int row = 1; row < 5; row++) { for (int col = 1; col < 5; col++) { block = new PuzzleBlock(); block.Top = row * 155; block.Left = col * 155; block.Text = blockCount.ToString(); Name = "Block" + blockCount.ToString(); //block.Click += new EventHandler(Block_Click); block.Click += Block_Click; if (blockCount == 16) { block.Name = "EmptyBlock"; block.Text = ""; block.BackColor = Color.AntiqueWhite; } blockCount++; this.Controls.Add(block); } } }
private void PuzzleArea_ResizeEnd(object sender, EventArgs e) { int collum = 0; int row = 0; int count = 0; int NW = this.Width - 16; int NH = this.Height - 39; PuzzleBlock block3; PuzzleBlock block2 = new PuzzleBlock(0, 0, 0, 0, 0, 0, null, false); foreach (var button in buttons) { this.Width = OW; this.Height = OH; count++; int BT = button.Top - ((OH - 39) - ((button.Width * rowcount) + (0 * (rowcount - 1)))) / 2; int BL = button.Left - ((OW - 16) - ((button.Width * collumcount) + (0 * (collumcount - 1)))) / 2; collum = BL / button.Width; row = BT / button.Width; block3 = new PuzzleBlock(collum, row, NW, collumcount, rowcount, NH, button, false); if (count == (rowcount * collumcount)) { button.Text = null; button.Name = "ZeroBlock"; button.FlatStyle = FlatStyle.Flat; button.BackColor = Color.Black; count = 0; } } this.Width = NW + 16; this.Height = NH + 39; }
private void InitializeBlocks(int Width, int Height) { //W difference +16 //H difference +39 PuzzleBlock block; int count = 0; rowcount = 4; collumcount = 4; for (int row = 0; row < rowcount; row++) { for (int collum = 0; collum < collumcount; collum++) { count++; block = new PuzzleBlock(collum, row, Width, collumcount, rowcount, Height, null, false); block.Click += (Block_Click); block.Text = count.ToString(); if (count == rowcount * collumcount) { block.Text = null; block.Name = "ZeroBlock"; block.FlatStyle = FlatStyle.Flat; block.BackColor = Color.Black; } buttons.Add(block); this.Controls.Add(block); } } }
private void SwapBlocks(Button block) { PuzzleBlock p = new PuzzleBlock(0, 0, 0, 0, 0, 0, null, true); Button Empty = (Button)this.Controls["ZeroBlock"]; Point oldblocklocation = block.Location; if (Math.Sqrt(Math.Pow(block.Left - Empty.Left, 2) + Math.Pow(block.Top - Empty.Top, 2)) == block.Width + p.space) { block.Location = Empty.Location; Empty.Location = oldblocklocation; } }
private void ShuffleBlocks() { int randNumber; string blockName; Button block; for (int i = 0; i < 100; i++) { randNumber = rand.Next(1, 16); blockName = "block" + randNumber.ToString(); block = (Button)this.Controls[blockName]; SwapBlocks(block); } }
private void InitializeBlocks() { int blockCount = 1; PuzzleBlock block; for (int row = 0; row < 5; row++) { for (int col = 0; col < 5; col++) { block = new PuzzleBlock(); block.Top = row * 84; block.Left = col * 84; block.Text = blockCount.ToString(); blockCount++; this.Controls.Add(block); } } }
private void InitializeBlocks() { int blockCount = 1; PuzzleBlock block; for (int row = 1; row < 5; row++) { for (int col = 1; col < 5; col++) { block = new PuzzleBlock(); block.Top = row * 84; block.Left = col * 84; block.Text = blockCount.ToString(); if (blockCount == 16) { block.Text = string.Empty; block.BackColor = Color.Gray; } blockCount++; this.Controls.Add(block); } } }