Commit 7d859852 by BellCodeEditor

save project

parent 4340fa23
# 默认忽略的文件
/shelf/
/workspace.xml
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.13 (pythonProject)" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/pygame_lesson3_diy3.iml" filepath="$PROJECT_DIR$/.idea/pygame_lesson3_diy3.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="jdk" jdkName="Python 3.13 (pythonProject)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>
\ No newline at end of file
import pygame
import random
from pygame import locals
# 初始化pygame,为使用硬件做准备
......@@ -19,6 +20,8 @@ down = pygame.image.load('down.png') # 头 朝下
x, y = 240, 120
position = [(180, 90), (180, 120), (210, 120), (x, y)]
apple_x = 360 #苹果横坐标
apple_y = 300 #苹果纵坐标
setheading = "right"
snake_head = right
......@@ -52,7 +55,14 @@ while True:
else:
y += 30
position.append((x, y))
position.pop(0)
#贪吃蛇吃到了苹果
if x == apple_x and y == apple_y:
num1 = random.randint(1, 22) #横排的几个格子
num2 = random.randint(1, 16) #纵排的几个格子
apple_x = 30*num1-30 #苹果的X坐标
apple_y = 30*num2-30 #苹果的Y坐标
else:
position.pop(0)
# 将背景图画上去
screen.blit(background, (0, 0))
# 将贪吃蛇的头画上去
......@@ -62,7 +72,8 @@ while True:
screen.blit(body, position[i])
# 将果实画上去
screen.blit(food, (360, 300))
screen.blit(food, (apple_x,apple_y))
# 刷新画面
pygame.display.update()
FPSCLOCK.tick(3)
\ No newline at end of file
FPSCLOCK.tick(3)
\ 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