2012-11-08 62 views
-3

我需要一些幫助,我的hang子手遊戲,每當我把一個像「煤氣」這樣的字遊戲工作正常,但是當我鍵入一個像「池」這樣的詞它不起作用。所以如果這個詞有兩個相同的字母,我就贏不了。如果你能幫助我,將不勝感激。Hang子手蟒蛇遊戲不起作用

這是代碼。

劊子手 由Justin 最後修訂日期2012年11月8日 播放劊子手遊戲的用戶(一個或多個) 導入時間 進口OS 進口SYS 進口隨機

gallows1=''' 
    '------' 
    |  | 
    | 
    | 
    | 
    | 
    | 
    | 
    | 
    | 
    | 
==================''' 
gallows2=''' 
    '------' 
    |  | 
    |  O 
    |  | 
    | 
    | 
    | 
    | 
    | 
    | 
    | 
==================''' 
gallows3=''' 
    '------' 
    |  | 
    |  O 
    |  /| 
    | 
    | 
    | 
    | 
    | 
    | 
    | 
==================''' 
gallows4=''' 
    '------' 
    |  | 
    |  O 
    |  /|\\ 
    | 
    | 
    | 
    | 
    | 
    | 
    | 
==================''' 
gallows5=''' 
    '------' 
    |  | 
    |  O 
    |  /|\\ 
    | /
    | 
    | 
    | 
    | 
    | 
    | 
==================''' 
gallows6=''' 
    '------' 
    |  | 
    |  O 
    |  /|\\ 
    | /\\ 
    | 
    | 
    | 
    | 
    | 
    | 
==================''' 
gallowsDead=''' 
    '------' 
    |  | 
    |  | 
    |  | 
    |  O 
    |  ||| 
    |  | | 
    | 
    | 
    | 
    | 
==================''' 
gallowsAlive=''' 
    '------' 
    |  | 
    |  
    |  
    |      _____________________ 
    |      |      | 
    |      | Good Job :D  | 
    |      |      | 
    |      <|_____________________|      
    |     O/ 
    |     /| 
================== /\ ''' 
print""" 
      _ _           
     | | | |           
     | |__| | __ _ _ __ __ _ _ __ ___ __ _ _ __ 
     | __ |/ _` | '_ \/_` | '_ ` _ \/_` | '_ \  
     | | | | (_| | | | | (_| | | | | | | (_| | | | | 
     |_| |_|\__,_|_| |_|\__, |_| |_| |_|\__,_|_| |_| 
           _/|      
          |___/       
""" 
print "        MENU  " 
print "      *=============*" 
print "       1 Player Game" 
print "      *=============*" 
print "       2 Player Game" 
print "      *=============*" 
print "       Options  " 
print "      *=============*" 
print "       Exit   " 
print "      *=============*" 
mode = "" 
while mode != "2" or "1" or "O" or "E": 
    mode=raw_input("Please type in your choice ") 
    break 
os.system("CLS") 
if mode =="2": 
    tries = 0 
    usedLetters="" 
    lettersCorrect=0 
    originalWord=raw_input("A Two player game of Hangman it is, Player A please enter a word! ") 
    os.system("CLS") 
    wordLength=len(originalWord) 
    solvedWord=wordLength*["_ "] 
    maxTries=6 
    while originalWord != solvedWord and maxTries <= 6: 
     if tries == 0: 
      print gallows1 
     if tries == 1: 
      print gallows2 
     if tries == 2: 
      print gallows3 
     if tries == 3: 
      print gallows4 
     if tries == 4: 
      print gallows5 
     if tries == 5: 
      print gallows6 
     print "Player B,Try to guess the word!" 
     print    solvedWord 
     print 
     print"Used Letters:",usedLetters 
     print 
     letter= raw_input("Please Guess a letter! ") 
     if len(letter)== 1: 
      if usedLetters.find(letter) != -1: 
       print "You already picked", letter 
      else: 
       usedLetters = usedLetters + letter 
       index = originalWord.find(letter) 
       if index == -1: 
        tries = tries+1 
        print "The letter",letter,"is not in the word!" 
       else: 
        print"The",letter,"is in the word." 
        lettersCorrect=lettersCorrect+1 
        for rang in range(wordLength): 
         if letter == originalWord[rang]: 
          solvedWord[rang] = letter 
        if 
     os.system("CLS") 
     if tries == maxTries: 
      print gallowsDead 
      print "I'm sorry, Player B that was 6 guesses, You Lose." 
      print 'The word was "',originalWord,'"' 
      break 
     if lettersCorrect == wordLength: 
      print gallowsAlive 
      print "Congratulations,Player B ,You win." 
      print 'The word was "',originalWord,'"' 
      break 
+6

如果調試了一下這個問題,隔離它,這將是有益的,你問可能是一般有關,而不是具體到你的程序 - –

回答

4

使用find意味着你只檢查出現在originalWord中的第一個字母。所以對於「池」,猜測「o」應該將字母正確值遞增2,但它只會遞增1。

嘗試使用str.count(sub[, start[, end]])來計算被猜測的字母的實例總數,然後使用該數字以正確的數量遞增字母正確。

+0

NVM我固定它的問題:P – user1810717

+1

出於興趣,那你改變以解決問題? – Talvalin