2013-05-08 117 views
-4

我是Python新手,對於我今天一直在處理的代碼有個疑問。我正在創建一個使用while循環的遊戲,其中兩個對手將轉向彼此「打」,直到其中一個玩家擁有0點生命值。爲遊戲創建一個while循環

這是我到目前爲止的代碼,雖然它不工作。誰能幫忙?

done=False 
while not done: 
    if You.Hit_points>Opponent.Hit_points: 
     move=raw_input("Would you like to make a move? (y/n) ") 
     if move=="y": 
      print "",You.name,"hit ",Opponent.name," by",You.Hit_points," hit points!" 
      Opponent.Health=You.Hit_points+You.Skill_points+Opponent.Health 
      print "Due to the hit",Opponent.name,"is left with",Opponent.Health," health points." 
      print ("The Mighty Beast will make a move.") 
      print "",Opponent.name,"hits",You.name,"by",Opponent.Hit_points,"points" 
      You.Health=(Opponent.Hit_points-Opponent.Skill_points)+You.Health 
      print "Due to the hit",You.name,"loses",Opponent.Hit_points,"points.Leaving",You.name,"with",You.Health,"health points." 
      print "Now it is",Opponent.name,"'s turn to make a move" 
      You.Health=You.Health-(Opponent.Hit_points+Opponent.Skill_points) 
      print "Due to the hit",You.name,"is left with",You.Health,"health points." 
    else: 
     You.Hit_points==0 
     move=="n" 
     done=True 
+1

它怎麼不起作用?如果它沒有運行,可能是因爲'Opponent.Hit_points'大於'You.Hit_points'以 – 2013-05-08 02:38:49

+2

開頭,那麼你得到的錯誤信息是什麼? – Serial 2013-05-08 02:39:35

+0

我得到\t TypeError:不支持的操作數類型爲+:'int'和'str' – user2360627 2013-05-08 03:42:47

回答

0
if You.Hit_points>Opponent.Hit_points: 

也許應該

if You.Hit_points > 0 and Opponent.Hit_points > 0 

吧?否則一旦You的HP下降到Opponent以下 - 可能在第一回合後 - 戰鬥將結束。