private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e) { var backgroundWorker = (BackgroundWorker)sender; while (!e.Cancel) { if (backgroundWorker.CancellationPending) { e.Cancel = true; return; } else { this.Dispatcher.Invoke(() => { AliveDead.ButtonValues(); livesText.Text = "Alive: " + Convert.ToString(AliveDead.Next()); // could add an if statement to check if all boxes are false // if true, call StopLoop(); }); Thread.Sleep(speed); } } }
private void button_Click(object sender, RoutedEventArgs e) { var button = (Button)sender; if (((SolidColorBrush)button.Background).Color == Colors.White) { //ButtonList.buttons[0].Background = Brushes.ForestGreen; button.Background = Brushes.ForestGreen; if (shape.Count != 0) { int counter = 0; // since Dictionaries don't have traditional indecies i need to iterate through them to get the correct index. foreach (KeyValuePair <Point, bool> keyValuePair in AliveDead.squares) { if (counter == ButtonList.buttons.IndexOf(button)) { // this needs to be replaced with a list of points List <Point> allToClick = new List <Point>(); foreach (Point point in shape) { allToClick.Add(new Point(keyValuePair.Key.x + point.x, keyValuePair.Key.y + point.y)); } foreach (Point buttonPoint in allToClick) { if (AliveDead.squares.ContainsKey(buttonPoint)) { int counter2 = 0; foreach (KeyValuePair <Point, bool> keyValuePair1 in AliveDead.squares) { if (keyValuePair1.Key.x == buttonPoint.x && keyValuePair1.Key.y == buttonPoint.y && counter2 < ButtonList.buttons.Count) { if (ButtonList.buttons[counter2].Background != Brushes.ForestGreen) { ButtonList.buttons[counter2].Background = Brushes.ForestGreen; //AliveDead.alive += 1; } } counter2 += 1; } } } break; } counter += 1; } } } else if (((SolidColorBrush)button.Background).Color == Colors.ForestGreen) { AliveDead.alive -= 1; button.Background = Brushes.White; if (shape.Count != 0) { int counter = 0; // since Dictionaries don't have traditional indecies i need to iterate through them to get the correct index. foreach (KeyValuePair <Point, bool> keyValuePair in AliveDead.squares) { if (counter == ButtonList.buttons.IndexOf(button)) { // this needs to be replaced with a list of points List <Point> allToClick = new List <Point>(); foreach (Point point in shape) { allToClick.Add(new Point(keyValuePair.Key.x + point.x, keyValuePair.Key.y + point.y)); } foreach (Point buttonPoint in allToClick) { if (AliveDead.squares.ContainsKey(buttonPoint)) { int counter2 = 0; foreach (KeyValuePair <Point, bool> keyValuePair1 in AliveDead.squares) { if (keyValuePair1.Key.x == buttonPoint.x && keyValuePair1.Key.y == buttonPoint.y && counter2 < ButtonList.buttons.Count) { if (ButtonList.buttons[counter2].Background != Brushes.White) { ButtonList.buttons[counter2].Background = Brushes.White; //AliveDead.alive += 1; } } counter2 += 1; } } } break; } counter += 1; } } } nextButton.Focus(); AliveDead.ButtonValues(); int countingAlive = 0; foreach (KeyValuePair <Point, bool> checking in AliveDead.squares) { if (checking.Value == true) { countingAlive += 1; } } livesText.Text = "Alive: " + countingAlive; //MessageBox.Show(AliveDead.squares[ButtonList.buttons.IndexOf(button)].ToString()); //MessageBox.Show(ButtonList.buttons.IndexOf(button).ToString()); }
private void NextButton_Click(object sender, RoutedEventArgs e) { AliveDead.ButtonValues(); livesText.Text = "Alive: " + Convert.ToString(AliveDead.Next()); }