Esempio n. 1
0
def cards_indexes(columns):
    """zwraca listę ze wszystkimi indeksami kart"""
    indexes = []
    board_rows = helper.calc_board_rows(
        unique_divisors) * helper.calc_board_columns(unique_divisors)
    for i in range(board_rows):
        indexes.append(divmod(i, columns))
    return indexes
Esempio n. 2
0
def run_board_default():
    """Zwraca planaszę, gotową do gry, karty zakryte, ułożone losowo"""
    columns = helper.calc_board_columns(unique_divisors)
    rows = helper.calc_board_rows(unique_divisors)
    board = make_empty_board(rows, columns)
    indexes = cards_indexes(columns)
    random_indexes = random_cards_indexes(indexes)
    cards = create_cards()
    return make_game_board(board, random_indexes, cards)
Esempio n. 3
0
def make_test_board():
    card_list = get_cards()
    cards = create_cards()
    all_divisors = calc_all_divisors(card_list)
    unique_divisors = calc_pair_divisors(all_divisors)
    columns = calc_board_columns(unique_divisors)
    rows = calc_board_rows(unique_divisors)
    indexes = cards_indexes(columns)
    board = make_empty_board(rows, columns)
    make_game_board(board, indexes, cards)
    return board
Esempio n. 4
0
 def test_click_same_pair(self):
     card_list = get_cards()
     all_divisors = calc_all_divisors(card_list)
     unique_divisors = calc_pair_divisors(all_divisors)
     columns = calc_board_columns(unique_divisors)
     rows = calc_board_rows(unique_divisors)
     board = make_test_board()
     game = create_game(board)
     on_card_clicked(game, board, columns, rows, row=1, col=1)
     self.assertEqual(count_showed_cards(game), 1)
     on_card_clicked(game, board, columns, rows, row=1, col=1)
     self.assertEqual(count_showed_cards(game), 1)
Esempio n. 5
0
def test_click_same_pair():
    """test sprawdza ile kart będzie odkrytych jeżeli gracz spróbuje odsłonić tą samą kartę"""
    card_list = get_cards()
    all_divisors = calc_all_divisors(card_list)
    unique_divisors = calc_pair_divisors(all_divisors)
    columns = calc_board_columns(unique_divisors)
    rows = calc_board_rows(unique_divisors)
    board = make_test_board()
    game = create_game(board)
    on_card_clicked(game, board, columns, rows, row=1, col=1)
    assert count_showed_cards(game) == 1
    on_card_clicked(game, board, columns, rows, row=1, col=1)
    assert count_showed_cards(game) == 1
Esempio n. 6
0
 def test_check_attempts_amount(self):
     card_list = get_cards()
     all_divisors = calc_all_divisors(card_list)
     unique_divisors = calc_pair_divisors(all_divisors)
     columns = calc_board_columns(unique_divisors)
     rows = calc_board_rows(unique_divisors)
     board = make_test_board()
     game = create_game(board)
     on_card_clicked(game, board, columns, rows, row=0, col=0)
     on_card_clicked(game, board, columns, rows, row=1, col=2)
     self.assertEqual(game['attempts'], 1)
     on_card_clicked(game, board, columns, rows, row=1, col=2)
     self.assertEqual(game['attempts'], 1)
     on_card_clicked(game, board, columns, rows, row=1, col=0)
     self.assertEqual(game['attempts'], 1)
     on_card_clicked(game, board, columns, rows, row=1, col=3)
     self.assertEqual(game['attempts'], 2)
Esempio n. 7
0
def test_click_good_pair():
    """test sprawdza czy będą widoczne dwie poprawnie odsłonięte karty"""
    card_list = get_cards()
    all_divisors = calc_all_divisors(card_list)
    unique_divisors = calc_pair_divisors(all_divisors)
    columns = calc_board_columns(unique_divisors)
    rows = calc_board_rows(unique_divisors)
    board = make_test_board()
    game = create_game(board)
    on_card_clicked(game, board, columns, rows, row=1, col=1)
    assert count_showed_cards(game) == 1
    on_card_clicked(game, board, columns, rows, row=2, col=3)
    assert count_showed_cards(game) == 2
    on_card_clicked(game, board, columns, rows, row=0, col=0)
    assert count_showed_cards(game) == 3
    on_card_clicked(game, board, columns, rows, row=1, col=2)
    assert count_showed_cards(game) == 4
Esempio n. 8
0
def test_check_attempts_amount():
    """test sprawdza czy poprawnie nalicza się ilość prób"""
    card_list = get_cards()
    all_divisors = calc_all_divisors(card_list)
    unique_divisors = calc_pair_divisors(all_divisors)
    columns = calc_board_columns(unique_divisors)
    rows = calc_board_rows(unique_divisors)
    board = make_test_board()
    game = create_game(board)
    on_card_clicked(game, board, columns, rows, row=0, col=0)
    on_card_clicked(game, board, columns, rows, row=1, col=2)
    assert game['attempts'] == 1
    on_card_clicked(game, board, columns, rows, row=1, col=2)
    assert game['attempts'] == 1
    on_card_clicked(game, board, columns, rows, row=1, col=0)
    assert game['attempts'] == 1
    on_card_clicked(game, board, columns, rows, row=1, col=3)
    assert game['attempts'] == 2
