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
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)
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
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)
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
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)
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
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
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)
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})
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()
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
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}
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)
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']
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)
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)