Sharing is caring!

1 Best FLAMES Game in Python With Source Code

Table of Contents

Have you ever thought about checking your compatibility with someone? Maybe you’re familiar with the fun game known as FLAMES?

Today, let’s explore the realm of FLAMES with Python, where we’ll develop an entertaining and engaging method to assess relationship compatibility.

Prepare yourself for this coding journey that blends logic, strings, and a hint of romantic charm!

What is the FLAMES Game?

FLAMES is a popular game played to determine the relationship between two people based on their names. FLAMES stands for:

  • Friends
  • Lovers
  • Affectionate
  • Marriage
  • Enemies
  • Siblings

The game works by taking the names of two individuals and eliminating common letters to find out the relationship status represented by the remaining letters in “FLAMES”.

Let’s Code the FLAMES Game in Python

Step-by-Step Implementation

We’ll build the FLAMES game using Python to automate the process of determining relationship compatibility based on the given names. Here’s how our Python script accomplishes this:

def calculate_flames(name1, name2):
    name1 = name1.lower().replace(" ", "")
    name2 = name2.lower().replace(" ", "")

    # Count frequency of each letter in both names
    count1 = {}
    count2 = {}
    for letter in name1:
        count1[letter] = count1.get(letter, 0) + 1
    for letter in name2:
        count2[letter] = count2.get(letter, 0) + 1

    # Calculate the number of letters to be eliminated
    total_count = count1.copy()
    for letter in count2:
        if letter in total_count:
            total_count[letter] -= count2[letter]
        else:
            total_count[letter] = -count2[letter]

    # Count the remaining letters
    remaining_count = sum(abs(count) for count in total_count.values())

    # Determine the relationship status
    flames_key = "FLAMES"
    while len(flames_key) > 1:
        index = (remaining_count % len(flames_key)) - 1
        if index >= 0:
            flames_key = flames_key[index + 1:] + flames_key[:index]
        else:
            flames_key = flames_key[:len(flames_key) - 1]

    return flames_key

def display_result(name1, name2, flames_result):
    relationship = {
        'F': 'Friends',
        'L': 'Lovers',
        'A': 'Affectionate',
        'M': 'Marriage',
        'E': 'Enemies',
        'S': 'Siblings'
    }
    print(f"Based on '{name1}' and '{name2}', you are {relationship[flames_result]}!")

def main():
    print("Welcome to the FLAMES game!")
    name1 = input("Enter the first name: ")
    name2 = input("Enter the second name: ")
    flames_result = calculate_flames(name1, name2)
    display_result(name1, name2, flames_result)

if __name__ == "__main__":
    main()

Step-by-Step Explanation of FLAMES Game Implementation

Importing Required Modules

Import the random module to generate random outcomes for the game.

import random

Defining the calculate_flames Function

Define a function calculate_flames to compute the FLAMES result based on two names.

def calculate_flames(name1, name2):
    # Normalize names: convert to lowercase and remove spaces
    name1 = name1.lower().replace(" ", "")
    name2 = name2.lower().replace(" ", "")

    # Count letter frequencies in each name
    count1 = {}
    count2 = {}

    for letter in name1:
        if letter in count1:
            count1[letter] += 1
        else:
            count1[letter] = 1

    for letter in name2:
        if letter in count2:
            count2[letter] += 1
        else:
            count2[letter] = 1

    # Calculate remaining letters after eliminating common ones
    total_count = count1.copy()
    for letter in count2:
        if letter in total_count:
            total_count[letter] -= count2[letter]
        else:
            total_count[letter] = -count2[letter]

    # Determine relationship using the FLAMES method
    flames_key = "FLAMES"
    while len(flames_key) > 1:
        index = (sum(abs(count) for count in total_count.values()) % len(flames_key)) - 1
        if index >= 0:
            flames_key = flames_key[index + 1:] + flames_key[:index]
        else:
            flames_key = flames_key[:len(flames_key) - 1]

    return flames_key

Defining the display_result Function

Define a function display_result to map the FLAMES result to a meaningful relationship status.

