def __init__(self):
     '''
     Initializes a new battle manager by loading the list of characters from the file and
     by initializing tkinter.
     '''
     self.character_choices = CharacterList("battle_characters.txt")
     self.root = tkinter.Tk()
class Battle_Manager(object):
    def __init__(self):
        '''
        Initializes a new battle manager by loading the list of characters from the file and
        by initializing tkinter.
        '''
        self.character_choices = CharacterList("battle_characters.txt")
        self.root = tkinter.Tk()

    def setup_character_selector(self):
        ''' This method is called to create the CharacterSelector screen. '''
        self.root.title("Select your character!")
        self.char_sel = Screen_character_selector(
            self.root, self.character_choices, self.onclose_character_selector)

    def onclose_character_selector(self, selected_char):
        ''' This method is called when the Screen_character_selector closes. 
            selected_char should contain the index in the list of the character selected by the user. 
            The method manages the assignment of the player and computer objects and then starts the 
            Prepare for Battle page.
            '''
        selected_char = int(selected_char)

        # Saves players character choice
        self.player = self.character_choices.get_and_remove_character(
            selected_char)

        # Gets a player for the computer.
        self.computer = self.character_choices.get_random_character()

        # Destroys the "Character Selection" frame
        self.char_sel.destroy()

        # Retitle the main frame.
        self.root.title("The Combatants!")

        # Creates the "Prepare to Battle" frame
        self.prepare = Screen_prepare_to_battle(self.root, self.player,
                                                self.computer,
                                                self.onclose_prepare_to_battle)

    def onclose_prepare_to_battle(self):
        ''' 
        This method is called when the user presses button on the Prepare to Battle screen.
        The method closes the current window and creates the battle window.
        '''
        # Destroy the "Prepare to Battle" frame.
        self.prepare.destroy()

        # Retitle the main frame.
        self.root.title("Battle!")

        # Create the Battle frame
        self.battle_screen = Screen_Battle(self.root, self.player,
                                           self.computer, self.onclose_battle)

    def onclose_battle(self):
        ''' This method is called after the battle is over.  This method causes the program to exit. '''
        self.root.destroy()
class Battle_Manager(object):
    def __init__(self):
        """
        Initializes a new battle manager by loading the list of characters from the file and
        by initializing tkinter.
        """
        self.character_choices = CharacterList("battle_characters.txt")
        self.root = tkinter.Tk()

    def setup_character_selector(self):
        """ This method is called to create the CharacterSelector screen. """
        self.root.title("Select your character!")
        self.char_sel = Screen_character_selector(self.root, self.character_choices, self.onclose_character_selector)

    def onclose_character_selector(self, selected_char):
        """ This method is called when the Screen_character_selector closes. 
            selected_char should contain the index in the list of the character selected by the user. 
            The method manages the assignment of the player and computer objects and then starts the 
            Prepare for Battle page.
            """
        selected_char = int(selected_char)

        # Saves players character choice
        self.player = self.character_choices.get_and_remove_character(selected_char)

        # Gets a player for the computer.
        self.computer = self.character_choices.get_random_character()

        # Destroys the "Character Selection" frame
        self.char_sel.destroy()

        # Retitle the main frame.
        self.root.title("The Combatants!")

        # Creates the "Prepare to Battle" frame
        self.prepare = Screen_prepare_to_battle(self.root, self.player, self.computer, self.onclose_prepare_to_battle)

    def onclose_prepare_to_battle(self):
        """ 
        This method is called when the user presses button on the Prepare to Battle screen.
        The method closes the current window and creates the battle window.
        """
        # Destroy the "Prepare to Battle" frame.
        self.prepare.destroy()

        # Retitle the main frame.
        self.root.title("Battle!")

        # Create the Battle frame
        self.battle_screen = Screen_Battle(self.root, self.player, self.computer, self.onclose_battle)

    def onclose_battle(self):
        """ This method is called after the battle is over.  This method causes the program to exit. """
        self.root.destroy()
 def __init__(self):
     """
     Initializes a new battle manager by loading the list of characters from the file and
     by initializing tkinter.
     """
     self.character_choices = CharacterList("battle_characters.txt")
     self.root = tkinter.Tk()
