Пример #1
0
def gameMain():
    word = Word('words.txt')
    guess = Guess(word.randFromDB())

    finished = False
    hangman = Hangman()
    maxTries = hangman.getLife()

    while guess.numTries < maxTries:

        display = hangman.get(maxTries - guess.numTries)
        print(display)
        guess.display()

        guessedChar = input('Select a letter: ')
        if len(guessedChar) != 1:
            print('One character at a time!')
            continue
        if guessedChar in guess.guessedChars:
            print('You already guessed \"' + guessedChar + '\"')
            continue

        finished = guess.guess(guessedChar)
        if finished == True:
            break

    if finished == True:
        print('Success')
    else:
        print(hangman.get(0))
        print('word [' + guess.secretWord + ']')
        print('guess [' + guess.currentWord + ']')
        print('Fail')
Пример #2
0
def gameMain():
    word = Word('words.txt')
    guess = Guess(word.randFromDB())

    hangman = Hangman()
    maxTries = hangman.getLife()

    while (maxTries - guess.numTries):

        display = hangman.get(maxTries - guess.numTries)
        print(display)
        guess.display()

        guessedChar = input("Select a letter:")
        if len(guessedChar) != 1:
            print("One character at a time!")
            continue
        if guessedChar in guess.guessedChars:
            print("You already guessed \' %c \' " % (guessedChar))
            continue

        if guess.guess(guessedChar) == True:
            print("Success!")
            break

    if guess.guess(guessedChar) == False:
        print(hangman.get(0))
        print("word [ %s ]" % (guess.secretWord))
        print("guess [ %s ]" % (guess.currentStatus))
        print('Fail')
Пример #3
0
def gameMain():
    word = Word('words.txt')
    guess = Guess(word.randFromDB())  # 랜덤하게 단어선택

    finished = False
    hangman = Hangman()
    maxTries = hangman.getLife()  # 목숨의 개수를 초기화 시킴

    while guess.numTries < maxTries:  # 목숨이 몇개 남았는지 체크해줌

        display = hangman.get(maxTries - guess.numTries)
        print(display)
        guess.display()

        guessedChar = input('Select a letter: ')
        if len(guessedChar) != 1:  # 한글자가 아니면
            print('One character at a time!')
            continue
        if guessedChar in guess.guessedChars:  # 이미 사용한 문자라면
            print('You already guessed \"' + guessedChar + '\"')
            continue

        finished = guess.guess(guessedChar)
        if finished == True:
            break

    if finished == True:
        print('Success')
        print('word : ' + guess.secretWord)
    else:
        print(hangman.get(0))
        print('word [' + guess.secretWord + ']')
        print('guess [' + guess.currentStatus + ']')
        print('Fail')
Пример #4
0
def gameMain():
    word = Word('words.txt')
    guess = Guess(word.randFromDB())

    finished = False
    hangman = Hangman()
    maxTries = hangman.getLife()

    while guess.numTries < maxTries:

        display = hangman.get(maxTries - guess.numTries)
        print(display)
        guess.display()

        guessedChar = input('Select a letter: ')

        finished = guess.guess(guessedChar)
        if finished:
            break

    if finished:
        print('Success')
    else:
        print(hangman.get(0))
        print('word [' + guess.word + ']')
        print("Guess:", end=" ")
        for i in range(len(guess.current)):
            print(guess.current[i], end=" ")
        print()
        print('Fail')