Esempio n. 9
0
 def test_if_game_is_finished(self):
     card_list = get_cards()
     all_divisors = calc_all_divisors(card_list)
     unique_divisors = calc_pair_divisors(all_divisors)
     columns = calc_board_columns(unique_divisors)
     rows = calc_board_rows(unique_divisors)
     board = make_test_board()
     game = create_game(board)
     on_card_clicked(game, board, columns, rows, row=0, col=0)
     on_card_clicked(game, board, columns, rows, row=1, col=2)
     on_card_clicked(game, board, columns, rows, row=0, col=1)
     on_card_clicked(game, board, columns, rows, row=1, col=3)
     on_card_clicked(game, board, columns, rows, row=0, col=2)
     on_card_clicked(game, board, columns, rows, row=2, col=0)
     on_card_clicked(game, board, columns, rows, row=0, col=3)
     on_card_clicked(game, board, columns, rows, row=2, col=1)
     on_card_clicked(game, board, columns, rows, row=1, col=0)
     on_card_clicked(game, board, columns, rows, row=2, col=2)
     on_card_clicked(game, board, columns, rows, row=1, col=1)
     on_card_clicked(game, board, columns, rows, row=2, col=3)
     self.assertTrue(all_card_showed(game, columns, rows), True)
Esempio n. 10
0
 def test_which_card_showed(self):
     card_list = get_cards()
     all_divisors = calc_all_divisors(card_list)
     unique_divisors = calc_pair_divisors(all_divisors)
     columns = calc_board_columns(unique_divisors)
     rows = calc_board_rows(unique_divisors)
     board = make_test_board()
     game = create_game(board)
     on_card_clicked(game, board, columns, rows, row=1, col=3)
     on_card_clicked(game, board, columns, rows, row=0, col=3)
     self.assertEqual(board[1][3], {'value': 1, 'showed': True})
     self.assertEqual(board[0][3], {'value': 3, 'showed': True})
     on_card_clicked(game, board, columns, rows, row=0, col=0)
     self.assertEqual(board[1][3], {'value': 1, 'showed': False})
     self.assertEqual(board[0][3], {'value': 3, 'showed': False})
     self.assertEqual(board[0][0], {'value': 0, 'showed': True})
     on_card_clicked(game, board, columns, rows, row=1, col=2)
     on_card_clicked(game, board, columns, rows, row=2, col=2)
     self.assertEqual(board[0][0], {'value': 0, 'showed': True})
     self.assertEqual(board[1][2], {'value': 0, 'showed': True})
     self.assertEqual(board[2][2], {'value': 4, 'showed': True})
Esempio n. 11
0
def run_game(resources, images_res):
    pg.display.set_caption("Memory game")
    game_display = pg.display.set_mode((display_width, display_height))
    all_divisors = helper.calc_all_divisors(card_list)
    unique_divisors = helper.calc_pair_divisors(all_divisors)
    columns = helper.calc_board_columns(unique_divisors)
    rows = helper.calc_board_rows(unique_divisors)
    board = engine.run_board_default()
    clock = pg.time.Clock()
    game = engine.create_game(board)
    board_view = make_board_view(board, display_size, images_res)
    input_data = {'exit': False}

    while not input_data['exit']:
        input_data = process_events(game)
        if GAME_OVER == update_game(game, board, input_data, columns, rows, resources):
            time.sleep(1)
            break
        render_game(board_view, game_display, resources, game, board)
        clock.tick(FPS)

    pg.display.quit()
Esempio n. 12
0
def test_if_game_is_finished():
    """test sprawdza czy po odklikaniu wszystkich par, wszystkie karty są odsłonięte"""
    card_list = get_cards()
    all_divisors = calc_all_divisors(card_list)
    unique_divisors = calc_pair_divisors(all_divisors)
    columns = calc_board_columns(unique_divisors)
    rows = calc_board_rows(unique_divisors)
    board = make_test_board()
    game = create_game(board)
    on_card_clicked(game, board, columns, rows, row=0, col=0)
    on_card_clicked(game, board, columns, rows, row=1, col=2)
    on_card_clicked(game, board, columns, rows, row=0, col=1)
    on_card_clicked(game, board, columns, rows, row=1, col=3)
    on_card_clicked(game, board, columns, rows, row=0, col=2)
    on_card_clicked(game, board, columns, rows, row=2, col=0)
    on_card_clicked(game, board, columns, rows, row=0, col=3)
    on_card_clicked(game, board, columns, rows, row=2, col=1)
    on_card_clicked(game, board, columns, rows, row=1, col=0)
    on_card_clicked(game, board, columns, rows, row=2, col=2)
    on_card_clicked(game, board, columns, rows, row=1, col=1)
    on_card_clicked(game, board, columns, rows, row=2, col=3)
    assert all_card_showed(game, columns, rows) == True
Esempio n. 13
0
def test_which_card_showed():
    """test sprawdza czy następuje zakrywanie/odkrywanie wybranych kart"""
    card_list = get_cards()
    all_divisors = calc_all_divisors(card_list)
    unique_divisors = calc_pair_divisors(all_divisors)
    columns = calc_board_columns(unique_divisors)
    rows = calc_board_rows(unique_divisors)
    board = make_test_board()
    game = create_game(board)
    on_card_clicked(game, board, columns, rows, row=1, col=3)
    on_card_clicked(game, board, columns, rows, row=0, col=3)
    assert board[1][3] == {'value': 1, 'showed': True}
    assert board[0][3] == {'value': 3, 'showed': True}
    on_card_clicked(game, board, columns, rows, row=0, col=0)
    assert board[1][3] == {'value': 1, 'showed': False}
    assert board[0][3] == {'value': 3, 'showed': False}
    assert board[0][0] == {'value': 0, 'showed': True}
    on_card_clicked(game, board, columns, rows, row=1, col=2)
    on_card_clicked(game, board, columns, rows, row=2, col=2)
    assert board[0][0] == {'value': 0, 'showed': True}
    assert board[1][2] == {'value': 0, 'showed': True}
    assert board[2][2] == {'value': 4, 'showed': True}
Esempio n. 14
0
 def test_time_measure(self):
     card_list = get_cards()
     all_divisors = calc_all_divisors(card_list)
     unique_divisors = calc_pair_divisors(all_divisors)
     columns = calc_board_columns(unique_divisors)
     rows = calc_board_rows(unique_divisors)
     board = make_test_board()
     game = create_game(board)
     on_card_clicked(game, board, columns, rows, row=0, col=0)
     time.sleep(2)
     on_card_clicked(game, board, columns, rows, row=1, col=2)
     on_card_clicked(game, board, columns, rows, row=0, col=1)
     on_card_clicked(game, board, columns, rows, row=1, col=3)
     on_card_clicked(game, board, columns, rows, row=0, col=2)
     on_card_clicked(game, board, columns, rows, row=2, col=0)
     on_card_clicked(game, board, columns, rows, row=0, col=3)
     on_card_clicked(game, board, columns, rows, row=2, col=1)
     on_card_clicked(game, board, columns, rows, row=1, col=0)
     on_card_clicked(game, board, columns, rows, row=2, col=2)
     on_card_clicked(game, board, columns, rows, row=1, col=1)
     self.assertEqual(game['finish_at'], None)
     on_card_clicked(game, board, columns, rows, row=2, col=3)
     self.assertTrue(game['started_at'] < game['finish_at'], True)
Esempio n. 15
0
def test_time_measure():
    """test sprawdza czy dobrze jest liczony czas od startu do zakończenia gry"""
    card_list = get_cards()
    all_divisors = calc_all_divisors(card_list)
    unique_divisors = calc_pair_divisors(all_divisors)
    columns = calc_board_columns(unique_divisors)
    rows = calc_board_rows(unique_divisors)
    board = make_test_board()
    game = create_game(board)
    on_card_clicked(game, board, columns, rows, row=0, col=0)
    time.sleep(2)
    on_card_clicked(game, board, columns, rows, row=1, col=2)
    on_card_clicked(game, board, columns, rows, row=0, col=1)
    on_card_clicked(game, board, columns, rows, row=1, col=3)
    on_card_clicked(game, board, columns, rows, row=0, col=2)
    on_card_clicked(game, board, columns, rows, row=2, col=0)
    on_card_clicked(game, board, columns, rows, row=0, col=3)
    on_card_clicked(game, board, columns, rows, row=2, col=1)
    on_card_clicked(game, board, columns, rows, row=1, col=0)
    on_card_clicked(game, board, columns, rows, row=2, col=2)
    on_card_clicked(game, board, columns, rows, row=1, col=1)
    assert game['finish_at'] == None
    on_card_clicked(game, board, columns, rows, row=2, col=3)
    assert game['started_at'] < game['finish_at']
Esempio n. 16
0
 def test_calc_board_rows(self):
     card_list = get_cards()
     all_divisors = calc_all_divisors(card_list)
     unique_divisors = calc_pair_divisors(all_divisors)
     self.assertEqual(calc_board_columns(unique_divisors) * calc_board_rows(unique_divisors), len(card_list) * 2)
Esempio n. 17
0
def test_calc_board_rows():
    card_list = get_cards()
    all_divisors = calc_all_divisors(card_list)
    unique_divisors = calc_pair_divisors(all_divisors)
    assert (calc_board_columns(unique_divisors) * calc_board_rows(unique_divisors) == len(card_list)*2)