Commit 32555455 by BellCodeEditor

save project

parent 126cfcb6
Showing with 1730 additions and 26 deletions
#!/usr/bin/env python
import pygame,sys,time,random import pygame,sys,time,random
from pygame.locals import * from pygame.locals import *
# 定义颜色变量 # 定义颜色变量
...@@ -70,7 +70,7 @@ def main(): ...@@ -70,7 +70,7 @@ def main():
if direction == 'up': if direction == 'up':
snakePosition[1] -= 20 snakePosition[1] -= 20
if direction == 'down': if direction == 'down':
snakePosition[1] += 20 snakePosition[1] += 20
# 增加蛇的长度 # 增加蛇的长度
snakeSegments.insert(0,list(snakePosition)) snakeSegments.insert(0,list(snakePosition))
# 判断是否吃掉了树莓 # 判断是否吃掉了树莓
...@@ -100,7 +100,7 @@ def main(): ...@@ -100,7 +100,7 @@ def main():
if snakePosition[0] == snakeBody[0] and snakePosition[1] == snakeBody[1]: if snakePosition[0] == snakeBody[0] and snakePosition[1] == snakeBody[1]:
gameOver(playSurface) gameOver(playSurface)
# 控制游戏速度 # 控制游戏速度
fpsClock.tick(10) fpsClock.tick(7)
if __name__ == "__main__": if __name__ == "__main__":
main() main()
\ No newline at end of file
import random import random
a=random(0.4) int a
a=random(0,4)
print(a) print(a)
\ No newline at end of file
import pygame import pygame
from pygame import locals
# 初始化pygame,为使用pygame做准备
pygame.init() pygame.init()
screen=pygame.display.set_mode((660,480))
background=pygame.image.load('bg.png') # 创建一个窗口
right=pygame.image.load('right.png')
food=pygame.image.load('apple.png')
body=pygame.image.load('body.png')
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
exit()
screen.bilt(background,(0,0))
screen.bilt(right,(240,120))
screen.bilt(body,(210,120))
screen.bilt(body,(180,120))
screen.bilt(body,(180,90))
screen.bilt(food,(360,300))
pygame.display.update()
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment