看了www.pygame.org,感觉挺好玩的,看看pygame的手册,参考其它贪吃蛇写法,产生如下代码:有注释,有详细代码,有真相!#!/usr/bin/python#-*-coding:utf8-*-#import pygameimport randomimport osmain_dir = os.path.split(os.path.abspath(__file__))[0]print main_dir# 屏幕大小SCREENSIZE = (640,480)SCREENRECT = pygame.Rect(0, 0, SCREENSIZE[0], SCREENSIZE[1])CAPTION = "first Snake"# 帧FPS = 30# 起始蛇长START_SEGMENT = 5#起始地点START_POS = (20,20)# 移动速率MOVE_RATE = 2MOVE_THRESHOLD = 5#蛇头,食物大小FOODSIZE = (12,12)SNAKE_HEAD_SIZE = (12,12)SNAKE_SEG_SIZE = (12,12)# 障碍物宽度BLOCK_WIDE = 5# food, snanke_segment只能在这范围内产生SCREEN_SEGMENT = ((SCREENSIZE[0]) / SNAKE_SEG_SIZE
...
继续阅读
(17)