Beispiel #1
0
        //fruit
        private void DrawFruit()
        {
            if (!fruit)
            {
f:
                for (int i = 0; i < 13; i++)
                {
                    for (int j = 0; j < 13; j++)
                    {
                        Rectangle point = new Rectangle(i * 20, j * 20, 20, 20);
                        if (snake.IndexOf(point) == -1)
                        {
                            empty_filed.Add(point);
                        }
                    }
                }
                food = empty_filed[rand.Next(0, empty_filed.Count - 1)];
                for (int i = 0; i < snake.Count; i++)
                {
                    if (snake[i] == food)
                    {
                        goto f;
                    }
                }
                empty_filed.Clear();
                Graphics g = Fuild.CreateGraphics();
                g.FillEllipse(Brushes.Red, food);
                fruit = true;
            }
            else
            {
                Graphics g = Fuild.CreateGraphics();
                g.FillEllipse(Brushes.Red, food);
            }
        }
Beispiel #2
0
        //snake
        private void DrawSnake()
        {
            Graphics graphics = Fuild.CreateGraphics();

            for (int i = 0; i < snake.Count; i++)
            {
                if (i == 0)
                {
                    graphics.FillEllipse(Brushes.Black, snake[i]);
                }
                else
                {
                    graphics.FillEllipse(Brushes.Green, snake[i]);
                }
            }
        }