import sys, os, pygame from pygame.locals import * def open_file(file_name, mode): """Open a file.""" try: the_file = open(file_name, mode) except(IOError), e:#fail safe print "Cannot to open the file", file_name, "Ending program.\n", e raw_input("\n\nPress the enter key to exit.") sys.exit() else: return the_file def next_line(the_file): line = the_file.readline() line = line.replace("/", "\n") return line def next_block(the_file): score = [] for i in range(10): score.append(next_line(the_file)) return score def main(): high_file = open_file("high_score.txt", "r") score = next_block(high_file) global score high_file.close() main() pygame.init() def main(): pygame.display.init() background = pygame.image.load("greenberet.png") backgroundRect = background.get_rect() Font = pygame.font.Font(os.path.join("data", "FreeMono.ttf"), 18) #pygame.mixer.music.load("GreenBeret.ogg") #pygame.mixer.music.play(-1) size = (width, height) = background.get_size() screen = pygame.display.set_mode(size) pygame.display.set_caption('War on Durkadurkastan: High Scores') pygame.mouse.set_visible(1) screen.blit(background, backgroundRect) pygame.display.flip() stop = False ren = Font.render("High Scores: %06d" % score, 0, (98, 123, 76)) Surface.blit(ren, ( 150 - ren.get_width()/2, 10 - ren.get_height()/2)) pygame.display.flip() while not stop: key = pygame.key.get_pressed() for e in pygame.event.get(): if e.type == QUIT or key[K_ESCAPE]: pygame.quit() sys.exit() if e.type == KEYDOWN and e.key == K_SPACE: stop = True if __name__ == "__main__": main()