|
2 rokov pred | |
---|---|---|
.. | ||
README.md | 2 rokov pred | |
blank-canvas.png | 5 rokov pred | |
main.py | 5 rokov pred | |
movies-list-short.csv | 5 rokov pred | |
movies-list.csv | 5 rokov pred | |
utils.py | 5 rokov pred |
This repository contains the code for Hangman: Creating games in OpenCV blog post.
release_year
, cast
, director
, keywords
and tagline
as 5 features of a movie.dropna
function from Pandas.,
in the movie title or any of the 5 features. This has been done to make sure that the commas are present only to separate the data across columns in CSV file.Save the final database to a CSV file using to_csv
function from Pandas.
Read the dataset from the CSV file and store it in dictionary format: movie_title:[year,list of keywords, tagline, director, list of cast]
- read_from_csv
Get a random movie from the list of movies and get all the information (5 features) for that movie - get_movie_info
From the 5 movie features, select any 3 features. If the features have list of keywords and/or list of cast, randomly select one from the list - select_hints
Read the hangman template - get_canvas
Get the points where each blank rectanglular box will be drawn depending on the maximum width and height among all the characters present in the movie name - get_char_coords
Draw the blank rectangular boxes - draw_blank_rects
While the number of incorrect attempts is less than 6 and the game hasn't been won or lost yet:
Take character input from user
If the character is invalid (not an alphabet), display INVALID CHARACTER
Else if the character has already been entered, display ALREADY USED
Else if the character is NOT present in movie title, display WRONG
, increment number of incorrect attempts, display another body part in Hangman, and display the character in Letters used
Else, display CORRECT
, display the letters in the blank rectangles and display the character in Letters used
If all characters in movie have been guessed, break the loop and display YOU WON
If number of incorrect attempts are equal to or more than 6, break the loop and display YOU LOST
Reveal the movie name at the end of the game.
Wait for the user to press a key and quit.
The entire game will run on full screen by default.
python main.py
Want to become an expert in AI? AI Courses by OpenCV is a great place to start.