예제 #1
0
def get_hands():
    unavailable_cards = []
    hands = {}

    for player_i in range(basic_utils.ask_int("How many human players?\n")):

        hand = request_cards(str(player_i + 1))
        hands["p" + str(player_i)] = hand
        unavailable_cards += hand

    missing_card = select_card(excluded=unavailable_cards)
    hands["missing"] = missing_card
    unavailable_cards.append(missing_card)

    comp_card_amount = basic_utils.ask_int("How many cards for the computer?\n")
    hands["comp"] = select_cards(comp_card_amount, unavailable_cards)

    hands["extra"] = []
    for _ in range(36 - len(unavailable_cards)):
        card = select_card(excluded=unavailable_cards)
        hands["extra"].append(card)
        unavailable_cards.append(card)

    save_cards(hands)

    basic_utils.clear_screen()
    return hands
 def test_clear_screen(self):
     """ Tests that the right amount of new lines were printed, including the last
     one added automatically by python"""
     expected = "\n" * 81
     with pcutils.MockPrint() as mocked_print:
         basic_utils.clear_screen()
         print_output = mocked_print.stdout
     self.assertEqual(expected, print_output)
예제 #3
0
def answer(action, comp_cards, missing_card):
    search_code = action[1]
    if not is_valid_search_code(search_code):
        print("An invalid search code was entered!!")
        return

    if len(search_code) == 1:
        show_amount(search_code, comp_cards)
        pause()
    elif len(search_code) == 2:
        show_cards(search_code, comp_cards)
        basic_utils.clear_screen()
    elif len(search_code) == 3:
        show_three_elements(search_code, comp_cards)
        guess(missing_card)
        basic_utils.clear_screen()
예제 #4
0
def request_cards(player):
    cards = []
    basic_utils.clear_screen()
    print("Player " + player + " - Pick your cards:\n\n")

    while True:
        print(CARD_HELP)
        print("You have entered " + str(len(cards)) + " cards.")
        card = input("Enter a card - enter 'done' when finished:\n")
        if is_valid_card(card):
            cards.append(card)
        elif card.lower() == "done":
            break
        else:
            print("An invalid card was entered!")

    print("\n\n\nYou have entered the following cards:")
    print("\n".join(list_of_codes_to_names(cards)))
    answer = input("\nAre you sure these are your cards? If so, enter 'done'\n")
    if answer.lower() == "done":
        return cards
    else:
        return request_cards(player)