コード例 #1
0
def main():
    hangman = Hangman()
    while True:
        won, state = hangman.begin()
        if won:
            print("Won! The string is: " + state)
        else:
            print("Could not win. Starting again")
        hangman = Hangman()
コード例 #2
0
def main():
    choice = 0

    while choice != 6:
        '''Main menu screen.'''
        print("\nWelcome to the Python Fair.")
        print("1. Higher or lower?")
        print("2. Rock, Paper, Scissors")
        print("3. Counting jar")
        print("4. Hangman")
        print("5. Trivia")
        print("6. Leave")
        '''User input on the main menu.'''
        while True:
            try:
                choice = int(input("What do you want to do? "))
                break
            except ValueError:
                print("Not proper input.")
        '''Navigation to a selected game.'''
        if choice == 1:
            HighLow()
        elif choice == 2:
            RockPaperScissors()
        elif choice == 3:
            CountingJar()
        elif choice == 4:
            Hangman()
        elif choice == 5:
            Trivia()
        elif choice == 6:
            print("Goodbye.")
        else:
            print("Not a option.")
コード例 #3
0
ファイル: TestHangman.py プロジェクト: dmy-git/Hangman
 def test_import_std_file(self):
     std_file = open("words.txt")
     std_words = std_file.readlines()
     std_file.close()
     self.game = Hangman()
     self.assertEqual(len(self.game.words), len(std_words),
                      "Imported word isn't correct")
コード例 #4
0
    def startGame(self):
        while True:
            picked_word = None
            while True:
                self.hangman = Hangman()

                min_length = input("Enter Minimum Length : ")
                max_length = input("Enter Maximum Length : ")

                if not min_length.isdigit() or not max_length.isdigit() or\
                        int(min_length) <= 0 or int(max_length) <= 0:
                    print("Please Enter a Positive Integer")
                    continue

                picked_word = self.word.randFromDB(int(min_length),
                                                   int(max_length))
                if picked_word is None:
                    print("No Words Found")
                    continue
                break
            self.guess = Guess(picked_word)
            self.gameOver = False
            while not self.gameOver:
                self.guessClicked()
コード例 #5
0
from Hangman import Hangman
print("Welcome to Hangman!\n")
play = input("Would you like to play a game? (y/N) ")
if play.lower() != "y":
    print("Maybe later! Goodbye!")
    exit()
play_again = True
game = Hangman()
game.initialize_file('words.dat')
while play_again and game.num_words_available > 0:
    print("Starting game.")
    game.display_statistics()
    print("\n")
    game.new_word()
    while not game.game_over:
        game.display_game()
        user_guess = input("Enter a letter to guess. ")
        if not user_guess.isalpha():
            print("Sorry, I don't understand. That's not a letter. \n")
        elif not game.guess(user_guess.upper()):
            print("Sorry, you've alread guessed that letter. \n")
    game.reveal_word()
    game.display_statistics()
    game.game_over = False
    again = input("Would you like to play again? (y/N)")
    if again.lower() != "y":
        play_again = False

print("Thanks for playing! Goodbye!")
exit()
コード例 #6
0
ファイル: TestHangman.py プロジェクト: dmy-git/Hangman
 def setUp(self):
     self.game = Hangman(None, "kotik")
コード例 #7
0
ファイル: TestHangman.py プロジェクト: dmy-git/Hangman
 def setUp(self):
     self.game = Hangman(None, "kotik")
     self.saved_stdout = sys.stdout
コード例 #8
0
ファイル: TestHangman.py プロジェクト: dmy-git/Hangman
 def test_imported_word(self):
     self.game = Hangman("test.txt")
     self.assertEqual(self.game.word, "test", "Imported word isn't correct")
コード例 #9
0
ファイル: Driver.py プロジェクト: pomps8/Hangman
# Imports
from Hangman import Hangman

# FileName: Driver.py
# Author: Anthony Pompili
# Date: February 14, 2020
# Description: This file is the main driver for the "Hangman" game. This will initialize the game, and prompt
# the user if they want to play a game and then create a game for them to play with a phrase.

