Example #1
0
def __main__():
    """
    For prototyping purposes only. Will be used to model the final game loop.
    The basic structure of the game loop.
    :return: None
    """
    # ask for dims
    game_dims = get_dims()
    player_name = get_player_name()
    # Create the player object
    player = Player(player_name, game_dims)
    ships = get_ships()  # Get description of the fleet

    for ship in ships:
        player.add_my_ship(ship)

    # transmit boat types to opponent
    send_ship_types(ships)
    # get enemy's boat types
    opp_ship_types = get_ship_types()
    print("Here are opp's ship_types:", opp_ship_types)

    game_on = True

    while game_on:
        change_turn = False
        while not change_turn:
            change_turn, game_on = your_move(player)  # Play a move

        change_turn = False
        while game_on and not change_turn:
            change_turn, game_on = opp_move(player)  # Respond to enemy's move
Example #2
0
def get_players():
    players = []
    players_fetchall = db.get_players(
    )  # call method to get a list with all players from database
    for row in players_fetchall:
        # username, firstname, lastname, gender, wins, defeats
        players.append(Player(row[0], row[1], row[2], row[3], row[4]))

    return players
Example #3
0
    def setUp(self):
        cardsHandOne = [None] * 9
        cardsHandTwo = [None] * 9

        for i in range(0, 9):
            cardHandOne = Card("Card no %d" % i, "Card for hand one",
                               "http://and.a.link/", random.randint(6, 9),
                               random.randint(2, 3), random.randint(3, 7))
            cardHandTwo = Card("Card no %d" % i, "Card for hand one",
                               "http://and.a.link/", random.randint(4, 7),
                               random.randint(3, 5), random.randint(3, 7))

            cardsHandOne[i] = cardHandOne
            cardsHandTwo[i] = cardHandTwo

        self.__cardsHandOne = Deck(deck=cardsHandOne)
        self.__cardsHandTwo = Deck(deck=cardsHandTwo)

        self.__handOne = Player(name="Player one",
                                deck=Deck(deck=cardsHandOne))
        self.__handTwo = Player(name="Player two",
                                deck=Deck(deck=cardsHandTwo))
Example #4
0
async def hunt(ctx):

    # get user ID
    newUserID = ctx.author.id
    # get player object associated with ID
    player_object = Player.get_player(newUserID)

    Fight_Controller.create_hunt(newUserID)

    # create enemy
    new_enemy = Enemy()
    # create fight
    # announce winner
    # distribute spoils if any

    pass
Example #5
0
# Sound
# mixer.music.load("background.wav")
# mixer.music.play(-1)

# Caption and Icon
pygame.display.set_caption("Fabula")
icon = pygame.image.load('Assets/icon.png')
pygame.display.set_icon(icon)

# FPS
font = pygame.font.Font('freesansbold.ttf', 32)

field = Field.Field(20, 20)

player = Player.Player(int(screen_width / 2), int(screen_height / 2))

fps_value = 0
last_time = time.time()
running = True
while running:
    clock.tick(10)
    # RGB = Red, Green, Blue
    screen.fill((49, 142, 70))
    # Background Image
    # screen.blit(background, (0, 0))
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
    if event.type == pygame.KEYDOWN:
        if event.key == pygame.K_LEFT:
