2013-05-27 2 views
0

나는 pygame, easygui 및 shelve로 파이썬에서 간단한 레이싱 게임을 만들었습니다. 게임을 끝내면 유휴 상태와 .desktop 파일에서 모두 훌륭하게 작동했습니다. 그 후 나는 최고 점수 시스템을 추가하기로 결정했습니다. 시스템은 유휴 상태에서 훌륭하게 작동하지만 .desktop 파일에서 "치명적인 파이썬 오류 : (파이 게임 낙하산) 분할 오류"라는 오류가 발생합니다. 나는 정말 그렇게 도움이 될 것이다 게임에서 최고 점수 시스템을 떠나고 싶습니다 appreciated.`Shelve가 파이 게임의 치명적인 오류를 유발합니까?

if hero.colliderect(finishline): 
    starttimer=0 
    running=0 
    d=shelve.open('highscores.txt') 
    highscore=d['highscore'] 
    if time<highscore: 
     d=shelve.open('highscores.txt') 
     d['highscore']=time 
     player=easygui.enterbox(msg=("Congratulations you have set the new highscore of "+str(time)+ " please enter your name")) 
     d['player']=player 
     d.close 
    if time>highscore: 
     d=shelve.open('highscores.txt') 
     player=d['player'] 
     highscore=d['highscore'] 
     d.close 
     easygui.msgbox(msg=("Congratulations you have finished with a time of "+str(time)+" The highscore is "+str(highscore)+ "set by "+player)) 

`

답변

1

난 당신의 코드에서 작은 오류의 몇 가지를 볼 수 있지만 나는이가 어떠했는지 확실하지 않다 segfault의 원인은 다음과 같습니다.

from contextlib import closing 

if hero.colliderect(finishline): 
    starttimer = running = 0 
    with closing(shelve.open('highscores.txt')) as d: 
     highscore = d['highscore'] 
     if time < highscore: 
      d['highscore'] = time 
      player = easygui.enterbox(msg=("Congratulations you have set a new highscore of {0}. Please enter your name: ".format(time))) 
      d['player'] = player 
     else: 
      player = d['player'] 
      easygui.msgbox(msg=("Congratulations you have finished with a time of {0}. The highscore is {1} set by {2}".format(time, highscore, player))) 
+0

내 게임에서이 기능을 사용 해 주셔서 감사합니다. –

관련 문제