示例#1
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            toolStripStatusLabelScore.Text = score.ToString();

            if (down == true)
            {
                snake.moveDown();
            }

            if (up == true)
            {
                snake.moveUp();
            }

            if (right == true)
            {
                snake.moveRight();
            }

            if (left == true)
            {
                snake.moveLeft();
            }

            //kiểm tra thực phẩm sau khi trạm vào sinh ra thực phẩm có tọa độ mới
            for (int i = 0; i < snake.SnakeRec.Length; i++)
            {
                if (snake.SnakeRec[i].IntersectsWith(food.foodRec))
                {
                    score += 5;
                    snake.growSnake();// mỗi lần va trạm food thì tăng độ dài rắn lên
                    food.foodLocation(randFood);
                }
            }
            collision();
            this.Invalidate();//thao tác này để cập nhật lại
        }