Commit f8b5edff by BellCodeEditor

auto save

parent f2e5d3a0
Showing with 56 additions and 26 deletions
File added
import turtle
pen=turtle.Pen()
pen.pencolor('black')
for y in range(10):
for i in range(5):
pen.right(72)
pen.forward(100)
pen.right(36)
turtle.done()
num1=int(input('请输入一个整数'))
if num1>=90:
g='A'
elif 60<=num1<=89:
g='B'
else
\ No newline at end of file
sum1=0
for i in range(1,100+1):
sum1+=1
print(sum1)
import pygame
import pygame,random
from pygame import locals
pygame.init()
screen = pygame.display.set_mode((660, 480))
......@@ -10,7 +10,12 @@ body = pygame.image.load('body.png')
down=pygame.image.load('down.png')
up=pygame.image.load('up.png')
left=pygame.image.load('left.png')
my_font=pygame.font.Font('COURI.TTF',28)
score=0
x,y=240,120
apple_x=360
apple_y=300
position=[(90,120),(180,120),(210,120),(x,y)]
setheading='right'
snake_head = right
while True:
......@@ -24,17 +29,37 @@ while True:
if event.key == locals.K_LEFT and setheading!='right':
setheading='left'
snake_head=left
if event.key == locals.K_RIGHT and setheading!='down':
if event.key == locals.K_UP and setheading!='down':
setheading='up'
snake_head=right
if event.key == locals.K_LEFT and setheading!='up':
snake_head=up
if event.key == locals.K_DOWN and setheading!='up':
setheading='down'
snake_head=left
snake_head=down
if setheading=='right':
x+=30
elif setheading=='left':
x-=30
elif setheading=='down':
y+=30
else:
y-=30
position.append((x,y))
if x == apple_x and y == apple_y:
score=score+10
num1=random.randint(1,22)
num2=random.randint(1,16)
apple_x=num1*30-30
apple_y=num2*30-30
else:
position.pop(0)
screen.blit(background, (0, 0))
screen.blit(right, (240, 120))
screen.blit(body, (210, 120))
screen.blit(body, (180, 120))
screen.blit(body, (180, 90))
screen.blit(food, (360, 300))
screen.blit(snake_head,position[-1])
for i in range(len(position)-1):
screen.blit(body,position[i])
#screen.blit(body, (180, 90))
screen.blit(food, (apple_x, apple_y))
info='score'+str(score)
text=my_font.render(info,True,(0,0,0))
screen.blit(text,(540,10))
pygame.display.update()
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