The classic game is a fun way to calculate your love percentage with your partner, crush, or someone you’re interested in. It used to be how crushes were vetted in high school. This article will show you how to create a Flames Love Percentage Game using C#.
The game is based on the acronym FLAMES, which stands for Friends, Lovers, Affectionate, Marriage, Enemies, and Siblings.
In the game, the letters in the word “FLAMES” are used to determine the relationship between two people. Here’s how it works:
Now that you know how the game works, let’s look at how to implement it in C#.
To create the Flames game in C#, we’ll create a console application that prompts users to enter their partner’s name to calculate love percentage. We’ll then calculate the Flames result using the algorithm outlined above, and display the result to the user.
using System;
class FlamesGame
{
static void Main(string[] args)
{
Console.WriteLine("Welcome to the Flames game!");
Console.Write("Enter your name: ");
string yourName = Console.ReadLine();
Console.Write("Enter your partner's name: ");
string partnerName = Console.ReadLine();
string flamesResult = CalculateFlames(yourName, partnerName);
Console.WriteLine("Your Flames result is: " + flamesResult);
}
static string CalculateFlames(string yourName, string partnerName)
{
string flames = "FLAMES";
int count = yourName.Length + partnerName.Length;
for (int i = 0; i < yourName.Length; i++)
{
for (int j = 0; j < partnerName.Length; j++)
{
if (yourName[i] == partnerName[j])
{
count -= 2;
yourName = yourName.Remove(i, 1);
partnerName = partnerName.Remove(j, 1);
i--;
break;
}
}
}
int index = 0;
for (int i = 1; i <= 5; i++)
{
index = (index + count) % flames.Length;
if (index == 0)
{
index = flames.Length;
}
flames = flames.Remove(index - 1, 1);
}
return flames;
}
}
We start by displaying a welcome message to the user and prompting them to enter their name and their partner’s name using the Console.ReadLine()
method.
Console.WriteLine("Welcome to the Flames game!");
Console.Write("Enter your name: ");
string yourName = Console.ReadLine();
Console.Write("Enter your partner's name: ");
string partnerName = Console.ReadLine();
Next, we pass the user’s names to the CalculateFlames()
method, which performs the actual calculation of the result.
string flamesResult = CalculateFlames(yourName, partnerName);
The CalculateFlames()
method first removes all the standard letters from the two names by iterating through the letters in each name and removing the letters that appear in both names. It also keeps a count of the remaining letters.
static string CalculateFlames(string yourName, string partnerName)
{
string flames = "FLAMES";
int count = yourName.Length + partnerName.Length;
for (int i = 0; i < yourName.Length; i++)
{
for (int j = 0; j < partnerName.Length; j++)
{
if (yourName[i] == partnerName[j])
{
count -= 2;
yourName = yourName.Remove(i, 1);
partnerName = partnerName.Remove(j, 1);
i--;
break;
}
}
}
Next, the method uses a loop to iterate through the letters in “FLAMES” and remove the letter corresponding to the count. It removes letters until only one remains, which is the final result of the Flames game.
int index = 0;
for (int i = 1; i <= 5; i++)
{
index = (index + count) % flames.Length;
if (index == 0)
{
index = flames.Length;
}
flames = flames.Remove(index - 1, 1);
}
return flames;
Finally, the method returns the Flames result, which is then displayed to the user.
Console.WriteLine("Your Flames result is: " + flamesResult);
This article demonstrates how to create a Flames Love Percentage Game using C#. By following the steps outlined in this article, you should now be able to create your own Flames game in C#.
We hope you found this article helpful, and if you have any questions or comments, please leave them below!
Also published here.