Example #6
0
class TestPlayer(unittest.TestCase):

    __handOne = None
    __handTwo = None
    __cardsHandOne = None
    __cardsHandTwo = None

    def setUp(self):
        cardsHandOne = [None] * 9
        cardsHandTwo = [None] * 9

        for i in range(0, 9):
            cardHandOne = Card("Card no %d" % i, "Card for hand one",
                               "http://and.a.link/", random.randint(6, 9),
                               random.randint(2, 3), random.randint(3, 7))
            cardHandTwo = Card("Card no %d" % i, "Card for hand one",
                               "http://and.a.link/", random.randint(4, 7),
                               random.randint(3, 5), random.randint(3, 7))

            cardsHandOne[i] = cardHandOne
            cardsHandTwo[i] = cardHandTwo

        self.__cardsHandOne = Deck(deck=cardsHandOne)
        self.__cardsHandTwo = Deck(deck=cardsHandTwo)

        self.__handOne = Player(name="Player one",
                                deck=Deck(deck=cardsHandOne))
        self.__handTwo = Player(name="Player two",
                                deck=Deck(deck=cardsHandTwo))

    def tearDown(self):
        self.__handOne = None
        self.__handTwo = None

    def testVisibleCards(self):
        visibleCards = []

        for i in range(0, 3):
            self.__handOne.DrawCard()
            self.__handOne.EndTurn()
            self.__handOne.PutCard(self.__handOne.hand[0])
            visibleCards.append(self.__cardsHandOne.DrawCard())

            self.__handOne.EndTurn()
            self.__handTwo.EndTurn()

        expected = len(visibleCards)
        actual = len(self.__handOne.VisibleCards)

        self.assertEqual(expected, actual, "Visible card count is incorrect")

        for i in range(0, 1):
            message = "Card %d is incorrect." % i
            self.assertEquals(visibleCards[i], self.__handOne.VisibleCards[i],
                              message)

    def testPutCard(self):
        self.__handOne.DrawCard()
        self.__handOne.EndTurn()
        self.__handOne.PutCard(self.__handOne.hand[0])
        card = self.__handOne.VisibleCards[0]

        self.assertNotEquals(None, card, "PutCard() returns none")

        self.assertEquals(self.__cardsHandOne.DrawCard(), card,
                          "PutCard did not take first card in deck")

    def testActionPoints(self):
        expectedStart = Player.MAX_ACTION_POINTS
        expectedAfterPutCard = expectedStart - Player.CARD_COST

        self.assertEqual(expectedStart, self.__handOne.ActionPoints,
                         "Not correct number of ActionPoints at start")

        self.__handOne.DrawCard()

        self.assertEqual(expectedAfterPutCard, self.__handOne.ActionPoints,
                         "Not correct number of ActionPoints after PutCard")

        self.__handOne.EndTurn()

        self.assertEqual(expectedStart, self.__handOne.ActionPoints,
                         "ActionPoints not reset after end of turn")

    def testCardsLeft(self):
        expected = 9

        self.assertEqual(expected, self.__handOne.CardsLeft,
                         "Number of cards left not displayed correct")

        expected = 7

        self.__handOne.DrawCard()
        self.__handOne.EndTurn()

        self.__handOne.PutCard(self.__handOne.hand[0])
        self.__handOne.EndTurn()
        self.__handOne.DrawCard()
        self.__handOne.EndTurn()
        self.__handOne.PutCard(self.__handOne.hand[0])

        self.assertEqual(expected, self.__handOne.CardsLeft,
                         "Number of cards left not decreased correct")

    def testBattleSequence(self):
        expected = None

        self.__handOne.DrawCard()
        self.__handOne.EndTurn()
        self.__handOne.PutCard(self.__handOne.hand[0])
        self.__handOne.EndTurn()

        self.__handTwo.DrawCard()
        self.__handTwo.EndTurn()
        self.__handTwo.PutCard(self.__handTwo.hand[0])
        self.__handTwo.EndTurn()

        if self.__handOne.VisibleCards[0].AP > self.__handTwo.VisibleCards[
                0].DP:
            expected = self.__handOne.VisibleCards[0]
        else:
            expected = self.__handTwo.VisibleCards[0]

        actual = self.__handOne.Attack(self.__handTwo.VisibleCards[0],
                                       self.__handOne.VisibleCards[0])

        self.assertEquals(expected, actual, "Wrong winner on Player.Attack")

        try:
            self.__handOne.Attack(self.__handOne.VisibleCards[0],
                                  self.__handTwo.VisibleCards[0])
            self.fail("Attack with opponents card possible")
        except Exception, e:
            if isinstance(e, IncorrectAttackerError):
                self.__handOne.Attack(self.__handTwo.VisibleCards[0],
                                      self.__handOne.VisibleCards[0])
                self.__handOne.Attack(self.__handTwo.VisibleCards[0],
                                      self.__handOne.VisibleCards[0])

                try:
                    self.__handOne.Attack(self.__handTwo.VisibleCards[0],
                                          self.__handOne.VisibleCards[0])
                    self.fail("More attacks than AP allow possible")
                except Exception, e2:
                    if isinstance(e2, OutOfMovesError):
                        pass
                    else:
                        self.fail("Not correct error (OutOfMovesError)")

            else:
Example #7
0
 def set_data_player(self, player_type, name, params, train_program):
     self.player = Player(type=player_type,
                          full_name=name,
                          indicators=params,
                          last_train=train_program)