Commit ef73089f by BellCodeEditor

save project

parent b150d866
Showing with 35 additions and 2 deletions
...@@ -56,6 +56,7 @@ time = 0 ...@@ -56,6 +56,7 @@ time = 0
score = 0 score = 0
gamestate = True gamestate = True
speed = 8 speed = 8
chaoguo = 4
score_audio = pygame.mixer.Sound('score.wav') score_audio = pygame.mixer.Sound('score.wav')
font = pygame.font.Font("STKAITI.TTF",20) font = pygame.font.Font("STKAITI.TTF",20)
...@@ -68,6 +69,15 @@ while True: ...@@ -68,6 +69,15 @@ while True:
# 接收到退出事件后退出程序 # 接收到退出事件后退出程序
exit() exit()
if event.type == locals.KEYDOWN: if event.type == locals.KEYDOWN:
if gamestate == False:
for sprite in block_list:
sprite.kill()
score = 0
wukong.rect.x = 150
wukong.rect.y = 400
speed = 8
gamestate = True
chaoguo = 4
if jumpState == "runing": if jumpState == "runing":
if event.key == locals.K_SPACE: if event.key == locals.K_SPACE:
jumpState = "up" jumpState = "up"
...@@ -126,11 +136,34 @@ while True: ...@@ -126,11 +136,34 @@ while True:
gameover = pygame.image.load('gameover.png') # 游戏结束 gameover = pygame.image.load('gameover.png') # 游戏结束
screen.blit(gameover, (400, 200)) screen.blit(gameover, (400, 200))
gamestate = False gamestate = False
if sprite.rect.x + sprite.rect.width < wukong.rect.x and sprite.score == 1: if sprite.rect.x + sprite.rect.width < wukong.rect.x and sprite.score == 1:
sprite.score = 0 sprite.score = 0
score += 1 score += 1
score_audio.play() score_audio.play()
if score > dictdata['第1名']:
dictdata['第1名'] = score
chaoguo = 1
if chaoguo == 2:
dictdata['第3名'] = dictdata['第2名']
dictdata['第2名'] = dictdata['第1名']
elif score > dictdata['第2名']:
dictdata['第2名'] = score
chaoguo = 2
if chaoguo == 3:
dictdata['第3名'] = dictdata['第2名']
elif score > dictdata['第3名'] and chaoguo == 4:
dictdata['第2名'] = score
chaoguo = 3
jsondata = json.dumps(dictdata,ensure_ascii=False)
with open('record.txt','w',encoding = 'utf-8') as f:
f.write(jsondata)
text1 = '分数:' + str(score) text1 = '分数:' + str(score)
info1 = font.render(text1,True,(255,255,255)) info1 = font.render(text1,True,(255,255,255))
screen.blit(info1,(850,10)) screen.blit(info1,(850,10))
......
{"第1名": 100, "第2名": 50, "第3名": 15} {"第1名": 100, "第2名": 4, "第3名": 3}
\ No newline at end of file \ 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