Пример #5
0
def gameMain():
    '''게임 구동 과정'''

    # 파일에 있는 단어 정리 및 갯수 알려주기
    word = Word('aabbcc.txt')

    # 파일안에 있는 단어 랜덤적으로 가져온다.
    guess = Guess(word.randFromDB())

    # 처음에는 단어가 완성이 안돼있으니 False 출력
    finished = False

    # 목숨갯수(maxTries = 6)초기화
    hangman = Hangman()
    maxTries = hangman.getLife()

    # numTries(현재 남은 목숨갯수)가 6보다 크거나 같을 때가지 실행
    while guess.numTries < maxTries:

        # 시각적으로 행맨을 보여준다 (남은 목숨갯수에 맞게)
        # 6 -> 0
        display = hangman.get(maxTries - guess.numTries)
        print(display)
        guess.display()

        guessedChar = input('Select a letter: ')

        # 알파벳 한개만 적기 #
        if len(guessedChar) != 1:
            print('One character at a time!')
            continue
        # guessedChars는 이미적은 알파벳을 모아 놓은 곳
        if guessedChar in guess.guessedChars:
            print('You already guessed \"' + guessedChar + '\"')
            continue

        # 입력된 알파벳이 랜덤단어안에 있는지 확인
        # 단어가 완성 되었는지
        finished = guess.guess(guessedChar)
        if finished == True:
            break

    # 알파벳이 존재한다면 성공
    if finished == True:
        print('Success')

    # 만약 제안된 기회 안에 단어를 완성하지못했다면
    else:
        # 매달린 남자 보여주기
        print(hangman.get(0))
        #사용한 알파벳, 기회가용횟수, 실패
        print('word was [' + guess.secretWord + ']')
        print('guess [' + guess.currentStatus + ']')
        print('Fail')
Пример #6
0
def gameMain():
    word = Word('words.txt')
    #guess 는 Guess 클래스에 랜덤으로 단어 하나를 인자로 던진 것
    guess = Guess(word.randFromDB())

    finished = False
    hangman = Hangman()
    #목숨의 개수를 초기화
    maxTries = hangman.getLife()
    #실패한 횟수가 목숨보다 적으면 계속 실행
    while guess.numTries < maxTries:
        #display라는 변수를 통해 만들어서 행맨 모양을 불러옴
        display = hangman.get(maxTries - guess.numTries)
        #행맨 모양 출력
        print(display)
        #Current 와 Tries 출력
        guess.display()
        #입력한 문자를 guessedChar라고 함
        guessedChar = input('Select a letter: ')
        #입력한 문자가 한글자가 아니라면
        if len(guessedChar) != 1:
            print('One character at a time!')
            continue
        #입력한 문자가 대문자라면
        if 65 <= ord(guessedChar) <= 90:
            #소문자로 변경
            guessedChar = chr(ord(guessedChar) + 32)
        #입력한 문자가 이미 입력했던 문자라면
        if guessedChar in guess.guessedChars:
            print('You already guessed \"' + guessedChar + '\"')
            continue
        #알파벳 이외의 다른 모든 경우의 수를 차단
        if ord(guessedChar) <= 64 or 91 <= ord(
                guessedChar) <= 96 or 123 <= ord(guessedChar):
            print('Please enter the alphabet!')
            continue
        #guess 모듈로 넘어가서 입력한 문자에 대해 처리
        finished = guess.guess(guessedChar)
        #단어가 완성되었을 때 while 탈출
        if finished == True:
            break

    if finished == True:
        print('Success')
    #단어가 완성되어서 탈출한게 아니라 목숨의 개수가 다달아서 False인 상태에서 while문을 빠져나온 경우
    else:
        print(hangman.get(0))
        print('word [' + guess.secretWord + ']')
        print('guess [' + ''.join(guess.currentStatus) + ']')
        print('Fail')
Пример #7
0
def gameMain():
    word = Word('words.txt')
    guess = Guess(word.randFromDB())

    finished = False
    hangman = Hangman()
    maxTries = hangman.getLife()

    while guess.numTries < maxTries:

        display = hangman.get(maxTries - guess.numTries)
        print(display)
        guess.display()

        guessedChar = input('Select a letter: ').lower()  # 대문자가 들어와도 소문자로 취급
        # []안의 내용을 컴파일하여 정규식 객체를 반환
        r = re.compile('[^ ㄱ-ㅣ가-힣]+')
        #guessedChar에서 공백을 제외한 문자들을 문자열로 반환
        result = r.sub('', guessedChar)

        if guessedChar.isdigit():
            print("알파벳을 입력해 주세요.")
            continue
        elif guessedChar in result:
            print("알파벳을 입력해 주세요.")
            continue
        if len(guessedChar) != 1:
            print('One character at a time!')
            continue
        if guessedChar in guess.guessedChars:
            print('You already guessed \"' + guessedChar + '\"')
            continue

        finished = guess.guess(guessedChar)
        if finished == True:
            break

    if finished == True:
        print('Success')
    else:
        print(hangman.get(0))
        print('word [' + guess.secretWord + ']')
        print('guess [' + guess.currentStatus + ']')
        print('Fail')
