Skip to content

Instantly share code, notes, and snippets.

@Chaitran77
Created November 28, 2017 07:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Chaitran77/85c78546a9239963664b9a31f1f699b9 to your computer and use it in GitHub Desktop.
Save Chaitran77/85c78546a9239963664b9a31f1f699b9 to your computer and use it in GitHub Desktop.
HangMan created by chaitran77 - https://repl.it/@chaitran77/HangMan
import random
import pygame
from pygame.locals import *
pygame.init()
words = "inhabitant resign excitement introduce reserve cattle feminine flavor sleeve incapable athlete investigation rabbit access recognize vigorous freshman ceiling coyote baboon wombat aposemetic miracle linear unlike border plastic rebellion remark settlement voucher intention heaven dentist recognize intervention sleeve champion mushroom development".split()
wrong_attempts = 0
class AI:
def __init__(self):
self.secret_word = self.choose_word()
self.char_canvas = []
self.generate_char_canvas()
def generate_char_canvas(self):
for letters in self.secret_word:
self.char_canvas.append("_")
def start_message(self):
print("Hello and welcome to HangMan!")
def retrieve_guess(self):
tmp_letter = input("Guess a letter:\n")
if len(tmp_letter) < 1:
print("Make sure that you only type --> ONE <-----> LETTER (not number!) <--")
self.retrieve_guess()
else:
return tmp_letter
def print_revealed_characters(self):
print(self.char_canvas)
def choose_word(self):
return random.choice(words)
def process_guess(self):
# try:
index_of_letter = self.secret_word.index(self.retrieve_guess())
del self.char_canvas[index_of_letter]
self.char_canvas = self.char_canvas[:index_of_letter] + list(self.retrieve_guess()) + self.char_canvas[index_of_letter:]
print(self.char_canvas)
"""
except ValueError:
wrong_attempts +- 1
print("Wrong")
"""
class Player:
def __init__(self):
pass
judge = AI()
judge.start_message()
print(judge.secret_word)
judge.process_guess()
"""
while "_" in self.char_canvas:
run
"""
"""
def pygame_hangman(wrong_attempts):
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment