2017-02-28 7 views
0

私はポケモンのターンベースのシミュレータを構築しています。具体的には、ピカチュウとスピアローの戦い(いくつかの創造的な自由が取られている)。問題は、ユーザーに使用したい移動を尋ねるたびに、移動が無効であるという応答を返すことです。ユーザーからの入力は、常にPythonで無効と見なされます

# Import Libraries and Methods 
import abc 
from random import randint 
from enum import Enum 

DamageTypes = Enum("DamageTypes", "Damaging") 
Types = Enum("Types", "ELECTRIC NORMAL FLYING") 

class attack(metaclass=abc.ABCMeta): 
    @abc.abstractproperty 
    def damage_type(self): 
     return NotImplemented 

    @abc.abstractproperty 
    def move_type(self): 
     return NotImplemented 

class Tackle(attack): 

    #def __bool__(self): 
     #return self.Tackle is False 

    @property 
    def damage_type(self): 
     return DamageTypes.Damaging 

    @property 
    def move_type(self): 
     return Types.NORMAL 


class Thundershock(attack): 

    #def __bool__(self): 
     #return self.Thundershock is False 

    @property 
    def damage_type(self): 
     return DamageTypes.Damaging 

    @property 
    def move_type(self): 
     return Types.ELECTRIC 

class Peck(attack): 

    #def __bool__(self): 
     #return self.Peck is False 

    @property 
    def damage_type(self): 
     return DamageTypes.Damaging 

    @property 
    def move_type(self): 
     return Types.FLYING 

def damage_calculator(monster1, monster2): 
    #Critical Strike Chance Modifier 
    Critical = 1 
    Critical_Chance = randint(0,9) 
    if Critical_Chance == 0: 
     Critical = 2 

    #STAB (or Same Type Attack Bonus) Modifier 
    STAB = 1 
    #for player 
    if monster1.attack is True: 
     if Thundershock(attack) is True: 
      STAB = 1.5 
     elif Tackle(attack) is True: 
      STAB = 1 
    #for enemy 
    if monster2.attack is True: 
     if Peck(attack) is True: 
      STAB = 1.5 
     if Tackle(attack) is True: 
      STAB = 1.5 

    #Modifier for Minimum Possible Damage Dealt 
    DmgModifierLow = STAB*Critical*0.85 
    #Modifier for Maximum Possible Damage Dealt 
    DmgModifierHigh = STAB*Critical 

    if monster1.attack is True: 
     if 'user_choice' == 'thundershock': 
      AttackDamage = magic_1 
      DamageDefense = magic_defense_2 
      Base = 40 
     elif 'user_choice' == 'tackle': 
      AttackDamage = attack_1 
      DamageDefense = defense_2 
     Base = 40 
    elif monster2.attack is True: 
     if wild_choice == 0: 
      AttackDamage = attack_2 
      DamageDefense = defense_1 
      Base = 40 
     elif wild_choice == 1: 
      AttackDamage = attack_2 
      DamageDefense = defense_1 
      Base = 35 

    DamageHigh = ((210/250)*(AttackDamage/DamageDefense)* (Base)+2)*DmgModifierHigh 
    DamageLow = ((210/250)*AttackDamage/DamageDefense*(Base)+2)*DmgModifierLow 
    DamageDealt = randint(DamageLow,DamageHigh) 

    if monster1.attack: 
     monster2.current_health_2 -= DamageDealt 
    if monster2.attack: 
     monster1.current_health_1 -= DamageDealt 

# create the stats for the monsters 
Pikachu = [] 
Spearow = [] 

# apply stats to Pikachu 
health_1 = randint(180, 211) 
#health that is modified 
current_health_1 = health_1 
attack_1 = randint(115, 146) 
magic_1 = randint(85, 116) 
defense_1 = randint(105, 136) 
magic_defense_1 = randint(105, 136) 
speed_1 = randint(185, 216) 

