Skip to content

Commit

Permalink
Merge pull request #5 from LakshmiNarayanP/HighScoreFeature
Browse files Browse the repository at this point in the history
Added high score feature by @LakshmiNarayanP
  • Loading branch information
dhhruv authored Oct 27, 2021
2 parents 87230c1 + 0de1b63 commit 36dda8a
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions chromedino.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,17 @@ def menu(death_count):
scoreRect = score.get_rect()
scoreRect.center = (SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2 + 50)
SCREEN.blit(score, scoreRect)
f = open("score.txt","a")
f.write(str(points)+"\n")
f.close()
with open("score.txt", "r") as f:
score = f.read() # Read all file in case values are not on a single line
score_ints = [ int(x) for x in score.split() ] # Convert strings to ints
highscore = max(score_ints) # sum all elements of the list
hs_score_text = font.render("High Score : " + str(highscore), True, (0,0,0))
hs_score_rect = hs_score_text.get_rect()
hs_score_rect.center = (SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2 + 100)
SCREEN.blit(hs_score_text, hs_score_rect)
textRect = text.get_rect()
textRect.center = (SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2)
SCREEN.blit(text, textRect)
Expand Down

0 comments on commit 36dda8a

Please sign in to comment.