Exemple #1
0
        private void Load_Click(object sender, RoutedEventArgs e)
        {
            dispatcherTimer.Stop();

            //maybe you will need here a exception because of the save path.
            // if there is no file to load
            string[] lines = File.ReadAllLines(myPath);
            string[] poslines;

            if (playGround != null)
            {
                // clear the current field and array
                myCanvas.Children.Clear();
                //clear the field before you load a old one
                Array.Clear(playGround.gameBoard, 0, playGround.gameBoard.Length);
            }

            foreach (string line in lines)
            {
                poslines = line.Split('|');

                if (line.Contains("PosX"))
                {
                    if (poslines.Length > 1)
                    {
                        try
                        {
                            int x = Convert.ToInt32(poslines[0].Remove(0, 5));
                            int y = Convert.ToInt32(poslines[1].Remove(0, 6));
                            playGround.CreateNewCreature(y, x);
                        }
                        catch (Exception ex)
                        {
                            // save the exception info into a logfile to check what happens
                            // databse should not allow to change this settings
                        }
                    }
                }
                else
                {
                    try
                    {
                        int pixel = Convert.ToInt32(poslines[0].Remove(0, 10));
                        int field = Convert.ToInt32(poslines[1].Remove(0, 11));

                        pixelSize  = pixel;
                        fieldSize  = field;
                        playGround = new PlayGround(fieldSize);
                    }
                    catch (Exception ex)
                    {
                        // save the exception info into a logfile to check what happens
                        // databse should not allow to change this settings
                        pixelSize = 10;
                        fieldSize = 100;
                    }
                }
            }
            DrawPlayeGround();
        }
Exemple #2
0
 private void NewGameButton_Click(object sender, RoutedEventArgs e)
 {
     if (playGround != null)
     {
         playGround = null;
     }
     myCanvas.Children.Clear();
     StopTimer();
     Inital();
 }
Exemple #3
0
 private void NewGameButton_Click(object sender, RoutedEventArgs e)
 {
     if (playGround != null)
     {
         playGround = null;
     }
     myCanvas.Children.Clear();
     dispatcherTimer.Stop();
     dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
 }
Exemple #4
0
        private void Inital()
        {
            fieldSize = Int32.Parse(FieldSizeTextBox.Text);
            int spawnRate = Int32.Parse(SpawnRateTextBox.Text);

            int coverRate = fieldSize * fieldSize / 100 * spawnRate;

            playGround = new PlayGround(fieldSize, coverRate);
            DrawField(fieldSize);
        }
Exemple #5
0
        private void Inital()
        {
            try
            {
                pixelSize = Int32.Parse(CreatureSize.Text);

                fieldSize = Int32.Parse(FieldSizeTextBox.Text);

                int spawnRate = Int32.Parse(SpawnRateTextBox.Text);

                int coverRate = fieldSize * fieldSize / 100 * spawnRate;

                playGround = new PlayGround(fieldSize, coverRate);
                DrawPlayeGround();
            }
            catch (Exception e)
            {
                MessageBox.Show("Please use Numbers nothing else");
            }
        }