How to Build The Flames Love Calculator Game in C#

Written by ssukhpinder | Published 2023/02/17
Tech Story Tags: csharp | dotnet | dotnet-core | game | programming | c-sharp | coding | coding-skills | web-monetization

TLDRThe Flames Love Percentage Game is a fun way to calculate your love percentage with your partner, crush, or someone you’re interested in. In the game, the letters in the word “FLAMES” are used to determine the relationship between two people. To create the Flames game in C#, we’ll create a console application that prompts users to enter their partner name to calculate love percentage. We then calculate the result using the algorithm outlined above, and display the result to the user.via the TL;DR App

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:

  1. Write down your name and your partner’s name.
  2. Cross out all the letters that appear in both names.
  3. Count the remaining letters.
  4. Starting with “F”, count up to the number of remaining letters.
  5. When you reach the letter, cross it out and return to “F”.
  6. Continue counting and crossing out letters until only one letter remains.
  7. The letter that remains is the result of your Flames game.

Result letter meaning

  • F — Friends
  • L — Lovers
  • A — Affectionate
  • M — Marriage
  • E — Enemies
  • S — Siblings

Now that you know how the game works, let’s look at how to implement it in C#.

Implementing the Flames Game 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.

Here’s the code for the Flames game in C#:

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;
    }
}

Let’s go through the code step by step

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);

Conclusion

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.



Written by ssukhpinder | Programmer by heart | C# | Python | .Net Core | Xamarin | Angular | AWS
Published by HackerNoon on 2023/02/17