Exemple #1
0
        public SnakeForm()
        {
            InitializeComponent();

            this.Font = new Font(Program.myFonts.Families[0], 9);

            KeyPreview = true;

            eatRobotLabel.Visible = true;

            food = new Food(randFood, false);

            unFood = new List<Food>();

            passedScore = new List<int>();

            down = false;
            up = false;
            right = false;
            left = false;
        }
Exemple #2
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (score % 50 == 0 && score != 0)
            {
                bool isPassed = false;

                foreach(int s in passedScore)
                {
                    if (s == score)
                    {
                        isPassed = true;
                        break;
                    }
                }

                if (isPassed == false)
                {
                    passedScore.Add(score);
                    timer1.Interval = timer1.Interval * 9 / 10;
                    levelLabel.Text = (score / 50).ToString();

                    Food f = new Food(randFood, true);
                    unFood.Add(f);
                }
            }

            keydEnabled = true;

            if (down) { snake.moveDown(); }
            else if (up) { snake.moveUp(); }
            else if (right) { snake.moveRight(); }
            else if (left) { snake.moveLeft(); }

            for (int i = 0; i < snake.SnakeRec.Length; i++)
            {
                if (snake.SnakeRec[i].IntersectsWith(food.foodRec))
                {
                    snakeHeadPos = snake.SnakeRec[i].Location;
                    snake.growSnake();
                    score += 10;
                    scoreLabel.Text = score.ToString();
                    food.foodLocation(randFood, unFood);
                }
            }

            collision();

            this.Invalidate();
        }
Exemple #3
0
        private void restart()
        {
            isStart = true;
            statLabel.Visible = false;

            timer1.Start();

            snake = new Snake();
            food = new Food(randFood, false);
            unFood = new List<Food>();
            snake = new Snake();
            passedScore = new List<int>();

            score = 0;
            scoreLabel.Text = "0";
            levelLabel.Text = "0";
            timer1.Interval = 200;

            down = false;
            up = false;
            right = false;
            left = false;
        }