Simple FLAMES Game Using Tkinter Python
FLAMES is a popular game that has been played for ages. It helps to determine the compatibility between two people. It stands for "Friends, Lovers, Affectionate, Marriage, Enemies, and Siblings". The letters that are the same in both players' names are taken out of their names in this game. The remaining letters are used to determine the relationship between the two players.
In this article, we will discuss how to create a FLAMES game using Tkinter. The Python module Tkinter is used to create graphical user interfaces (GUIs). We will use Tkinter to create a simple user interface for the FLAMES game.
Let's begin by making a simple Tkinter window with a label and two entry fields for the names of the two people:
from tkinter import * # create the main window root = Tk() root.title("FLAMES Game") root.geometry("400x200") # create the labels and entry fields label1 = Label(root, text="Enter Name 1:") label1.grid(row=0, column=0, padx=10, pady=10) entry1 = Entry(root) entry1.grid(row=0, column=1, padx=10, pady=10) label2 = Label(root, text="Enter Name 2:") label2.grid(row=1, column=0, padx=10, pady=10) entry2 = Entry(root) entry2.grid(row=1, column=1, padx=10, pady=10) root.mainloop()
The two labels and two entry fields for the two people's names are created using this code in a window. The window is 400x200 pixels in size.
After that, we must provide a button that launches the FLAMES game. When the button is pressed, a function called flames_game() will be launched. The two names will be taken from the entry fields once the function removes the common letters. The FLAMES algorithm will then be used for the remaining letters to ascertain the link between the two individuals. The outcome will then be shown in a message box.
from tkinter import * from tkinter import messagebox # define the FLAMES game function def flames_game(): name1 = entry1.get().lower() name2 = entry2.get().lower() # remove common letters from the names for letter in name1: if letter in name2: name1 = name1.replace(letter, "", 1) name2 = name2.replace(letter, "", 1) # create the FLAMES dictionary flames_dict = { "F": "Friends", "L": "Lovers", "A": "Affectionate", "M": "Marriage", "E": "Enemies", "S": "Siblings" } # calculate the FLAMES result count = len(name1) + len(name2) while len(flames_dict) > 1: index = count % len(flames_dict) - 1 if index >= 0: flames_dict = list(flames_dict.keys()) flames_dict.remove(flames_dict[index]) flames_dict = {key: flames_dict[key] for key in range(len(flames_dict))} else: flames_dict = {key: flames_dict[key] for key in range(len(flames_dict) - 1)} count = len(flames_dict) # display the result in a message box result = list(flames_dict.values())[0] messagebox.showinfo("FLAMES Result", result) # create the main window root = Tk() root.title("FLAMES Game") root.geometry("400x200")
Let's now include a button in the window that, when pressed, launches the flames_game() function:
# create the labels and entry fields label1 = Label(root, text="Enter Name 1:") label1.grid(row=0, column=0, padx=10, pady=10) entry1 = Entry(root) entry1.grid(row=0, column=1, padx=10, pady=10) label2 = Label(root, text="Enter Name 2:") label2.grid(row=1, column=0, padx=10, pady=10) entry2 = Entry(root) entry2.grid(row=1, column=1, padx=10, pady=10) # create the FLAMES button button = Button(root, text="FLAMES", command=flames_game) button.grid(row=2, column=0, columnspan=2, pady=10) root.mainloop()
This code generates the "FLAMES" button, and when clicked, launches the flames game() function. To make the window look a little better, we have also added some padding around the entry fields and the button.
The two names are first extracted from the entry fields and changed to lowercase by the flames_game() method. By looping through each letter in name1 and determining if it appears in name2, it then eliminates the common letters from the names. If a shared letter is discovered, the replace() method is used to delete it from both names.
Next, we develop a dictionary named flames_dict that associates a relationship status with each letter of the word "FLAMES." The FLAMES result is then calculated by looping over the dictionary until just one letter is left. The number of letters in names 1 and 2 are counted at the beginning of the loop. The remaining count is then divided by the dictionary's length to determine an index. The letter at the index is eliminated from the dictionary if the index is higher than or equal to zero. The final letter in the dictionary is eliminated if the index value is less than zero. The cycle is repeated until there is just one letter left in the dictionary, at which point the loop ends.
Lastly, we use the 'showinfo()' method of the 'messagebox' module to display the outcome in a message box.
The FLAMES game with a user interface made with Tkinter is ready to use. To make the window look more appealing, we can alter its layout and design, or you can enhance the game's features.