Skip to content
  • P
    Projects
  • G
    Groups
  • S
    Snippets
  • Help

Administrator / pygame_lesson9_diy3

  • This project
    • Loading...
  • Sign in
Go to a project
  • Project
  • Repository
  • Issues 0
  • Merge Requests 0
  • Pipelines
  • Wiki
  • Snippets
  • Members
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Files
  • Commits
  • Branches
  • Tags
  • Contributors
  • Graph
  • Compare
  • Charts
Commit 72e57a37 authored 3 years ago by BellCodeEditor's avatar BellCodeEditor
Browse files
Options
  • Browse Files
  • Download
  • Email Patches
  • Plain Diff

save project

parent 26ccace0
Hide whitespace changes
Inline Side-by-side
Showing with 10 additions and 10 deletions
  • my_game.py
  • record.txt
my_game.py
View file @ 72e57a37
...@@ -127,19 +127,19 @@ while True: ...@@ -127,19 +127,19 @@ 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#变为False gamestate = False#变为False
if score > thr: if score > thr:#如果分数大于第三名的分数
if score >one: if score >one:#如果比第一名大
record['第1名'] = score record['第1名'] = score#第一名的分数变为现在第一名的分数
record['第2名'] = one record['第2名'] = one#第二名变为之前第一名的分数
record['第3名'] = two record['第3名'] = two#同理
elif score > two: elif score > two:#如果比第一名大
record['第2名'] = score record['第2名'] = score
record['第3名'] = thr record['第3名'] = thr
else: else:
record['第3名'] = score record['第3名'] = score
record = json.dumps(record,ensure_ascii=False) nrecord = json.dumps(record,ensure_ascii=False)#把python字典转换为json字符串
with open('record.txt','w',encoding='utf-8') as f: with open('record.txt','w',encoding='utf-8') as f:
f.write(record) f.write(nrecord)#输入最新文件(重置排名)
else: else:
if prop.rect.x + prop.rect.width <wukong.rect.x: if prop.rect.x + prop.rect.width <wukong.rect.x:
score += prop.score score += prop.score
......
This diff is collapsed. Click to expand it.
record.txt
View file @ 72e57a37
{"第1名": 1, "第2名": 0, "第3名": 0} {"第1名": 2, "第2名": 1, "第3名": 0}
\ No newline at end of file \ No newline at end of file
This diff is collapsed. Click to expand it.
  • Write
  • Preview
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