|
| 1 | +import cv2 |
| 2 | +import numpy as np |
| 3 | +from utils import * |
| 4 | + |
| 5 | +movie_csv = "movies-list-short.csv" |
| 6 | +canvas = "blank-canvas.png" |
| 7 | + |
| 8 | +movies_data = read_from_csv(movie_csv) |
| 9 | + |
| 10 | +movie, movie_info = get_movie_info(movies_data) |
| 11 | + |
| 12 | +print(movie) |
| 13 | + |
| 14 | +hints,labels = select_hints(movie_info) |
| 15 | + |
| 16 | +img = get_canvas(canvas) |
| 17 | + |
| 18 | +char_rects = get_char_coords(movie) |
| 19 | + |
| 20 | +img = draw_blank_rects(movie,char_rects,img) |
| 21 | + |
| 22 | +cv2.namedWindow("Hangman", cv2.WND_PROP_FULLSCREEN) |
| 23 | +cv2.setWindowProperty("Hangman",cv2.WND_PROP_FULLSCREEN,cv2.WINDOW_FULLSCREEN) |
| 24 | + |
| 25 | +cv2.imshow("Hangman",img) |
| 26 | + |
| 27 | +chars_entered = [] |
| 28 | + |
| 29 | +incorrect_attempts = 0 |
| 30 | + |
| 31 | +img_copy = img.copy() |
| 32 | + |
| 33 | +while 1: |
| 34 | + img = img_copy.copy() |
| 35 | + img = draw_hint(img,hints,labels,incorrect_attempts) |
| 36 | + if incorrect_attempts >= 6: |
| 37 | + img = draw_lost(img) |
| 38 | + break |
| 39 | + elif check_all_chars_found(movie, chars_entered): |
| 40 | + img = draw_won(img) |
| 41 | + break |
| 42 | + else: |
| 43 | + letter = cv2.waitKey(0) & 0xFF |
| 44 | + if letter < 65 or letter > 122 or (letter > 90 and letter < 97): |
| 45 | + img = draw_invalid(img) |
| 46 | + cv2.imshow("Hangman",img) |
| 47 | + continue |
| 48 | + else: |
| 49 | + letter = chr(letter).upper() |
| 50 | + if letter in chars_entered: |
| 51 | + img = draw_reuse(img) |
| 52 | + img = draw_used_chars(img,chars_entered,letter) |
| 53 | + cv2.imshow("Hangman",img) |
| 54 | + continue |
| 55 | + else: |
| 56 | + chars_entered.append(letter) |
| 57 | + if letter in movie: |
| 58 | + img = draw_right(img) |
| 59 | + img = displayLetter(img,letter,movie,char_rects) |
| 60 | + img_copy = displayLetter(img_copy,letter,movie,\ |
| 61 | + char_rects) |
| 62 | + else: |
| 63 | + img = draw_wrong(img,incorrect_attempts) |
| 64 | + incorrect_attempts += 1 |
| 65 | + img = draw_used_chars(img,chars_entered,letter) |
| 66 | + img = draw_hangman(img,incorrect_attempts) |
| 67 | + img_copy = draw_used_chars(img_copy,chars_entered,letter) |
| 68 | + img_copy = draw_hangman(img_copy,incorrect_attempts) |
| 69 | + cv2.imshow("Hangman",img) |
| 70 | + #cv2.waitKey(0) |
| 71 | + |
| 72 | +img = revealMovie(movie,img,char_rects) |
| 73 | +cv2.imshow("Hangman",img) |
| 74 | +cv2.waitKey(0) |
| 75 | + |
| 76 | +cv2.destroyAllWindows() |
0 commit comments