Пример #1
0
        void updateCanvas(object sender, EventArgs e)
        {
            if (totalScore >= 5)
            {
                time.Interval = new TimeSpan(0, 0, 0, 0, 90);
            }
            if (totalScore >= 10)
            {
                time.Interval = new TimeSpan(0, 0, 0, 0, 80);
            }
            if (totalScore >= 15)
            {
                time.Interval = new TimeSpan(0, 0, 0, 0, 70);
            }
            if (totalScore >= 20)
            {
                time.Interval = new TimeSpan(0, 0, 0, 0, 60);
            }
            if (totalScore >= 25)
            {
                time.Interval = new TimeSpan(0, 0, 0, 0, 50);
            }
            if (totalScore >= 30)
            {
                time.Interval = new TimeSpan(0, 0, 0, 0, 40);
            }
            if (totalScore >= 35)
            {
                time.Interval = new TimeSpan(0, 0, 0, 0, 30);
            }


            if (dir != 0)
            {
                for (int i = snake.Count - 1; i > 0; i--)
                {
                    snake[i] = snake[i - 1];
                }
            }


            if (dir == goup)
            {
                y -= 10;
            }
            if (dir == godown)
            {
                y += 10;
            }
            if (dir == goleft)
            {
                x -= 10;
            }
            if (dir == goright)
            {
                x += 10;
            }


            if (snake[0].x == food[0].x && snake[0].y == food[0].y)
            {
                snake.Add(new loadTheSnake(food[0].x, food[0].y));
                food[0] = new addFood(rand.Next(0, 37) * 10, rand.Next(0, 35) * 10);
                bomb[0] = new getBomb(rand.Next(0, 37) * 10, rand.Next(0, 35) * 10);
                mycanvas.Children.RemoveAt(0);
                bomb[0].setBombPosition();
                mycanvas.Children.Add(bomb[0].ell);

                addfood();
                totalScore++;

                Score.Text = totalScore.ToString();
            }

            if (snake[0].x == bomb[0].x && snake[0].y == bomb[0].y)
            {
                MessageBox.Show(wrongFood);
                this.Close();
            }


            snake[0] = new loadTheSnake(x, y);

            if (snake[0].x > 370 || snake[0].y > 350 || snake[0].x < 0 || snake[0].y < 0)
            {
                this.Close();
            }


            for (int i = 1; i < snake.Count; i++)
            {
                if (snake[0].x == snake[i].x && snake[0].y == snake[i].y)
                {
                    MessageBox.Show(message);
                    this.Close();
                }
            }


            for (int i = 0; i < mycanvas.Children.Count; i++)
            {
                if (mycanvas.Children[i] is Rectangle || mycanvas.Children[i] is Ellipse)
                {
                    count++;
                }
            }
            mycanvas.Children.RemoveRange(1, count);
            count = 0;
            addBomb();
            addsnake();
        }
Пример #2
0
        void getBombTime(object sender, EventArgs e)
        {
            bomb[0] = new getBomb(rand.Next(0, 37) * 10, rand.Next(0, 35) * 10);

            mycanvas.Children.Add(bomb[0].ell);
        }