Пример #8
0
def gameMain():
    #Word클래스로 만든 오브젝트 
    word = Word('words.txt')
    #guess 는 랜덤 단어로 만든 Guess의 오브젝트
    guess = Guess(word.randFromDB())
    #
    finished = False
    #Hangman의 오브젝트 만들어서 남은생명
    hangman = Hangman()
    #남은생명==리스트 아이템 개수
    maxTries = hangman.getLife()

    #아마 numtries는 실행횟수 일듯@@@@@@@@@
    #실행횟수 < 남은생명 일때.. loop
    while guess.numTries < maxTries:
        #현재 행맨의 모습..
        display = hangman.get(maxTries - guess.numTries)
        print(display)

        #현재까지의 상황출력 (맞춘글자, 실패횟수)
        guess.display()
        #알파벳 제시!
        guessedChar = input('Select a letter: ')
        if len(guessedChar) != 1:
            print('One character at a time!')
            continue
        #guseedChars는 내가 이미 제시한 알파벳들의 리스트 일듯.
        if guessedChar in guess.guessedChars:
            print('You already guessed \"' + guessedChar + '\"')
            continue
        #guess()는 해당 알파벳이 단어안에 있으면 위치를기록.
        #없으면 실패횟수를 증가시킴
        #모든글자를 다 맞추었으면 True 아니면 False.
        finished = guess.guess(guessedChar)
        if finished == True:
            break

    if finished == True:
        print('Success')
    else:
        print(hangman.get(0))
        print('word [' + guess.secretWord + ']')
        print('guess [' + guess.currentStatus + ']')
        print('Fail')
Пример #9
0
def gameMain():
    word = Word('words.txt')
    guess = Guess(word.randFromDB())  #랜덤 단어 선택

    finished = False
    hangman = Hangman()
    maxTries = hangman.getLife()  #목숨개수 초기화

    while guess.numTries < maxTries:
        # numTries는 추측 실패 횟수
        display = hangman.get(maxTries - guess.numTries)
        print(display)
        guess.display()

        guessedChar = input('Select a letter: ')
        # 입력받은 문자열이 1개의 문자가 아닐 때
        if len(guessedChar) != 1:
            print('One character at a time!')
            continue
        # 입력받은 문자가 이미 이전에 입력받은 것일 떄
        if guessedChar in guess.guessedChars:
            print('You already guessed \"' + guessedChar + '\"')
            continue
        # 입력받은 문자가 a~z가 아닐 때
        if guessedChar < 'a' or guessedChar > 'z':
            print('please enter a character between a and z')
            continue
        #전체 문자 맞추면 while문 break 하고 Success 프린트
        finished = guess.guess(guessedChar)
        if finished == True:
            break

    if finished == True:
        print()
        print(guess.secretWord)
        print('Success!')
        print('You win by trying', guess.numTries, 'Times')
    #허용된 횟수 내에 전체 문자 못 맞추면 hangman.text[0] 출력, 즉 목 매다는 그림 출력
    else:
        print(hangman.get(0))
        print('word [' + guess.secretWord + ']')
        print()
        print('Fail')
        print("The word was", guess.secretWord)
Пример #10
0
def gameMain():
    numbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
    word = Word('words.txt')
    #guess에 랜덤단어 저장
    guess = Guess(word.randFromDB())

    finished = False

    hangman = Hangman()

    maxTries = hangman.getLife()

    while guess.numTries < maxTries:

        display = hangman.get(maxTries - guess.numTries)
        print(display)
        guess.display()

        guessedChar = input('Select a letter: ')
        if len(guessedChar) != 1:
            print('One character at a time!')
            continue
        else:
            if guessedChar in numbers:
                print("Not numbers!")
                continue

        if guessedChar in guess.guessedChars:
            print('You already guessed \"' + guessedChar + '\"')
            continue

        finished = guess.guess(guessedChar)
        if finished == True:
            break

    if finished == True:
        print('Success')
    else:
        print(hangman.get(0))
        print('word [' + guess.word + ']')
        print('guess [', guess.strcurrent, ']')
        print('Fail')