def display_result(name1, name2, flames_result):
    relationships = {
        'F': 'Friends',
        'L': 'Lovers',
        'A': 'Affectionate',
        'M': 'Marriage',
        'E': 'Enemies',
        'S': 'Siblings'
    }
    print(f"Based on '{name1}' and '{name2}', you are {relationships[flames_result]}!")

Main Function Execution

Implement the main function to execute the FLAMES game.

def main():
    print("Welcome to the FLAMES game!")
    name1 = input("Enter the first name: ")
    name2 = input("Enter the second name: ")
    flames_result = calculate_flames(name1, name2)
    display_result(name1, name2, flames_result)

if __name__ == "__main__":
    main()

This organized method outlines functions for handling input, calculating the FLAMES outcome systematically, and showing the result to the player.

Every function has a unique purpose in carrying out the game’s logic and revealing the result, guaranteeing clarity and efficiency in the FLAMES game execution.

Enhancing the FLAMES Game

To make the FLAMES game even more engaging, you can consider the following enhancements:

  • Interactive GUI: Implement a graphical user interface (GUI) using libraries like Tkinter to make the game more visually appealing.
  • Multiplayer Mode: Allow multiple players to input their names and compare compatibility with each other.
  • Extended Relationship Insights: Provide additional insights or recommendations based on the relationship status (e.g., compatibility tips).

Interactive GUI using Tkinter

import tkinter as tk
from tkinter import messagebox

def calculate_flames(name1, name2):
    # Implementation of calculate_flames function (as previously defined)

def display_result(name1, name2, flames_result):
    relationships = {
        'F': 'Friends',
        'L': 'Lovers',
        'A': 'Affectionate',
        'M': 'Marriage',
        'E': 'Enemies',
        'S': 'Siblings'
    }
    result = f"Based on '{name1}' and '{name2}', you are {relationships[flames_result]}!"
    messagebox.showinfo("FLAMES Result", result)

def check_flames():
    name1 = entry_name1.get()
    name2 = entry_name2.get()
    if name1 and name2:
        flames_result = calculate_flames(name1, name2)
        display_result(name1, name2, flames_result)
    else:
        messagebox.showwarning("Input Error", "Please enter both names.")

# GUI setup
root = tk.Tk()
root.title("FLAMES Game")

label_name1 = tk.Label(root, text="Enter Name 1:")
label_name1.pack()

entry_name1 = tk.Entry(root)
entry_name1.pack()

label_name2 = tk.Label(root, text="Enter Name 2:")
label_name2.pack()

entry_name2 = tk.Entry(root)
entry_name2.pack()

button_check = tk.Button(root, text="Check Relationship", command=check_flames)
button_check.pack()

root.mainloop()

Multiplayer Mode Implementation

def multiplayer_flames():
    print("Welcome to Multiplayer FLAMES game!")
    player_count = int(input("Enter number of players: "))
    players = []
    for i in range(player_count):
        name = input(f"Enter player {i+1}'s name: ")
        players.append(name)

    results = {}
    for i in range(player_count):
        for j in range(i + 1, player_count):
            flames_result = calculate_flames(players[i], players[j])
            results[(players[i], players[j])] = flames_result

    for (name1, name2), result in results.items():
        print(f"{name1} and {name2} are {result}")

if __name__ == "__main__":
    multiplayer_flames()

Extended Relationship Insights

You can expand the display_result function to provide additional insights or recommendations based on the relationship status returned by calculate_flames.

These enhancements make the FLAMES game more interactive, multiplayer-friendly, and insightful, enhancing user engagement and enjoyment. Adjust and expand these codes as needed to fit your specific implementation and design preferences.

Conclusion

The FLAMES game coded in Python offers an entertaining and enlightening method to delve into relationship compatibility using names.

This program showcases string manipulation and logic in Python while injecting a fun element into understanding relationships.

Whether you’re checking compatibility with a friend, significant other, or a new acquaintance, have fun playing FLAMES and discovering new connections! Enjoy coding!

Categories: Python

0 Comments

Leave a Reply

Avatar placeholder

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