Esempio n. 1
0
def test_play():
    """Test play"""

    assert play({'word': 'banana', 'inputs': list('abn')}) == True
    assert play({'word': 'banana', 'inputs': list('abcdefghijklm')}) == False
    assert play({'word': 'banana', 'inputs': list('???')}) == True
    assert play({'word': 'banana', 'inputs': list('!')}) == False
Esempio n. 2
0
def choose_game():
    print("We have these games!")
    print("(1) Guessing game (2) Hangman")

    game = int(input("What game do you wanna play?"))

    if game == 1:
        print("Good luck on te guessing game!")
        guessingGame.play()

    elif game == 2:
        print("Good luck on hangman game!")
        hangman.play()
Esempio n. 3
0
def main():
    header.define("Welcome!")

    print("(1) - Guessing")
    print("(2) - Hangman")

    game = int(input(">> Choose your game: "))

    if game == 1:
        Guessing()
    elif game == 2:
        hangman.play()
    else:
        print("Game {} is not present".format(game))
Esempio n. 4
0
def play():
    print("***********************")
    print("***  Choose a game  ***")
    print("***                 ***")
    print("***  (H)angman      ***")
    print("***  (G)uess number ***")
    print("***                 ***")
    print("***********************")

    option = input(": ")
    if option == 'H':
        guess_number.play()
    elif option == 'G':
        hangman.play()
Esempio n. 5
0
def choose_game():

    print('*****************************')
    print('********Choose game!*********')
    print('*****************************')

    print('(1) Hangman (2) Guessing')

    game = int(input('What game do you want to play?: '))

    if game == 1:
        hangman.play()
    elif game == 2:
        guessing.play()
def play_again():
    print('  _____')
    print('  |   |')
    print('      |')
    print('  O   |')
    print('  |/  |')
    print(' /|   |')
    print(' / \__|\n')
    answer = input('Great job!! Would you like to play again? (y/n)')
    if answer.lower().strip() == 'y':
        hangman.play()
    else:
        print('Thank you for playing! See you again soon!')
        exit()
Esempio n. 7
0
def choose_game():
    print("**********************************************************")
    print("          ", "Welcome, choose your game!")
    print("**********************************************************")

    print("(1) Forca (2) Adivinhação")

    game = int(input("Qual jogo? "))

    if (game == 1):
        print("Jogando forca")
        hangman.play()
    elif (game == 2):
        print("Jogando adivinhação")
        divination.play()
Esempio n. 8
0
def select_game():
    print("*********************************")
    print("Escolha o seu jogo")
    print("*********************************")

    jogo = int(input("(1) Forca (2) Adivinhação\nQual jogo?\nR: "))
    while (jogo < 1 or jogo > 2):
        jogo = int(
            input(
                "\n(1) Forca (2) Adivinhação\nVocê deve escolher 1 ou 2.\nR: ")
        )
    if (jogo == 1):
        hangman.play()
    else:
        guessing.play()
Esempio n. 9
0
def escolhe_jogo():
    print("*********************************")
    print("******* Choose your game! *******")
    print("*********************************")

    print("(1) Hangman (2) Guess the Number")

    jogo = int(input("Which game you want to play? "))

    if (jogo == 1):
        print("Playing Hangman!")
        hangman.play()

    elif (jogo == 2):
        print("Playing Guess the Number!")
        guess_number.play()
def test_same_guess_letter():
    secret_word = "elephant"
    wrong_word = ""
    list_guess = ["e"]
    guess = "e"
    assert play(secret_word, wrong_word, list_guess,
                guess) == ['Already guessed', '']
def test_letters_guess_digit():
    secret_word = "elephant"
    wrong_word = ""
    list_guess = []
    guess = "1"
    assert play(secret_word, wrong_word, list_guess,
                guess) == ['invalid option', '']
Esempio n. 12
0
def select_game():
    print("****************************")
    print("*Welcome to Nostalgic Game!*")
    print("****************************")

    print("(1) Guessing game, (2) Hangman")

    game = int(input("Select a game to play: "))

    if (1 == game):
        print("Guessing game selected")
        guessing_game.play()
    elif (2 == game):
        print("Hangman game selected")
        hangman.play()
    else:
        print("Invalid game")
def test_guess_two_letter():
    secret_word = "elephant"
    wrong_word = ""
    list_guess = []
    guess = "el"
    print(guess)
    assert play(secret_word, wrong_word, list_guess,
                guess) == ['invalid option', '']
