The final project for Codecademy’s programming course in computer science is to make a terminal game in python. I remembered wanting to play the game from an image match layout in Codecademy’s CSS course, so I decided to make my own match the images memory game.
I looked up image match games and realized my game board needed a theme. I chose shapes because they were the easiest for me to create using string characters and I was able to make more shapes by using large and small sizes of each one. The final game board has eight shape pairs and sixteen game pieces on a 4×4 board.
Python code
I wrote the game program in VS Code and the final program is split into two python files: one with string lists to make game boards and one with the game play variables and functions. The game file imports the game boards file, along with random
.
In the game file, the game_board_solution()
function uses the choice()
method from random
to assign shapes from the shape_nums
list to each spot in the game_board_solution_dict
. The start_game_setup()
function prints the title, start game board, and instructions for the player.
To flip a game board piece, the player enters a row and column number, the player_piece
. The play_game()
function prints a game board with the shape at player_piece
from the game_board_solution_dict
. play_game()
stores the shape number in the flipped_pieces
list and the print_player_board()
function prints a board using a shape row from the shapes_dict
and three rows from game_piece_row
.
When the player matches shapes, the matched_shapes_()
function prints a message and stores the shape numbers from flipped_pieces
in the matched_shapes
list so the player cannot flip those pieces again. When the player matches eight shape number pairs from the matching_shapes
list, the win_game()
function prints a message and lets them play again with a new game board solution.
See code on GitHub
暂无评论内容