Ejemplo n.º 1
0
 def test_player_buy_card(self):
     """
     Tests the buy_card method. This method only checks whether the attack
     action works properly.Any validation checks are conducted in parent
     methods and are thus checked using alternative test cases.
     """
     player = Player('Nikos')
     player._money = 10
     central = {
         'deck': CardsCollection(),
         'active': CardsCollection(),
         'supplement': CardsCollection(),
         'active_size': 5
     }
     central['deck'].push(Card('Deck card', 3, 0, 2), 1)
     central['active'].push(Card('Archer', 3, 0, 2), 5)
     player.buy_card(central['active'], central['deck'], 0)
     self.assertEqual(central['active'].size(), 5)
     self.assertEqual(player.discard.size(), 1)
     self.assertEqual(player.discard.cards[0].name, 'Archer')
     self.assertEqual(central['active'].cards[4].name, 'Deck card')
     player.buy_card(central['active'], central['deck'], 0)
     # deck size = 0 now -> no more cards from deck to active area
     self.assertEqual(central['active'].size(), 4)
     self.assertEqual(player.discard.size(), 2)
 def test_collection_replace(self):
     """
     Tests whether collection's content is correctly replaced by that of
     another -given- collection, when calling the appropriate method.
     """
     collection1 = CardsCollection()
     collection2 = CardsCollection()
     collection1.push(Card('Archer', 3, 0, 2), 2)
     collection2.push(Card('Deck card', 3, 0, 2), 3)
     collection1.replace(collection2)
     self.assertEqual(collection1.cards, collection2.cards)
Ejemplo n.º 3
0
 def __init__(self):
     """
     Initialises the game by adding new players,
     Two Decks: 1st for whole cards
                2nd for only used / played cards
     start used for who starts first
     """
     self.player_1 = Player('Player 1')
     self.player_2 = Player('Player PC')
     self.deck = CardsCollection()
     self.discard = CardsCollection()
     self.start = True
Ejemplo n.º 4
0
 def __init__(self):
     """
     Initialises the game by adding new players and defining the central area.
     """
     self.player_1 = Player('Player 1')
     self.player_pc = Player('Player PC')
     self.central = {
         'deck': CardsCollection(),
         'active': CardsCollection(),
         'supplement': CardsCollection(),
         'active_size': 5
     }
     self.aggressive = True
 def test_collection_clear(self):
     """
     Tests whether the list is cleared when using the appropriate method.
     """
     collection = CardsCollection()
     collection.push(Card('Archer', 3, 0, 2), 5)
     collection.push(Card('Deck card', 3, 0, 2), 5)
     collection.clear_collection()
     self.assertEqual(collection.cards, [])
 def test_collection_shuffle(self):
     """
     Tests whether the shuffling results to unexpected results.
     """
     collection = CardsCollection()
     collection.push(Card('Archer', 3, 0, 2), 5)
     collection.push(Card('Deck card', 3, 0, 2), 5)
     collection.shuffle_collection()
     self.assertEqual(len(collection.cards), 10)
 def test_collection_size(self):
     """
     Tests whether the size of the list returned when calling the
     appropriate method is the expected one.
     """
     collection = CardsCollection()
     self.assertEqual(collection.size(), 0)
     collection.push(Card('Archer', 3, 0, 5), 2)
     collection.push(Card('Test1', 1, 1, 1), 3)
     self.assertEqual(collection.size(), 5)
Ejemplo n.º 8
0
 def test_player_buy_supplement(self):
     """
     Tests the buy_supplement method. This method only checks whether the attack
     action works properly.Any validation checks are conducted in parent
     methods and are thus checked using alternative test cases.
     """
     player = Player('Nikos')
     player._money = 2
     central = {
         'deck': CardsCollection(),
         'active': CardsCollection(),
         'supplement': CardsCollection(),
         'active_size': 5
     }
     central['supplement'].push(Card('Levy', 1, 2, 2), 10)
     player.buy_supplement(central['supplement'])
     self.assertEqual(central['supplement'].size(), 9)
     self.assertEqual(player.discard.size(), 1)
     self.assertEqual(player.money, 0)
 def test_collection_pop(self):
     """
     Tests whether cards are removed successfully and correctly by the
     list.
     """
     collection = CardsCollection()
     card1 = Card('Archer', 3, 0, 2)
     card2 = Card('Test1', 1, 1, 1)
     card3 = Card('Test2', 1, 2, 1)
     collection.push(card1, 1)
     collection.push(card2, 2)
     collection.push(card3, 1)
     card_pop = collection.pop()
     self.assertEqual(card_pop, card3)
     card_pop = collection.pop(0)
     self.assertEqual(card_pop, card1)
 def test_collection_push(self):
     """
     Tests whether cards are appended successfully and correctly to the
     list.
     """
     collection = CardsCollection()
     card1 = Card('Archer', 3, 0, 2)
     card2 = Card('Archer', 1, 2, 1)
     collection.push(card1, 2)
     collection.push(card2)
     temp_list = [card1, card1, card2]
     self.assertSequenceEqual(collection.cards, temp_list)
