Python Flames Game Project with Source Code

We all love playing games. Game of Flames is such a fun game. In this project, we are going to create the Flames Game using Python. Let us start making the project.

About Flames Game

We are going to create the Game of Flames using Python. Flames is a game that predicts the relationship between two people using their names. Flames stands for;

F – Friends

L – Love

A – Affection

M – Marriage

E – Enemies

S – Siblings

So there are a total of 6 relations that two people can have.

Python Flames Game project Details

During this project, we are going to need only the Tkinter Module. Tkinter Module will help us create the GUI Window for our Game of Flames. We will also need some basic knowledge of python to create the project.

In this project, we are going to create a GUI Window. In the window, we will have two entry boxes to enter the names and a button that when clicked will predict the relation between two people.

Project Prerequisites

To create this project we are going to use the Tkinter Module. To install the Tkinter Module, we use the following command –

pip install tk

Download Python Flames Game Source Code

Please download the source code of Flames python game project from the following link: FLAMES Game Project Code

Steps to Create the Project

Below are the steps we are going to follow while creating the project.

  1. Importing the Required Modules
  2. Creating the GUI Window
  3. Creating the Buttons, Labels and Entry Field
  4. Implementing the Flames Function

1. Importing the Required Modules:

import tkinter as tk
from tkinter import *
  • Tkinter Module – We have imported the Tkinter Module as tk. This Module will help us create an easy GUI Window in Python.

2. Creating the GUI Window:

window=Tk()
window.title("PythonGeeks")
window.geometry("500x500")
  • Tk() method to create a blank GUI window.
  • title() method to give an appropriate title to the window.
  • geometry() method to specify the geometry of the window.

3. Creating the Buttons, Labels and Entry Fields:

Label(window,text="Play FLAMES With PythonGeeks",font=("Arial", 15 ),bg="blue").pack()
 
Label(window,text="Enter Your Name").pack()
Entry(window,textvariable=n1).pack()
Label(window,text="Enter Your Crush's Name").pack()
Entry(window,textvariable=n2).pack()
 
Button(window,text="SHOW RESULT",bg="light blue",command=Flames).pack()
  • Label() – Using the Label() method, we are going to create a widget which will help us display text. The first Label we have created is to display a title on the blank window. We have made two other labels to instruct the user what to add in the entry fields. Inside the Label() method, we can specify the font, size, background color, foreground color etc.
  • Entry() – The Entry() method helps us create entry fields where the user can enter the names. We have created two entry fields-

a. To enter your name.

b. To enter your crush’s name.

  • Textvariable saves the value entered by the user in the assigned variables. Here the variables are n1 and n2.
  • Button() – The Button() method helps in creating a button on the window. Whenever this button is clicked the Flames result will be displayed. This button will only work when both the entry fields are filled.
  • pack() – We have used pack() method to display all these widgets on the blank window. pack() method uses the first come first serve method and places the widget that is written in the code first in first place. This method does not use the x and y coordinates to display the widgets.

4. Implementing the Flames Function

n1=tk.StringVar()
n2=tk.StringVar()
 
def Flames():
    name1=n1.get()
    name2=n2.get()
    namestr = name1 + name2
    for c in namestr:
        if namestr.count(c) != 1:
            # counting common letters
            namestr = namestr.replace(c,"")
 
    number = len(namestr) % 6
    # number to move through FLAMES
    global rel
    rel= ""
    if number == 1:
        rel += "Friends"
    elif number == 2:
        rel += "Love"
    elif number == 3:
        rel += "Affection"
    elif number == 4:
        rel += "Marriage"
    elif number == 5:
        rel += "Enemy"
    elif number == 0:
        rel += "Siblings"
    else:
        pass
   
    Label(window,text="According to the Game of Flames the Relation is:").pack()
    Label(window,text=rel).pack()
  • StringVar() – This method specifies that the variables n1 and n2 are of string type.
  • We have created the Flames() function to find out the relationship between the two names entered by the user. This function will be evoked when the button on the window is clicked.
  • get() – Using the get() method, we get the values entered by the user.
  • We add both names and save it in the namestr variable. Using the count() method, we are going to count the number of common letters in the namestr and replace them with a blank.
  • Using the len() method we find the length of the namestr variable and mod it with 6 as we have 6 relations.
  • Making a global rel, we are going to use the if else loop and show the relationship using the number. To display the result we are going to use the Label() method.

Hurray! We have successfully completed FLAMES Game using Python. Now let us have a look at the output of the project.

Python Flames Game Output

This is how our GUI Window looks

python flames game output

Summary

We have successfully created the FLAMES Game using Python. We have used the Tkinter Module to build the project and learned about different functions used in the Tkinter Module.

Your opinion matters
Please write your valuable feedback about PythonGeeks on Google | Facebook


Leave a Reply

Your email address will not be published. Required fields are marked *