How To Build Flames Game In Python

Home » Coding » How To Build Flames Game In Python

Flames Game in Python is a fun technique to determine two people’s relationship status. It is based on the famous game FLAMES, which stands for Friends, Lovers, Affectionate, Marriage, Enemies, and Sibling. This article will give you a brief overview of How To Build Flames Game In Python.

Introduction

In this game, you must enter two names and then eliminate the common letters based on their occurrences. The leftover letters are enumerated and utilized individually to delete the letters in FLAMES. The outcome is the final letter that remains.

 

Objectives

Python is a versatile language with a wide range of applications. It is capable of performing diverse tasks, including game development. In this instance, we will develop a basic FLAMES game without relying on external libraries such as PyGame.

This game will be developed based on the following steps:

1. Take the two names.

2. Remove the common characters with their respective common occurrences.

3. Get the count of the characters that are left.

4. Take FLAMES letters as [“F”, “L”, “A”, “M”, “E”, “S”]

5. Start removing letters using the count we got.

6. The letter which lasts the process is the result.

Requirements

1. You must have a basic understanding of Python.

2. Any text editor or Visual Studio Code

3. To run and build the Python code on your machine, you will need a Python Environment.

Source Code

# function for removing common characters
# with their respective occurrences
def remove_match_char(list1, list2):
for i in range(len(list1)):
for j in range(len(list2)):
# if the common character is found
# then remove that character
# and return list of concatenated
# list with True Flag
if list1[i] == list2[j]:
c = list1[i]
# remove character from the list
list1.remove(c)
list2.remove(c)
# concatenation of two list elements with *
# * is act as border mark here
list3 = list1 + ["*"] + list2
# return the concatenated list with True flag
return [list3, True]
# no common characters is found
# return the concatenated list with False flag
list3 = list1 + ["*"] + list2
return [list3, False]
# Driver code
if __name__ == "__main__":
# take first name
p1 = input("Player 1 name : ")
# converted all letters into lower case
p1 = p1.lower()
# replace any space with empty string
p1.replace(" ", "")
# make a list of letters or characters
p1_list = list(p1)
# take 2nd name
p2 = input("Player 2 name : ")
p2 = p2.lower()
p2.replace(" ", "")
p2_list = list(p2)
# taking a flag as True initially
proceed = True
# keep calling remove_match_char function
# until common characters is found or
# keep looping until proceed flag is True
while proceed:
# function calling and store return value
ret_list = remove_match_char(p1_list, p2_list)


# take out concatenated list from return list
con_list = ret_list[0]


# take out flag value from return list
proceed = ret_list[1]
# find the index of "*" / border mark
star_index = con_list.index("*")
# list slicing perform
# all characters before * store in p1_list
p1_list = con_list[: star_index]
# all characters after * store in p2_list
p2_list = con_list[star_index + 1:]
# count total remaining characters
count = len(p1_list) + len(p2_list)
# list of FLAMES acronym
result = ["Friends", "Love", "Affection", "Marriage", "Enemy", "Siblings"]
# keep looping until only one item
# is not remaining in the result list
while len(result) > 1:
# store that index value from
# where we have to perform slicing.
split_index = (count % len(result) - 1)
# this steps is done for performing
# anticlock-wise circular fashion counting.
if split_index >= 0:
# list slicing
right = result[split_index + 1:]
left = result[: split_index]
# list concatenation
result = right + left
else:
result = result[: len(result) - 1]
# print final result
print("Relationship status :", result[0])

Explanation of the Code

1. We started the game by taking input for the first name, Player 1 name.

2. Then, we converted all of the letters into lowercase and replaced any space with an empty string.

3. Next, we made a list of all of the letters in Player 1’s name.

4. After that, we took the input for the second name, Player 2 name.

5. Again, we converted all of the letters into lowercase and replaced any space with an empty string.

6. Next, we created a list of characters from both players’ names.

7. Further, we started by setting the proceed flag to True.

8. Then we called the remove_match_char() function on each list.

9. The function remove_match_char() scans both lists to identify shared characters and eliminates them.

10. If there are no shared characters, the “proceed” variable is set to False, and the loop terminates.

11. If identical characters are discovered, the index of the “*” border mark is stored in ret_list[0]. The flag value (True) is stored in ret_list[1], and the index of the character’s occurrence in either p1_list or p2_list is stored in star_index, depending on the list used.

12. After eliminating the shared characters from both p1_list and p2_list.

13. We first took in two player names as input.

14. Next, each name’s letters are converted to lowercase.

15. Finally, any spaces are replaced with an empty string.

16. A list of these strings is then created.

17. Next, the remove_match_char function is called once for each list.

18. This function looks for a common character between the two lists and removes it.

19. If no common characters are found, the return value is [list1, False], and then proceed flag is set to True.

20. If a familiar character is found, the return value is [list3, True], and then proceed flag is set to False.

21. Finally, the concatenated list is returned with either [list3, True].

Output

Flames Game In Python

Conclusion

Hence, we have successfully built the Python application to build the Flames game in Python, which is quite exciting and fun to play with your friends.

More Python Projects>>>

You May Also Like To Create…

0 Comments

Submit a Comment

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