2016-11-30 5 views
-1

最近、私の友人と私は、ファンタジースタイルのゲームのためにPythonでテキストベースのバトルシーケンス(コンソールで)を始めました。最初に行くだろう彼らのアタック(ATT)+ HP(HP)、そして誰でも高い知性(INL)は、現在の状況:テキストベースのバトルメカニッ​​クス - Python

概要

それが動作する方法は、ユーザーがで提示されていることです。ユーザーが最初に行くと、彼らは3つのオプションを与えられます - 攻撃、恐怖と他の動き。私は 'Bide your time'を使っています。

相手は(自分がコントロールしていない)自分の移動のうち3つの間でランダムに選択し、そのチャンスを変えてから実行します。次に、他のものより高い知性を持っています。

HPのいずれかが0になるまで交互に続行する必要があります。ユーザーが相手を倒す場合、相手の統計/属性のいずれかを吸収するかどうかを選択する必要があります。

'battle'変数は、戦闘が開始されたかどうかによって異なります。

たび:0あなたはそれを離れて怖がらせるのいずれかの後に追加、または

問題です(「戦いが」1の場合、ループは継続すべきであるが、それが0であれば、それは停止する必要があります私はそれだけで起こる何にもかかわらず、ループを継続し、継続的に私の番で、コードを実行します。

  • 私はループが実際に動作しながら、どのように誤解がありますか?

今後の計画

  • 私はバランスの取れた方法でユーザーHP、攻撃と知性を変更します異なる人種(すなわちドワーフ、エルフ、オークなど)を追加する予定です。

  • 私はクラスを追加することも計画しています。クラスを追加することで、「Bide your time」の動きがクラス固有の動きに置き換えられます。

あなたが作成した提案や修正をお読みいただきありがとうございます。

import random 
import time 

Att = 10 
Inl = 5 
HP = 100 

OpAtt = 10 
OpInl = 4 
OpHP = 100 

FirstMove = 1 
OpFirstMove = 0 

battle = 1 

while battle == 1: 
    if Inl > OpInl: 
     FirstMove == 1 
     OpFirstMove == 0 
    else: 
     FirstMove == 0 
     OpFirstMove == 1 
    if FirstMove > OpFirstMove: 
     print("Your Current stats are:") 
     print("Attack:", Att) 
     print("HP:", HP) 
     time.sleep(2) 
     print("Your Opponent's current stats are:") 
     print("Attack:", OpAtt) 
     print("HP:", OpHP) 
     time.sleep(2) 
     print("Your turn!") 
     time.sleep(1) 
    else: 
     print("Your Current stats are:") 
     print("Attack:", Att) 
     print("HP:", HP) 
     time.sleep(2) 
     print("Your Opponent's current stats are:") 
     print("Attack:", OpAtt) 
     print("HP:", OpHP) 
     time.sleep(2) 
     print("Opponent's turn!") 
     time.sleep(1) 
    if FirstMove > OpFirstMove: 
     print("Select a move:") 
     Move1 = str(input(print("[A] Attack opponent\n[B] Bide your time\n[C] Try to scare your opponent off"))) 
     if Move1 == 'A' or Move1 == 'a': 
      Hit1 = random.randint(1, 4) 
      if Hit1 == 4 or 3 or 2: 
       damageRand = random.randint(8, 12) 
       OpHP = OpHP - damageRand 
       print("Success!, Opponet's HP is now", OpHP, ".") 
       FirstMove == 0 
       OpFirstMove == 1 
      else: 
       print("Failure, no damage dealt.") 
       FirstMove == 0 
       OpFirstMove == 1 
     elif Move1 == 'b' or Move1 == "B": 
      print("You do nothing") 
      FirstMove == 0 
      OpFirstMove == 1 
     elif Move1 == "c" or "C": 
      Scare1 = random.randint(1, 7) 
      if OpHP > 71: 
       if Scare1 == 7 or 6: 
        print("Congratulations!, you scared the opponent away, however, this means you gained no loot.") 
        battle == 0 
      elif OpHP < 70: 
       if Scare1 == 7 or 6 or 5 or 4: 
        print("Congratulations!, you scared the opponent away, however, this means you gained no loot.") 
        battle == 0 
      else: 
       print("Failure, the opponent stands his ground") 
       FirstMove == 0 
       OpFirstMove == 1 
    if OpFirstMove > FirstMove: 
     OpMove1 = random.randint(1, 8) 
     if OpMove1 == 1 or OpMove1 == 2 or OpMove1 == 3 or OpMove1 == 4 or OpMove1 == 5: 
      OpHit1 = random.randint(1, 4) 
      if OpHit1 == 4 or 3 or 2: 
       damageRand = random.randint(8, 12) 
       HP = HP - damageRand 
       print("Your Opponent Attacks!, Your HP is now", HP, ".") 
       FirstMove = 1 
       OpFirstMove = 0 
      else: 
       print("Your Opponent failed to attack you, no damage received.") 
       FirstMove = 1 
       OpFirstMove = 0 
     elif OpMove1 == 6: 
      print("Your Opponent does nothing") 
      FirstMove = 1 
      OpFirstMove = 0 
     elif OpMove1 == 7 or OpMove1 == 8: 
      OpScare1 = random.randint(1, 7) 
      if HP > 71: 
       if OpScare1 == 7 or 6: 
        print("Aargh!, you were scared away, don't worry though, this has no bad affects.") 
        battle == 0 
      elif HP < 70: 
       if OpScare1 == 7 or 6 or 5 or 4: 
        print("Aargh!, you were scared away, don't worry though, this has no bad affects.") 
        battle == 0 
      else: 
       print("Your Opponent tried to scare you away, but failed") 
       FirstMove = 1 
       OpFirstMove = 0 
else: 
    print("Pies are tasty") 


if OpHP < 1: 
     print ("Congratulations! You deafeated your Opponent, which one of their stats would you like to absorb?") 
     print("Your Opponent's current stats are:") 
     print("Attack:", OpAtt) 
     print("HP:", OpHP) 
     print ("Intellect:", OpInl) 
     absorb1 = print (str(input("[A] Intellect\n[B] Attack\n[C] HP\n[D] None of the above"))) 
     if absorb1 == "a" or absorb1 == "A": 
      Inl == OpInl 
      print ("Opponent's intellect absorbed") 
     elif absorb1 == "b" or absorb1 == "B": 
      Att == OpAtt 
      print ("Opponent's Attack absorbed") 
     elif absorb1 == "c" or absorb1 == "C": 
      HP == OpHP 
      print ("Opponent's HP absorbed") 
     elif (absorb1 == "d" or absorb1 == "D"): 
      print ("None of your Opponent's stats absorbed") 
     print("Your current stats are:") 
     print("Attack:", Att) 
     print("HP:", HP) 
     print ("Intellect:", Inl) 
elif HP < 1: 
    print ("Oh no! You were defeated by your Opponent!") 
    battle == 0 
+1

[よくある質問と回答](http://stackoverflow.com/help/how-to-ask)、[** M ** inimal、** C ** ompleteの作成、および** V ** erifiable ** E ** xample](http://stackoverflow.com/help/mcve)。一般的に言えば、コードを含む質問は、問題を再現するのに必要な最小のコードしか含まないように絞られなければなりません。つまり、不適切な働きをする特定の関数(またはその関数から数行)実行するために必要なサポートコード。 –

+0

'battle == 0'は' battle'がゼロであるかどうかをチェックします。 'battle = 0'は' battle'の値をゼロに割り当てます –

+0

'(input)'にprintステートメントを置かないでください。これが間違っているかどうかはわかりませんが、正しくはありません... –

答えて

0

私が見る主な問題は、あなたがbattle == 0を言うときあなたは変数battleに0を代入していないということです。あなたはただランダムにチェックされている戦いの値を変更していない最後の

  if OpScare1 == 7 or 6 or 5 or 4: 
       print("Aargh!, you were scared away, don't worry though, this has no bad affects.") 
       battle == 0 

それが0に等しい場合は、すべて変更する必要があります。battleはあなたが言うとき、例えば、だから、0に等しい場合は、テストしています変数をbattle = 0に割り当てようとしているもののうちの1つです。これらの例は数多くあります。

しかし、OpScare1 == 7と言っているのは、条件をテストしているif文にあるためです。

関連する問題