私はテキストゲームで戦闘システムを実装しようとしています。私はちょうど私が私に教えることを試みていると思う本の演習がハードコーディングを最小限に抑えるために異なるint
値を持つ私のシーンのそれぞれのインスタンスを作成することができたと思った。私は辞書でTestRoom
クラスにアクセスするときには、PowerShellで言う:クラスを使った戦闘システムの作成
TypeError: __init__() takes exactly 4 arguments (1 given)
私は、Pythonに新たなんだ、私はこれを行う方法を見つけ出す手助けと書籍はよくクラスを説明していませんしてください。
class Hero(object):
def __init__(self, health1, damage1, bullets1):
self.health1 = health1
self.damage1 = damage1
self.bullets1 = bullets1
class Gothon(object):
def __init__(self, health2, damage2):
self.health2 = health2
self.damage2 = damage2
class Combat(object):
def battle():
while self.health1 != 0 or self.health2 != 0 or self.bullets1 != 0:
print "You have %r health left" % self.health1
print "Gothon has %r health left" % self.health2
fight = raw_input("Attack? Y/N?\n> ")
if fight == "Y" or fight == "y":
self.health2 - self.damage1
self.health1 - self.damage2
elif fight == "N" or fight == "n":
self.health1 - self.damage2
else:
print "DOES NOT COMPUTE"
if self.health1 == 0:
return 'death'
else:
pass
class TestRoom(Combat, Hero, Gothon):
def enter():
hero = Hero(10, 2, 10)
gothon = Gothon(5, 1)
これは、Python 2.7
サイドノートである:Pythonの3アウトでPyhton 2.7悪いことを学んでいますか?答えは本当に必要ではありません、ちょうど不思議です。