예제 #1
0
        public void life(flappyBaseClass bottomPipe, flappyBaseClass topPipe)
        {
            try
            {
                Rect bottom     = new Rect(bottomPipe.GetLeft, bottomPipe.GetTop, bottomPipe.ActualWidth, bottomPipe.ActualHeight);
                Rect top        = new Rect(topPipe.GetLeft, topPipe.GetTop, topPipe.ActualWidth, topPipe.ActualHeight);
                Rect flappybird = new Rect(flappy.GetLeft, flappy.GetTop, flappy.ActualWidth - 10, flappy.ActualHeight - 10);

                Rect addScore = new Rect(bottomPipe.GetLeft, topPipe.GetTop, 50, 600);

                if (addScore.IntersectsWith(flappybird))
                {
                    if (!score.HasContent)
                    {
                        score.Content = '1';
                    }
                    else
                    {
                        if (flappy.isAlive())
                        {
                            score.Content = int.Parse(score.Content.ToString()) + 1;
                        }
                    }
                }

                if (bottom.IntersectsWith(flappybird) || top.IntersectsWith(flappybird) || !flappy.isAlive())
                {
                    topPipe.Shutdown();
                    bottomPipe.Shutdown();

                    flappy.isAlive(false);
                    flappy.Shutdown();
                    this.lifeThread.Abort();
                    close.Visibility = System.Windows.Visibility.Visible;
                }
            }
            catch (Exception e)
            {
                //throw e;
            }
        }
예제 #2
0
        private void start_Click(object sender, RoutedEventArgs e)
        {
            start.Visibility      = System.Windows.Visibility.Hidden;
            rectangle.Visibility  = System.Windows.Visibility.Hidden;
            flappyText.Visibility = System.Windows.Visibility.Hidden;
            birdText.Visibility   = System.Windows.Visibility.Hidden;

            flappy        = new bird(gameArea, Dispatcher, 3);
            flappy.Paused = false;
            flappy.Place(50, 300);

            pipeThread = new Thread(delegate()
            {
                while (true)
                {
                    this.Dispatcher.Invoke(
                        DispatcherPriority.SystemIdle,
                        new Action(() => addPipes()));
                    Thread.Sleep(2300);
                }
            });
            pipeThread.Start();
        }