def main():\n pygame.init()\n screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))\n pygame.display.set_caption('贪吃蛇')\n\n light = (100, 100, 100) # 蛇的颜色\n dark = (200, 200, 200) # 食物颜色\n\n font1 = pygame.font.SysFont('SimHei', 24) # 得分的字体\n font2 = pygame.font.Font(None, 72) # GAME OVER 的字体\n red = (200, 30, 30) # GAME OVER 的字体颜色\n fwidth, fheight = font2.size('GAME OVER')\n line_width = 1 # 网格线宽度\n black = (0, 0, 0) # 网格线颜色\n bgcolor = (40, 40, 60) # 背景色\n\n # 方向,起始向右\n pos_x = 1\n pos_y = 0\n # 如果蛇正在向右移动,那么快速点击向下向左,由于程序刷新没那么快,向下事件会被向左覆盖掉,导致蛇后退,直接GAME OVER\n # b 变量就是用于防止这种情况的发生\n b = True\n # 范围\n scope_x = (0, SCREEN_WIDTH // SIZE - 1)\n scope_y = (2, SCREEN_HEIGHT // SIZE - 1)\n # 蛇\n snake = deque()\n # 食物\n food_x = 0\n food_y = 0
...全文