Esempio n. 14
0
def menu():
    print('+++++++++++++++++++++++++++++')
    print('          Py Games!          ')
    print('+++++++++++++++++++++++++++++')
    print(' ')
    print('(1) Hangman (2) Guessing Game')
    game = int(input('What game do you choose? '))

    while (game < 1 or game > 2):
        game = int(
            input('I can find this game....could you try a valid option? '))

    if (game == 1):
        hangman.play()

    elif (game == 2):
        guessing_game.play()
def test_correct_guess_letter():
    secret_word = "elephant"
    wrong_word = ""
    list_guess = []
    guess = ["t"]
    assert play(secret_word, wrong_word, list_guess, guess) == [
        '    Word :-------t    turn left :4', [], ['t'], ''
    ]
Esempio n. 16
0
def test_play_repeat_input_correct():
    cg, wg, turns_left, game_over, final_message = hangman.play(sw = 'dog',
                                                                cg = ['d','o'],
                                                                wg = ['x'],
                                                                new_guess = 'd',
                                                                turns_left = 1)
    assert cg == ['d', 'o']
    assert wg == ['x']
    assert turns_left == 1
    assert game_over == False
Esempio n. 17
0
def test_play_wrong_input_lose():
    cg, wg, turns_left, game_over, final_message = hangman.play(sw = 'dog',
                                                                cg = ['d', 'o'],
                                                                wg = ['x','l','z','p'],
                                                                new_guess = 'a',
                                                                turns_left = 1)
    assert cg == ['d', 'o']
    assert wg == ['x','l','z','p','a']
    assert turns_left == 0
    assert game_over == True
    assert final_message == "You lost! The word was 'dog'."
Esempio n. 18
0
def test_play_wrong_input_normal_turn():

    cg, wg, turns_left, game_over, final_message = hangman.play(sw = 'dog',
                                                                cg = ['d', 'o'],
                                                                wg = ['x', 'l'],
                                                                new_guess = 'l',
                                                                turns_left = 3)
    assert cg == ['d', 'o']
    assert wg == ['x', 'l']
    assert turns_left == 3
    assert game_over == False
Esempio n. 19
0
def test_play_correct_input_normal_turn():
    #cg = ['e']
    #wg = ['x']
    cg, wg, turns_left, game_over, final_message = hangman.play(sw = 'elephant',
                                                                cg = ['e'],
                                                                wg = ['x'],
                                                                new_guess = 'l',
                                                                turns_left = 4)
    assert cg == ['e', 'l']
    assert wg == ['x']
    assert turns_left == 4
    assert game_over == False
Esempio n. 20
0
def test_play_correct_input_win_turn():
    #cg = ['d']
    #wg = ['x']
    cg, wg, turns_left, game_over, final_message = hangman.play(sw = 'dog',
                                                                cg = ['d', 'o'],
                                                                wg = ['x'],
                                                                new_guess = 'g',
                                                                turns_left = 4)
    assert cg == ['d', 'o', 'g']
    assert wg == ['x']
    assert turns_left == 4
    assert game_over == True
    assert final_message == "You win!"
def test_winner():
    secret_word = "elephant"
    wrong_word = ""
    list_guess = [
        "e",
        "l",
        "p",
        "h",
        "n",
        "a",
    ]
    guess = "t"
    assert play(secret_word, wrong_word, list_guess,
                guess) == ['You win', "a"
                           "b"
                           "x"
                           "z"]
Esempio n. 22
0
    else:
        scorer = build_multiplier_scorer(known_multiplier=1.0, missed_multiplier=1.0)

    if args.entropy_scorer:
        entropy_scorer_type, known_multiplier, missed_multiplier = args.entropy_scorer.split(':')
        assert entropy_scorer_type == 'multiplier'
        entropy_scorer = build_multiplier_scorer(float(known_multiplier), float(missed_multiplier))
    else:
        entropy_scorer = scorer
    scores = []
    guess_counts = []

    print args.limit, args.strategy
    for word in words_to_play:

        game = hangman.play(word.strip())
        for mystery_string in game:
            key = get_cache_key(mystery_string, mystery_string.missed_letters)
            next_guess = cached_guesses.get(key, None)
            if not next_guess:
                rejected_letters = mystery_string.missed_letters
                remaining_words = dictionary.filter_words(encoded_dictionary, mystery_string, rejected_letters)
                next_guess = get_next_guess(mystery_string, remaining_words, args.strategy, entropy_scorer)
                cached_guesses[key] = next_guess
            try:
                game.send(next_guess)
            except StopIteration:
                pass
        result = hangman.MysteryString(word, (set(mystery_string.guesses) | set([next_guess])))
        assert word == str(result)