Пример #11
0
def gameMain():
    word = Word('words.txt')
    guess = Guess(word.randFromDB())

    finished = False
    hangman = Hangman()
    maxTries = hangman.getLife()

    while guess.numTries < maxTries:

        display = hangman.get(maxTries - guess.numTries)
        print(display)
        guess.display()
        
        guessedChar = input('Select a letter: ')
        ## 입력이 영어 인경우만 처리 하기 위해
        if guessedChar.isalpha() != 1:
            print('Enter alphabet')
            continue
        if len(guessedChar) != 1:
            ## 만약 사용자가 문자대신 단어를 입력해서 맞으면 success
            if guessedChar == guess.secretWord:
                print('genius godgod smart!')
                finished = True
                break
            else:
                print('One character at a time!')
                continue
        if guessedChar in guess.guessedChars:
            print('You already guessed \"' + guessedChar + '\"')
            continue

        finished = guess.guess(guessedChar)
        if finished == True:
            break
    if finished == True:
        print('Success')
    else:
        print(hangman.get(0))
        print('word [' + guess.secretWord + ']')
        print('guess [' + guess.currentStatus + ']')
        print('Fail')
Пример #12
0
def gameMain():
    word = Word('words.txt')
    guess = Guess(word.randFromDB())

    finished = False
    hangman = Hangman()
    maxTries = hangman.getLife()

    while guess.numTries < maxTries:
        display = hangman.get(maxTries - guess.numTries)
        print(display)
        guess.display()
        guessedChar = input('Select a letter: ')
        if guessedChar.isalpha():
            if len(guessedChar) != 1:
                print('One character at a time!')
                continue
            if guessedChar in guess.guessedChars:
                print('You already guessed \"' + guessedChar + '\"')
                continue
            finished = guess.guess(guessedChar)
            if finished == True:
                break
        else:
            print('You must input Alphabet!!!')
            continue

    if finished == True:
        print('Success!! The answer is %s!!' %guess.secretWord)
    else:
        print(hangman.get(0))
        print('It is your guessed spell :', guess.guessedChars)
        print('Current : ', guess.currentStatus)
        print('Your Last Chance!! Insert Full Word!!')
        lastanswer = input('>>>>>>>> ')
        if lastanswer == guess.secretWord:
            print('Success!!')
        else:
            guess.answer = lastanswer
            print('word [' + guess.secretWord + ']')
            print('guess [' + guess.answer + ']')
            print('Fail')
Пример #13
0
def gameMain():
    #랜덤으로 단어 선택
    word = Word('words.txt')
    guess = Guess(word.randFromDB())

    finished = False
    hangman = Hangman()
    #목숨의 갯수를 초기화
    maxTries = hangman.getLife()

    while guess.numTries < maxTries: #max

        display = hangman.get(maxTries - guess.numTries)
        print(display)
        guess.display()
        
        #lstrip을 넣어서 공백은 자동으로 제거
        guessedChar = input('Select a letter: ')
        if len(guessedChar.lstrip()) != 1:
            print('One character at a time!')
            continue
        if guessedChar.lstrip() in guess.guessedChars:
            print('You already guessed \"' + guessedChar + '\"')
            continue
        # 입력한 문자가 알파벳 소문자가 아니면 오류
        if guessedChar.lstrip() not in alphabet:
            print('Character must be English small letter!')
            continue

        finished = guess.guess(guessedChar)
        if finished == True:
            break

    if finished == True:
        print('Success')
        print('The answer is '+guess.secretWord)
    else:
        print(hangman.get(0))
        print('word [' + guess.secretWord + ']')
        print('guess [' + guess.currentStatus + ']')
        print('Fail')
