示例#1
0
        private void clear_Click(object sender, RoutedEventArgs e)
        {
            if (slider.Value >= 1)
            {
                string sValue = Convert.ToString(slider.Value);
                sizeText.Text = sValue + " x " + sValue;

                int width  = Convert.ToInt32(slider.Value);
                int height = Convert.ToInt32(slider.Value);

                foreach (Button button in ButtonList.buttons)
                {
                    playArea.Children.Remove(button);
                }
                foreach (ColumnDefinition column in ButtonList.columns)
                {
                    playArea.ColumnDefinitions.Remove(column);
                }
                foreach (RowDefinition row in ButtonList.rows)
                {
                    playArea.RowDefinitions.Remove(row);
                }

                AliveDead.CreateDictionary(width, height);
                CreateButtonsAndGrid(width, height);

                livesText.Text = "Alive: 0";
            }
        }
示例#2
0
        private void slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs <double> e)
        {
            if (slider.Value >= 1)
            {
                string sValue = Convert.ToString(slider.Value);
                sizeText.Text = sValue + " x " + sValue;

                int width  = Convert.ToInt32(slider.Value);
                int height = Convert.ToInt32(slider.Value);

                foreach (Button button in ButtonList.buttons)
                {
                    playArea.Children.Remove(button);
                }
                foreach (ColumnDefinition column in ButtonList.columns)
                {
                    playArea.ColumnDefinitions.Remove(column);
                }
                foreach (RowDefinition row in ButtonList.rows)
                {
                    playArea.RowDefinitions.Remove(row);
                }

                AliveDead.CreateDictionary(width, height);
                CreateButtonsAndGrid(width, height);
                //AliveDead.ApplyStatus();
            }
        }
示例#3
0
        public MainWindow()
        {
            InitializeComponent();
            // this is where i would take the input

            AliveDead.CreateDictionary(5, 5);

            _backgroundWorker = new BackgroundWorker
            {
                WorkerSupportsCancellation = true
            };
            _backgroundWorker.DoWork             += backgroundWorker_DoWork;
            _backgroundWorker.RunWorkerCompleted += backgroundWorker_RunWorkerCompleted;


            nextButton.Focus();
            CreateButtonsAndGrid(5, 5);
            underPop.Text = "<" + Convert.ToString(AliveDead.underPopulated);
            overPop.Text  = ">" + Convert.ToString(AliveDead.overPopulated);
            growthS.Text  = ">=" + Convert.ToString(AliveDead.growthStart);
            growthE.Text  = "<=" + Convert.ToString(AliveDead.growthEnd);

            slider.Value = 50;
        }
示例#4
0
        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);
                }
            }
        }
示例#5
0
        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());
        }
示例#6
0
 private void NextButton_Click(object sender, RoutedEventArgs e)
 {
     AliveDead.ButtonValues();
     livesText.Text = "Alive: " + Convert.ToString(AliveDead.Next());
 }