Matchmaker Game Project in Python

The Matchmaker Game project in Python is a single-player game for desktops. Use your memorization skills to outmatch your opponent! Find matches and avoid mismatches to win. This game provides a basic example on how to program in Python programming.

Matchmaker Game Project Python

To Build a Simple  Matchmaker Game Project You need to follow the below steps

Step 1. Download Python

You only need Python to run this script. You can visit here to download Python and then you need to install a package named tk.

pip install tk

Step 2. Write the following code

Write this code in a Python file or directly copy this code and save the file with the name and .py extension e.g python Matchmaker.py

import random
import time
from tkinter import Tk, Button, DISABLED

def show_symbol(x,y):
    global first
    global previousx, previousy
    buttons[x,y]['text'] = button_symbols[x,y]
    buttons[x,y].update_idletasks()

    if first:
        previousx = x
        previousy = y
        first = False
    elif previousx != x or previousy !=y:
        if buttons[previousx, previousy]['text'] != buttons[x,y]['text']:
            time.sleep(0.5)
            buttons[previousx,previousy]['text']= ' '
            buttons[x,y]['text'] = ' '
        else:
            buttons[previousx, previousy]['command'] = DISABLED
            buttons[x,y]['command'] = DISABLED
        first = True

win = Tk()
win.title('Matchmaker')
win.resizable(width=False,height=False)
first = True
previousx = 0
previousy = 0
buttons = { }
button_symbols = { }
symbols = [u'\u2702',u'\u2705',u'\u2708',u'\u2709',u'\u270A',u'\u270B',
           u'\u270C',u'\u270F',u'\u2712',u'\u2714',u'\u2716',u'\u2728',
           u'\u2702',u'\u2705',u'\u2708',u'\u2709',u'\u270A',u'\u270B',
           u'\u270C',u'\u270F',u'\u2712',u'\u2714',u'\u2716',u'\u2728']

random.shuffle(symbols)


for x in range(6):
    for y in range(4):
        button = Button(command = lambda x=x, y=y: show_symbol(x,y),width=10,height=8)
        button.grid(column=x,row=y)
        buttons[x,y] = button
        button_symbols[x,y] = symbols.pop()

win.mainloop()

Step 3. Run the code

After saving the code double-click on the file to run the program or simply open Command Prompt and write the following command.

python Matchmaker.py

Demo:

Matchmaker

Leave a Comment