def gameMain():
    word = Word('words.txt')
    guess = Guess(word.randFromDB())

    finished = False  # bitmediyse false
    hangman = Hangman()
    maxTries = hangman.getLife()

    while guess.numTries < maxTries:  # en yuksek can in degerini kayit

        display = hangman.get(
            maxTries -
            guess.numTries)  # burasi neyi baslatip nasil degistiriyor
        print(
            display
        )  # can degerinden yanan candegerini cikarttigimizda kalan can degeri
        guess.display()

        guessedChar = raw_input('Select a letter:')
        print(guessedChar)
        if len(guessedChar) != 1:
            print('One character at a time!')
            continue
        if guessedChar in guess.guessedChars:
            print('You already guessed \"' + guessedChar +
                  '\"')  # tahmin ediline harfin olup olmadigini teyit eder
            continue

        finished = guess.guess(
            guessedChar)  # bu method neyi return yapmak icin bulunuyor
        if finished == True:  # guess class aldigi 1 tane harfi kayit
            break

    if finished == True:  # game in ortasinda bitirip cikmada  kull
        print('Success')
    else:
        print(hangman.get(0))
        print('word [' + guess.secret + ']')
        print('guess [' + guess.currentStatus + ']')
        print('Fail')
Пример #15
0
def gameMain():
    word = Word('assn7/words.txt')
    try:
        guess = Guess(word.random_word())
    except ValueError:
        print('can\'t find words.txt')
        exit()
    is_finished = False
    hangman = Hangman()
    max_tries = hangman.get_life()

    while guess.num_tries < max_tries:

        display = hangman.get(max_tries - guess.num_tries)
        print(display)
        guess.display()

        guessed_char = input('Select a letter: ')
        guessed_char = guessed_char.lower()
        if not guessed_char.isalpha():
            print('Input alphabet')
            continue
        if len(guessed_char) != 1:
            print('One character at a time!')
            continue
        if guessed_char in guess.guessed_chars:
            print('You already guessed \"' + guessed_char + '\"')
            continue

        is_finished = guess.guess(guessed_char)
        if is_finished:
            break

    if is_finished:
        print('Success')
    else:
        print(hangman.get(0))
        print('word [' + guess.secret_word + ']')
        print('guess [' + guess.current_status + ']')
        print('Fail')
Пример #16
0
def gameMain():
    word = Word('words.txt')
    guess = Guess(word.randFromDB())

    finished = False
    hangman = Hangman()
    maxTries = hangman.getLife()

    while guess.numTries < maxTries:

        # 목숨??
        display = hangman.get(maxTries - guess.numTries)
        print(display)
        guess.display()

        guessedChar = input('Select a letter: ')
        # 알파벳 한개만 적기
        if len(guessedChar) != 1:
            print('One character at a time!')
            continue
        # guessedChars는 이미적은 알파벳을 모아 놓은 곳
        if guessedChar in guess.guessedChars:
            print('You already guessed \"' + guessedChar + '\"')
            continue

        # 적은 알파벳이 랜덤적으로 고른/전체다 맞췄는지? 단어안에 있는지 확인
        finished = guess.guess(guessedChar)
        if finished == True:
            break

    # 알파벳이 존재한다면 성공
    if finished == True:
        print('Success')
    else:
        print(hangman.get(0))
        print('word [' + guess.secretWord + ']')
        print('guess [' + guess.currentStatus + ']')
        print('Fail')
Пример #17
0
def gameMain():
    word = Word('words.txt')
    guess = Guess(word.randFromDB())

    finished = False
    hangman = Hangman()
    maxTries = hangman.getLife()

    while guess.numTries < maxTries:
        display = hangman.get(maxTries - guess.numTries)
        print(display)
        guess.display()

        guessedChar = input('Select a letter: ')
        hangul = re.compile('[^ ㄱ-ㅣ가-힣]+')  # 한글과 띄어쓰기를 제외한 모든 글자

        if hangul.sub('', guessedChar):
            print('Only English')
            continue
        if len(guessedChar) != 1:
            print('One character at a time!')
            continue
        if guessedChar in guess.guessedChars:
            print('You already guessed \"' + guessedChar + '\"')
            continue

        finished = guess.guess(guessedChar.lower())
        if finished == True:
            break

    if finished == True:
        print('Success')
    else:
        print(hangman.get(0))
        print('word [' + guess.secretWord + ']')
        print('guess [' + guess.currentStatus + ']')
        print('Fail')