Ejemplo n.º 11
0
class Game(object):
    """
    Simulates a game. This is the main class of the game.
    """
    def __init__(self):
        """
        Initialises the game by adding new players,
        Two Decks: 1st for whole cards
                   2nd for only used / played cards
        start used for who starts first
        """
        self.player_1 = Player('Player 1')
        self.player_2 = Player('Player PC')
        self.deck = CardsCollection()
        self.discard = CardsCollection()
        self.start = True

    def start_game(self):
        """
        This is the main method of the game. It plays the game until a winner
        is identified.
        """
        self.set_up_game()
        self.start = self.get_opponent()

        # player_selection = input('Please select 1. 1 player \n2. 2 Players')
        # if player_selection == '2':
        #     for _ in range(self.deck.size()-1):
        #         self.player_1_turn()
        #         self.player_2_turn()

        winner = False
        while not winner:
            if self.start:
                self.player_1_turn()
                self.display_info()
                winner = self.check_winner()

            else:
                self.player_2_turn()
                self.display_info()
                winner = self.check_winner()

    @staticmethod
    def get_opponent():
        """
        Simulating dice throws and whoever gets higher number will start the game.
        """
        player_1_dice = random.randint(1, 6)
        print("\nPlayer 1 dice score" + str(player_1_dice))
        player_2_dice = random.randint(1, 6)
        print("\nPlayer 2 dice score" + str(player_2_dice))

        if player_1_dice >= player_2_dice:
            print('Player 1 will start the game')
            return True
        else:
            print('Player 2 will start the game')
            return False

    def set_up_game(self):
        """
        Initialises the game by generating the decks,
         Distributing equal numbers of the card randomly to players.
        """
        self.init_central_deck()
        self.deck.shuffle_collection()
        self.player_1._handsize = int(self.deck.size() / 2)
        self.player_2._handsize = int(self.deck.size() / 2)
        self.player_1.init_hand(self.deck)
        self.player_2.init_hand(self.deck)

    def init_central_deck(self):
        """
        Initialises the central deck by pushing the predefined cards into the
        deck.
        format (Name,Strength, Skill, Size)
        """
        self.deck.push(Card('Iron Man', 30, 45, 35))
        self.deck.push(Card('Hulk', 50, 10, 50))
        self.deck.push(Card('Groot', 40, 19, 48))
        self.deck.push(Card('Thanos', 45, 30, 46))
        self.deck.push(Card('Thor', 35, 25, 36))
        self.deck.push(Card('Ultron', 33, 48, 38))
        self.deck.push(Card('Captain-America', 36, 42, 33))
        self.deck.push(Card('Spider-man', 26, 50, 26))
        self.deck.push(Card('Vision', 28, 24, 28))
        self.deck.push(Card('Star-lord', 18, 32, 27))

    def display_info(self):
        """
        Displays player's Standings.
        """

        print("|----------------- INFO -----------------|")
        print("Displays player's Standings point:")
        print('You: %s' % self.player_1.point)
        print('PC: %s' % self.player_2.point)
        print('----------------------------------------')

    def player_1_turn(self):
        """
        This method is responsible for player's (player_1) turn. It asks for
        the action to be taken by printing appropriate messages indicating the
        valid options and calls the corresponding methods.
        """
        while True:
            self.display_info()
            print("\n----------------------------------------")

            if self.player_1.hand.size() > 0:
                self.player_1.hand.print_card(-1)
                print(
                    "Choose Action: (S = Strength, K = skill, I = size, G = God, R=Resurrect)"
                )
                valid = ['S', 'K', 'I', 'G', 'R']
                self.player_1_action(valid)
            else:
                print("\nNo more possible actions.\nTurn ending.")
                break

    def player_1_action(self, valid):
        """
        Gets user's choice, validates it and calls the appropriate method to
        complete the action.

        :param valid: a list of valid options for user's input
        :return True: if user decides to end his turn (False otherwise)
        """
        action = input("Enter Action: ")
        if action not in valid:
            print("\nPlease give a valid option!")
        elif action == 'S':
            self.player_1.play_card(-1, -1, self.player_2, self.discard,
                                    action)
        elif action == 'K':
            self.player_1.play_card(-1, -1, self.player_2, self.discard,
                                    action)
        elif action == 'I':
            self.player_1.play_card(-1, -1, self.player_2, self.discard,
                                    action)
        elif action == 'G':
            if self.player_1._godspell == 1:
                op_index = int(
                    input('Please mention which card opponent should play ?'))
                index = int(
                    input('Please mention which card you want to play ?'))
                self.player_1.hand.print_card(index)
                print(
                    "Choose Action: (S = Strength, K = skill, I = size, R=Resurrect)"
                )
                characteristics = input('please enter')
                self.player_1.play_card(index, op_index, self.player_1,
                                        self.discard, characteristics)
                self.player_1._godspell = 0
            elif self.player_1._godspell > 1 or self.player_1._godspell < 1:
                print('You already played God spell or wrong selection')

        elif action == 'R':
            if self.player_1._resurrectspell == 1:
                player_resurrect = random.randint(1, self.discard.size() - 1)
                card = self.discard.pop(player_resurrect)
                self.player_1.hand.push(card)
                self.player_1._resurrectspell = 0
                self.player_1_turn()
                # self.player_1.play_card(-1,-1, self.player_2, self.discard)

            elif self.player_1._godspell > 1 or self.player_1._godspell < 1:
                print('You already played Resurrect spell or wrong selection')
            return True
        return False

    def player_2_turn(self):
        """
        This method is responsible for player's (player_2) turn. It asks for
        the action to be taken by printing appropriate messages indicating the
        valid options and calls the corresponding methods.
        """
        while True:
            self.display_info()
            print("\n----------------------------------------")

            if self.player_2.hand.size() > 0:
                self.player_2.hand.print_card(-1)
                print(
                    "Choose Action: (S = Strength, K = skill, I = size, G = God, R=Resurrect)"
                )
                valid = ['S', 'K', 'I', 'G', 'R']
                self.player_2_action(valid)
            else:
                print("\nNo more possible actions.\nTurn ending.")
                break

    def player_2_action(self, valid):
        """
        Gets user's choice, validates it and calls the appropriate method to
        complete the action.

        :param valid: a list of valid options for user's input
        :return True: if user decides to end his turn (False otherwise)
        """
        action = input("Enter Action: ")
        if action not in valid:
            print("\nPlease give a valid option!")
        elif action == 'S':
            self.player_2.play_card(-1, -1, self.player_1, self.discard,
                                    action)
        elif action == 'K':
            self.player_2.play_card(-1, -1, self.player_1, self.discard,
                                    action)
        elif action == 'I':
            self.player_2.play_card(-1, -1, self.player_1, self.discard,
                                    action)
        elif action == 'G':
            if self.player_2._godspell == 1:
                op_index = int(
                    input('Please mention which card opponent should play ?'))
                index = int(
                    input('Please mention which card you want to play ?'))
                self.player_2.hand.print_card(index)
                print(
                    "Choose Action: (S = Strength, K = skill, I = size, R=Resurrect)"
                )
                characteristics = input('please enter')
                self.player_2.play_card(index, op_index, self.player_1,
                                        self.discard, characteristics)
                self.player_2._godspell = 0
            elif self.player_2._godspell > 1 or self.player_2._godspell < 1:
                print('You already played God spell or wrong selection')

        elif action == 'R':
            if self.player_2._resurrectspell == 1:
                player_resurrect = random.randint(1, self.discard.size() - 1)
                card = self.discard.pop(player_resurrect)
                self.player_2.hand.push(card)
                self.player_2._resurrectspell = 0
                self.player_2_turn()
                # self.player_1.play_card(-1,-1, self.player_2, self.discard)

            else:
                print('You already played Resurrect spell or wrong selection')
            return True
        return False

    def check_winner(self):
        """
        Check whether there is a winner, based on players' health, strength
        and on central deck's size.

        :return winner: True if a winner has been found
        """
        winner = False
        if self.deck.size() == 0:
            print("No more cards available")
            if self.player_1.point > self.player_2.point:
                winner = True
                print("Player One Wins")
            elif self.player_1.point == self.player_2.point:
                winner = True
                print("Draw")
            elif self.player_1.point < self.player_2.point:
                winner = True
                print("Computer Wins")

            winner = True
        return winner