private void buttons_Click(object sender, EventArgs e) { aButton b = (aButton)sender; count++; if (count % 2 == 1) { x1 = b.x; y1 = b.y; buttons[x1, y1].Enabled = false; } else { x2 = b.x; y2 = b.y; judge j = new judge(x1 + 1, y1 + 1, x2 + 1, y2 + 1, n + 2, m + 2, judgeKey); if (j.Judge()) { buttons[x1, y1].Visible = false; buttons[x2, y2].Enabled = false; buttons[x2, y2].Visible = false; judgeKey[x1 + 1, y1 + 1] = 0; judgeKey[x2 + 1, y2 + 1] = 0; score += 20; } else { buttons[x1, y1].Enabled = true; count -= 2; score -= 5; } } }
private void setGame() { this.tableLayoutPanel1.Controls.Clear(); this.tableLayoutPanel1.ColumnStyles.Clear(); this.tableLayoutPanel1.RowStyles.Clear(); this.tableLayoutPanel1.ColumnCount = n; for (int i = 0; i < n; i++) { this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 320 / n)); } this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Bottom; this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 32); this.tableLayoutPanel1.Name = "tableLayoutPanel1"; this.tableLayoutPanel1.RowCount = m; for (int i = 0; i < m; i++) { this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 320 / m)); } this.tableLayoutPanel1.Size = new System.Drawing.Size(320, 320); this.tableLayoutPanel1.TabIndex = 1; count = 0; score = 0; this.buttons = new aButton[n, m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { buttons[i, j] = new aButton(i, j); this.buttons[i, j].Dock = System.Windows.Forms.DockStyle.Fill; this.buttons[i, j].Location = new System.Drawing.Point(0, 0); this.buttons[i, j].Margin = new System.Windows.Forms.Padding(0); this.buttons[i, j].Name = "buttons"; this.buttons[i, j].Size = new System.Drawing.Size(320 / n, 320 / m); this.buttons[i, j].TabIndex = 0; this.buttons[i, j].UseVisualStyleBackColor = true; this.buttons[i, j].Click += new System.EventHandler(this.buttons_Click); this.tableLayoutPanel1.Controls.Add(this.buttons[i, j], j, i); } } setKey(); button2.Enabled = true; label3.Text = "shuffles : " + shffles.ToString(); }