예제 #1
0
    def __init__(self, name: str, bq: 'BattleQueue', ps: 'Playstyle') -> None:

        """
        Initialize this Sorcerer with the name name, battle_queue bq, and
        playstyle ps.

        >>> from a2_battle_queue import BattleQueue
        >>> from a2_playstyle import ManualPlaystyle
        >>> bq = BattleQueue()
        >>> c = Sorcerer("r", bq, ManualPlaystyle(bq))
        >>> c2 = Sorcerer("r2", bq, ManualPlaystyle(bq))
        >>> c.enemy = c2
        >>> c2.enemy = c
        >>> c
        r (Sorcerer): 100/100
        """

        super().__init__(name, bq, ps)
        self._character_type = 'sorcerer'

        self._skills['S'] = SorcererSpecial()

        self._defense = 10

        self.default = create_default_tree()
        self._skills['A'] = SorcererAttack(self.default.pick_skill(self, self))
    def setUp(self):
        """
        Sets up a Battle Queue containing 2 Sorcerer for all of the 
        unittests.
        """
        self.battle_queue = BattleQueue()
        playstyle = ManualPlaystyle(self.battle_queue)

        self.p1 = SorcererConstructor("P1", self.battle_queue, playstyle)
        self.p2 = SorcererConstructor("P2", self.battle_queue, playstyle)

        self.p1.enemy = self.p2
        self.p2.enemy = self.p1

        self.p1.set_skill_decision_tree(create_default_tree())
        self.p2.set_skill_decision_tree(create_default_tree())

        self.battle_queue.add(self.p1)
        self.battle_queue.add(self.p2)
    def setUp(self):
        """
        Sets up 2 SkillDecisionTrees for use in the test cases.
        """
        self.default_tree = create_default_tree()

        self.basic_tree = self.create_basic_tree()

        lines = [
            "                [3, Caster SP > 20, MageSpecial]",
            "                    /                    \\",
            "[2, Target HP < 20, RogueAttack]    [1, Caster HP < 20, MageAttack]"
        ]
        self.basic_tree_format = "\n".join(lines)

        bq = BattleQueue()

        self.caster = Rogue("Caster", bq, ManualPlaystyle(bq))
        self.target = Rogue("Target", bq, ManualPlaystyle(bq))
예제 #4
0
def set_up_game():
    """
    Sets up the battle queue and characters for the game.
    """
    global P1, P2, BATTLE_QUEUE

    # Create a new battle queue
    bq = ''
    while bq not in list(BATTLE_QUEUE_CLASSES.keys()):
        bq = input(
            "Select a Battle Queue type (n for a Normal Battle Queue, " +
            "r for a Restricted Battle Queue): ").strip()

    BATTLE_QUEUE = BATTLE_QUEUE_CLASSES[bq]()

    # Get the parameters for the first character
    player_1 = ''
    player_1_playstyle = ''

    while player_1 not in list(CHARACTER_CLASSES.keys()):
        player_1 = input("Select a class for the first character (m for " +
                         "Mage, r for Rogue, v for Vampire, s for " +
                         "Sorcerer): ").strip()

    player_1_name = input("Select a name for the first character: ").strip()

    while player_1_playstyle not in list(PLAYSTYLE_CLASSES.keys()):
        player_1_playstyle = input("Select a playstyle for the first " +
                                   "character (m for Manual, r for Random, " +
                                   "mr for Minimax (Recursive), " +
                                   "mi for Minimax (Iterative)): ")
        player_1_playstyle = player_1_playstyle.strip()

    # Get the parameters for the second character
    player_2 = ''
    player_2_playstyle = ''

    while player_2 not in list(CHARACTER_CLASSES.keys()):
        player_2 = input("Select a class for the second character (m for " +
                         "Mage, r for Rogue, v for Vampire, s for " +
                         "Sorcerer): ").strip()

    player_2_name = input("Select a name for the second character: ").strip()

    while player_2_playstyle not in list(PLAYSTYLE_CLASSES.keys()):
        player_2_playstyle = input("Select a playstyle for the second " +
                                   "character (m for Manual, r for Random, " +
                                   "mr for Minimax (Recursive), " +
                                   "mi for Minimax (Iterative)): ")
        player_2_playstyle = player_2_playstyle.strip()

    # Store the classes in other variable names for convenience
    P1_Character = CHARACTER_CLASSES[player_1]
    P2_Character = CHARACTER_CLASSES[player_2]
    p1_playstyle = PLAYSTYLE_CLASSES[player_1_playstyle](BATTLE_QUEUE)
    p2_playstyle = PLAYSTYLE_CLASSES[player_2_playstyle](BATTLE_QUEUE)

    # Call the corresponding __init__ for each player's character class
    # The parameters passed in are: their name, the battle queue and an
    # instance of their playstyle
    P1 = P1_Character(player_1_name, BATTLE_QUEUE, p1_playstyle)
    P2 = P2_Character(player_2_name, BATTLE_QUEUE, p2_playstyle)

    if player_1 == 's':
        default_tree = create_default_tree()
        P1.set_skill_decision_tree(default_tree)

    if player_2 == 's':
        default_tree = create_default_tree()
        P2.set_skill_decision_tree(default_tree)

    # Set the enemy attribute of the characters
    # You can assume this will be called before any attacks are performed
    P1.enemy = P2
    P2.enemy = P1

    # Add the characters to the Battle Queue
    BATTLE_QUEUE.add(P1)
    BATTLE_QUEUE.add(P2)