Esempio n. 23
0
import hangman
import advinhador

print("#" * 30)
print("Welcome to Alura Games")
print("#" * 30)

print("\n")
print("Choose the Game you want to play:")

print("\n")
print("(1) Guessing")
print("(2) Hangman")

choosen_game = int(input("Wich game? "))

print("\1n")
if (choosen_game == 1):

    print("Let's play Guessing!")
    advinhador.play()
elif (choosen_game == 2):
    print("Let's play Hangman!")
    hangman.play()
Esempio n. 24
0
def playGame():
    # board initialization
    board = getBlank()
    score = 0
    level = 1
    totalScore = 0 # internal, used to keep track of score for entire game
    fillAndAnimate(board, [], score)

    # start of game initialization
    gameOver = False
    continueTextSurf = None
    gameOverTextSurf = None
    firstGemPick = None
    lastMouseDownY = None
    lastMouseDownX = None

    # display the directions
    welcomeTextSurf = None
    welcomeTextSurf = FONT.render('Welcome to Gems! Match gems in groups of 3 or more to earn at least 70 points and advance!', 1, OVERCOLOR, OVERBACKCOLOR)
    welcomeTextRect = welcomeTextSurf.get_rect()
    welcomeTextRect.center = int(WINDOWWIDTH / 2), int(WINDOWHEIGHT / 2)
    DISPLAY.blit(welcomeTextSurf, welcomeTextRect)
    pygame.display.update()  # update the display
    pygame.time.delay(10000) # give them time to read the directions

    # main loop for the game
    while True:
        chosenBox = None
        for event in pygame.event.get():
            # handle exiting the game
            if event.type == QUIT or (event.type == KEYUP and event.key == K_ESCAPE):
                pygame.quit()
                sys.exit()
            elif event.type == KEYUP and event.key == K_BACKSPACE:
                return # begin new game
            elif event.type == MOUSEBUTTONUP:
                if gameOver:
                    return
                if event.pos == (lastMouseDownX, lastMouseDownY):
                    chosenBox = checkForClick(event.pos)
                else:
                    firstGemPick = checkForClick((lastMouseDownX, lastMouseDownY))
                    chosenBox    = checkForClick(event.pos)
                    if not firstGemPick or not chosenBox:
                        # invalid drag, deselect both
                        firstGemPick = None
                        chosenBox = None
            elif event.type == MOUSEBUTTONDOWN:
                # start of mouse click or drag
                lastMouseDownX, lastMouseDownY = event.pos

        if chosenBox and not firstGemPick:
            # was first gem clicked on
            firstGemPick = chosenBox
        elif chosenBox and firstGemPick:
            # two gems clicked, swap them
            firstSwapGem, secondSwapGem = getSwap(board, firstGemPick, chosenBox)
            if firstSwapGem == None and secondSwapGem == None:
                # gems weren't adjacent- no swap
                firstGemPick = None  # deselect
                continue

            # show swap animation
            boardCopy = getBoardCopyNoGems(board, (firstSwapGem, secondSwapGem))
            animateMove(boardCopy, [firstSwapGem, secondSwapGem], [], score)

            # swap gems in board structure
            board[firstSwapGem['x']][firstSwapGem['y']] = secondSwapGem['imageNum']
            board[secondSwapGem['x']][secondSwapGem['y']] = firstSwapGem['imageNum']

            # see if it was matching
            matchedGems = findMatches(board)
            if matchedGems == []:
                # was an invalid match, swap back
                animateMove(boardCopy, [firstSwapGem, secondSwapGem], [], score)
                board[firstSwapGem['x']][firstSwapGem['y']] = firstSwapGem['imageNum']
                board[secondSwapGem['x']][secondSwapGem['y']] = secondSwapGem['imageNum']
            else:
                # matching move
                addPoints = 0
                while matchedGems != []:
                    # remove matched gems, pull board down

                    points = []
                    for gemSet in matchedGems:
                        addPoints += (10 + (len(gemSet) - 3) * 10)
                        for gem in gemSet:
                            board[gem[0]][gem[1]] = EMPTY_BOX
                        points.append({'points': addPoints,
                                       'x': gem[0] * GEMBOX + XEDGE,
                                       'y': gem[1] * GEMBOX + YEDGE})
                    score += addPoints

                    # drop new gems
                    fillAndAnimate(board, points, score)

                    # check for new matches
                    matchedGems = findMatches(board)
            firstGemPick = None

            if not possibleMove(board):
                if score >= 100:
                    continueTextSurf = FONT.render('You have passed this level with a score of %s. Pass the hangman challenge to continue.' % (score), 1, OVERCOLOR, OVERBACKCOLOR)
                    continueTextRect = continueTextSurf.get_rect()
                    continueTextRect.center = int(WINDOWWIDTH / 2), int(WINDOWHEIGHT / 2)
                    DISPLAY.blit(continueTextSurf, continueTextRect)
                    pygame.display.update()
                    import hangman
                    if hangman.play():
                        gameOver = False
                        level += 1
                        totalScore += score
                        board = getBlank()
                        score = 0
                        fillAndAnimate(board, points, score)
                    else:
                        totalScore += score
                        gameOver = True
                else:
                    totalScore += score
                    gameOver = True
            
        # draw board
        DISPLAY.fill(BACKGROUND)
        drawBoard(board)
        if firstGemPick != None:
            selectSpace(firstGemPick['x'], firstGemPick['y'])
        if gameOver:
            if gameOverTextSurf == None:
                # renders text
                if level == 1:
                    gameOverTextSurf = FONT.render('Game Over. Your Final Score is: %s (Click to start over)' % (score), 1, OVERCOLOR, OVERBACKCOLOR)
                else:
                    gameOverTextSurf = FONT.render('Game Over. Your Final Score is: %s (Click to start over)' % (totalScore), 1, OVERCOLOR, OVERBACKCOLOR)
                gameOverTextRect = gameOverTextSurf.get_rect()
                gameOverTextRect.center = int(WINDOWWIDTH / 2), int(WINDOWHEIGHT / 2)
            DISPLAY.blit(gameOverTextSurf, gameOverTextRect)
        displayLevel(level)
        displayScore(score)
        pygame.display.update()
