private void MatchingClick(object sender, EventArgs e) { MatchingLabel clicked = sender as MatchingLabel; if (clicked != null) { if (clicked.ForeColor != Color.Black) { if (curr1st == null) { curr1st = clicked; curr1st.ForeColor = Color.Black; } else if (curr2nd == null) { curr2nd = clicked; curr2nd.ForeColor = Color.Black; if ((int)calculator.Compute(curr1st.Text, null) == (int)calculator.Compute(curr2nd.Text, null)) { curr1st = curr2nd = null; CheckForWinner(); return; } timer1.Start(); } } } }
private void TimerTick(object sender, EventArgs e) { timer1.Stop(); curr1st.ForeColor = curr1st.BackColor; curr2nd.ForeColor = curr2nd.BackColor; curr1st = curr2nd = null; }
private void CheckForWinner() { foreach (Control ctrl in tableLayoutPanel1.Controls) { MatchingLabel labelCurrentlyChecking = ctrl as MatchingLabel; if (labelCurrentlyChecking != null && labelCurrentlyChecking.ForeColor == labelCurrentlyChecking.BackColor) { return; } } MessageBox.Show("You matched it all!", "You can add!"); Close(); }
private void AssignNumbersToSquares() { int amtIters = matchingItems.Count; for (int i = 0; i < amtIters; i++) { int randomNumber = random.Next(matchingItems.Count); MatchingLabel labelCurrentlyCreating = new MatchingLabel { Text = matchingItems[randomNumber], ForeColor = tableLayoutPanel1.BackColor }; labelCurrentlyCreating.Click += MatchingClick; tableLayoutPanel1.Controls.Add(labelCurrentlyCreating); matchingItems.RemoveAt(randomNumber); } }