Example #5
0
def main():
    # Loads the character list from the file
    character_choices = CharacterList("battle_characters.txt")
    # Get the user's choice
    print("Prepare to battle!\n\nWhich character would you like?")
    character_choices.print_list()
    iMax = character_choices.get_number_of_characters()
    choice = int(input())
    while (choice < 0 or choice >= iMax):
        choice = int(
            input("Please choose between 0 and " + str(iMax - 1) + "."))

    # Get the character for the user and the computer.
    player = character_choices.get_and_remove_character(choice)
    computer = character_choices.get_random_character()
    #print(player)
    #print(computer)
    # Preparation for the battle

    print("The computer picked " + computer.name)
    print("Let's battle!\n")
    # Battle Loop
    rnd = 1
    while (player.hit_points > 0 and computer.hit_points > 0):
        print("Round: " + str(rnd))
        player.attack(computer)
        computer.attack(player)

        if (player.hit_points <= 0 or computer.hit_points <= 0):
            if (computer.hit_points <= 0):
                computer.die()

            if (player.hit_points <= 0):
                player.die()

        else:
            print(player.name + ": " + str(player.hit_points) +
                  " hit points remaining.")
            print(computer.name + ": " + str(computer.hit_points) +
                  " hit points remaining.")
            input("\nPress enter to continue battle.\n")
            rnd += 1

    # Print exit message
    if (player.hit_points <= 0) and (computer.hit_points <= 0):
        print("\nThe battle ended in a tie.")
    elif (player.hit_points <= 0):
        print("\nYou have lost.")
    else:
        print("\nYou have won!")

    end_game = input("Press Enter to Exit")
Example #6
0
def main ():
    # Loads the character list from the file
    character_choices = CharacterList ("battle_characters.txt")
    # Get the user's choice
    print ("Prepare to battle!\n\nWhich character would you like?")
    character_choices.print_list()
    iMax = character_choices.get_number_of_characters()
    choice = int(input ())
    while (choice < 0 or choice >=iMax):
        choice = int(input ("Please choose between 0 and " + str (iMax-1) + "."))
    
    # Get the character for the user and the computer.
    player = character_choices.get_and_remove_character (choice)
    computer = character_choices.get_random_character()
    #print(player)
    #print(computer)
    # Preparation for the battle

    print ("The computer picked " + computer.name)
    print ("Let's battle!\n")
    # Battle Loop
    rnd = 1
    while (player.hit_points > 0 and computer.hit_points > 0):
        print ("Round: " + str (rnd))
        player.attack(computer)       
        computer.attack(player)

        if (player.hit_points <= 0 or computer.hit_points <= 0):
            if (computer.hit_points <= 0):
                computer.die()

            if (player.hit_points <= 0):
                player.die()
        
        else:
            print (player.name + ": " + str(player.hit_points) + " hit points remaining.")
            print (computer.name + ": " + str(computer.hit_points) + " hit points remaining.")
            input ("\nPress enter to continue battle.\n")
            rnd += 1
   
    # Print exit message
    if (player.hit_points <= 0) and (computer.hit_points <= 0):
        print ("\nThe battle ended in a tie.")
    elif (player.hit_points <= 0):
        print ("\nYou have lost.")
    else:
        print ("\nYou have won!")
        
    end_game=input("Press Enter to Exit")
 def onback_prepare_to_battle(self):
     self.character_choices = CharacterList("battle_characters.txt")
     self.prepare.destroy()
     self.root.title("Select your character!")
     self.char_sel = Screen_character_selector(
         self.root, self.character_choices, self.onclose_character_selector)