Esempio n. 25
0
def main():
    import hangman
    hangman.play(pause=True)
Esempio n. 26
0
"""
   Testing module to evaluate the performance of the implemented hangman-bot
   against a given list of words.
"""

from hangman import play, getWords

words = getWords('words.txt')
score,i = 0,0
n = len(words)

for word in words[0:n]:
    score += play(word,True)
    i += 1
    if i % 1000 == 0: print "Completed %d words" % (i)

print "\nNumber of games won: %d" % (score)
print "Number of games lost: %d" % (n - score)
print "Success percentage: %.4f\n"%((score/float(n))*100)
Esempio n. 27
0
def bad_guess(x, word, letters):
    if x == 6:
        print('  _____')
        print('  |   |')
        print('  O   |')
        print('      |')
        print('      |')
        print('      |')
        print(' _____|\n')
        print('You have', x, 'more incorrect guesses!\n')
    elif x == 5:
        print('  _____')
        print('  |   |')
        print('  O   |')
        print('  |   |')
        print('      |')
        print('      |')
        print(' _____|\n')
        print('You have', x, 'more incorrect guesses!\n')
    elif x == 4:
        print('  _____')
        print('  |   |')
        print('  O   |')
        print(' \|   |')
        print('      |')
        print('      |')
        print(' _____|\n')
        print('You have', x, 'more incorrect guesses!\n')

    elif x == 3:
        print('  _____')
        print('  |   |')
        print('  O   |')
        print(' \|/  |')
        print('      |')
        print('      |')
        print(' _____|\n')
        print('You have', x, 'more incorrect guesses!\n')

    elif x == 2:
        print('  _____')
        print('  |   |')
        print('  O   |')
        print(' \|/  |')
        print('  |   |')
        print('      |')
        print(' _____|\n')
        print('You have', x, 'more incorrect guesses!\n')

    elif x == 1:
        print('  _____')
        print('  |   |')
        print('  O   |')
        print(' \|/  |')
        print('  |   |')
        print(' /    |')
        print(' _____|\n')
        print('You have', x, 'more incorrect guesses!\n')

    else:
        print('  _____')
        print('  |   |')
        print('  O   |')
        print('  |   |')
        print(' /|\  |')
        print(' / \  |')
        print(' _____|\n')
        print('Oh no! The hangman has been hanged!!\n')
        answer = input('Would you like to know the word? (y/n)')
        if answer.lower().strip() == 'y':
            print('\nYour word was: ', word.upper(), '\n')
        answer = input('Would you like to try again? (y/n)')
        if answer.lower().strip() == 'y':
            hangman.play()
        else:
            print('\nThank you for playing! Swing you again soon! Muahaha!')
            exit()