前提・実現したいこと
RPGの対戦ゲームのようなものを作りたい
発生している問題・エラーメッセージ
player1.attack(player2) TypeError: 'int' object is not callable
#ソースコード
python
1import random 2 3class RPGgame: 4 def __init__(self,name,maxhp,attack,deffence): 5 self.name = name 6 self.maxhp = maxhp 7 self.hp = maxhp 8 self.attack = attack 9 self.deffence = deffence 10 11 def status(self): 12 return "{}: 体力{}/{}: 攻撃力{}: 防御力{}".format(self.name,self.maxhp,self.hp,self.attack,self.deffence) 13 14 def attack(self,enemy): 15 attack_point = self.attack - enemy.deffence 16 enemy.hp -= attack_point 17 print("{}の攻撃!{}に{}のダメージ!".format(self.name, enemy.name, attack_point)) 18 19player1_name = input("名前を入力してください(player1): ") 20player2_name = input("名前を入力してください(player2): ") 21 22maxhp1 = random.randint(50,70) 23maxhp2 = random.randint(50,70) 24 25player1 = RPGgame("plyer1_name", maxhp1, random.randint(20,30) , random.randint(5,10)) 26player2 = RPGgame("plyer2_name", maxhp2, random.randint(20,30) , random.randint(5,10)) 27 28print(player1.status()) 29print(player2.status()) 30 31player1.attack(player2) 32player2.attack(player1) 33 34print(player1.status()) 35print(player2.status())
このままではコードが読めないので、質問を編集し、<code>ボタンを押し、出てくる’’’の枠の中にコードを貼り付けてください
回答2件
あなたの回答
tips
プレビュー