# apply stats to Spearow 
health_2 = randint(190, 221) 
#health that is modified 
current_health_2 = health_2 
attack_2 = randint(125, 156) 
magic_2 = randint(65, 96) 
defense_2 = randint(67, 98) 
magic_defense_2 = randint(67, 98) 
speed_2 = randint(145, 176) 

def standby_battle_text(monster1, monster2): 
    print("-----------------") 
    print("SPEAROW  HP: {}/{}".format(current_health_2, health_2)) 
    print(" ") 
    print(" ") 
    print("PIKACHU  HP: {}/{}".format(current_health_1, health_1)) 
    user_choice = str.lower(input("What attack would you like to choose? (Tackle, Thundershock, or Heal) ")) 
    print("You used {}".format(user_choice)) 


class monster1: 
# Method for the stats for monster 1 
def __init__(self, health_1, current_health_1, attack_1, magic_1, defense_1, magic_defense_1, speed_1): 
    self.health_1 = health_1 
    self.current_health_1 = current_health_1 
    self.attack_1 = attack_1 
    self.magic_1 = magic_1 
    self.defense_1 = defense_1 
    self.magic_defense_1 = magic_defense_1 
    self.speed_1 = speed_1 

# Method for the attack of monster 1 
def attack(self, monster2): 
    while True: 
     standby_battle_text(monster1, monster2) 
     if 'user_choice' == "tackle": 
      #Tackle(attack) is True 
      damage_calculator(monster1, monster2) 
      #Tackle(attack) is False 
      #current_health_2 -= DamageDealt 
      break 
     if 'user_choice' == "thundershock": 
      #Thundershock(attack) is True 
      damage_calculator(monster1, monster2) 
      #Thundershock(attack) is False 
      #current_health_2 -= DamageDealt 
      break 
     if 'user_choice' == "heal": 
      current_health_1 += 50 
      if current_health_1 >= health_1: 
       current_health_1 = health_1 
      break 
     else: 
      print("That is not a valid move! Please choose again.") 
      print(" ") 


class monster2: 
    def __init__(self, health_2, current_health_2, attack_2, magic_2, defense_2, magic_defense_2, speed_2): 
    self.health_2 = health_2 
    self.current_health_2 = current_health_2 
    self.attack_2 = attack_2 
    self.magic_2 = magic_2 
    self.defense_2 = defense_2 
    self.magic_2 = magic_defense_2 
    self.speed_2 = speed_2 

# Method for the attack of monster 2 
def attack(self, monster1): 
    if current_health_2 <= 50: 
     enemy_heal_chance = randint(0, 3) 
     if enemy_heal_chance == 0 or enemy_heal_chance == 1: 
      current_health_2 += 50 
    else: 
     wild_choice = randint(0,1) 
     if wild_choice == 0: 
      #Tackle(attack) is True 
      damage_calculator(monster1, monster2) 
      #Tackle(attack) is False 
      #current_health_1 -= DamageDealt 
     if wild_choice == 1: 
      #Peck(attack) is True 
      damage_calculator(monster1, monster2) 
      #Peck(attack) is False 
      #current_health_1 -= DamageDealt 

Pikachu.append(monster1(health_1, current_health_1, attack_1, magic_1, defense_1, magic_defense_1, speed_1)) 
Spearow.append(monster2(health_2, current_health_2, attack_2, magic_2, defense_2, magic_defense_2, speed_2)) 

答えて

0
  • user_choice('user_choice')周りの単一引用符があります。削除してください。
  • standby_battle_text()機能から値を戻していません。したがって、メソッドmonster1の中にuser_choiceが認識される方法はありません。だから、return user_choiceからstandby_battle_text()
+1

私はこれがOPが行うべきであることに同意します。しかし今、彼は 'NameError:name 'user_choice'がその行に定義されていません。彼はそれについて何をすべきでしょうか? – Kevin

+0

不足している点をありがとう。 – Ujjwal

関連する問題