user_input = input("Do you want to play Hangman? (Type \"yes\" to play, otherwise the game will quit): ")

while (user_input.lower() == "yes"):
    print("Ok, lets play!")
    game_instance = Hangman()
    user_input = input("Would you like to play again? (Type \"yes\" to play, otherwise the game will quit): ")

print("Ok, bye then!")
コード例 #10
0
ファイル: game.py プロジェクト: CodyVollrath/Hangman
from Hangman import Hangman
from getpass import getpass
word = getpass("Enter Word Here -> ")
game = Hangman(word)
print("Game has started:\n\n")
print(game.getWord() + "\n\n")
letter = input("Enter a letter (enter only one letter) -> ")

while len(letter) <= 1:
    signal = game.guess(letter)
    print(signal)
    game.displayLettersTried()
    if signal == game.LOSE:
        print("Word was: " + game.word)
        break
    else:
        if not game.getWord().__contains__("_"):
            print(game.WIN)
            break
        else:
            letter = input("Enter a letter (enter only one letter) -> ")
コード例 #11
0
import argparse
from Hangman import Hangman

parser = argparse.ArgumentParser(
    description='TheHangman:\n1-tryb standardowy\n2-tryb artystyczny')
parser.add_argument('mode',
                    nargs='?',
                    const=1,
                    type=int,
                    help='default: 1',
                    default=1)

hangman = Hangman(parser.parse_args().mode)
コード例 #12
0
    word_generator = OxfordRequest()

    # English alphabet.
    alphabet = [
        "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N",
        "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"
    ]

    # Game loop...
    while True:
        # Initialize Hangman Model with word (new) & alphabet. Must validate all characters are within alphabet.
        while True:
            try:
                word = word_generator.get_random_word()
                word = word.upper()
                hangman = Hangman(word, alphabet)
                break
            except:
                print(word + " is not valid.")

        game_view.update_image(0)

        # Draw buttons to their initial state.
        for i in range(0, len(alphabet)):
            game_view.draw_button(i, gv.BUTTON_ACTIVE, alphabet[i])

        # Draw initial word blanks.
        for i in range(0, len(word)):
            if (word[i] == ' '):
                game_view.draw_character(i, ' ')
            else:
コード例 #13
0
 def __init__(self):
     self.hangman = Hangman()
コード例 #14
0
print('Hello! Would you like to play hangman?')
response = input('y/n?')

if response == 'n':
    print('Goodbye!')
    sys.exit()

#prompt user for a word
word = input('What word or phrase would you like to use?')
while len(word) > 25:
    print(
        'Your word/phrase is too long. The maximum number of characters is 25.'
    )
    word = input('Please type in a new word.')

#main game loop
os.system('cls')
print("Let's play hangman!")
hangman = Hangman(word)
while (hangman.get_life != 0):
    print()
    print()
    print()
    guess = input('Guess a letter:')
    hangman.find_letter(guess)
    if hangman.check_gameover() == True:
        sys.exit()
    if hangman.check_win() == True:
        sys.exit()
    hangman.print_word()
    hangman.print_hangman()
コード例 #15
0
    # Gather the settings info
    settings = HangmanSettings()
    display = settings.display
    max_incorrect = settings.max_incorrect
    count = 0
    total = 0

    display.clock("Start time")

    HangmanWordPassEngine.initialize(settings)

    # Grab the given secret from the generator function to start the game play!
    # No more secrets, no more play
    for secret in settings.get_secrets():

        hangman = Hangman(settings)

        score = hangman.play(secret, max_incorrect)
        total += score
        count += 1

        display.bare("{}: {}\n".format(secret.upper(), score))

        #display.clock("Finished game\n")

    # Compute the average score
    avg = float(total) / float(count)

    display.clock("End time")

    HangmanWordPassEngine.cleanup()
コード例 #16
0
from Hangman import Hangman
test = Hangman("hello")