Trybotics Logo

FLAMES Using C++

DESCRIPTION

Hello friends, We all know about the flames game. Lol, It's one of the funniest games that made our childhood more happier. In this instructable, we are going to see how to code a flames program using the C++ language.

Description:

Here I used the Circular doubly linked list.

Description:

int main()
{  
string name1,name2;
  int n1,n2;
  cout<<"ENTER FIRST NAME:";
  getline(cin,name1);
  cout<<"ENTER SECOND  NAME:";
  getline(cin,name2);
}

First, we need to get the two names with space so I use the getline() function to get the string with space.

Description:

void emit(string &a)
{
 
 for(int i=0;a[i]!='\0';i++) 
 {
    
      if(a[i]>='a'&&a[i]<='z') {}
      else if(a[i]>='A'&&a[i]<='Z'){} 
      else
      
         a[i]='0';
  
} 
}

Now, we need to remove the special characters like &, $, ' ' ...etc. By using this function we removed all characters other than alphabets. Here, instead of removing, I replace it with '0'.

Description:

 for(i=0;name1[i]!='\0';i++)
   
for(j=0;name2[j]!='\0';j++)
      
 if((name1[i]==name2[j] || name1[i]==name2[j]+32))
      
 {
          
     name1[i]='0';
           
     name2[j]='0';
          
      break;
       
}

It is the first step of the flames game, That we need to remove the same characters that present in the two names. This code snippet helps us to replace the same characters by '0' and it also works well even it contains both the uppercase and lower case. The break statement helps us to avoid the removal of repeating characters.

j=0;<br>for(i=0;name1[i]!='\0';i++)
     
     if(name1[i]!='0')
        
          j++;
  
for(i=0;name2[i]!='\0';i++)
      
     if(name2[i]!='0')
        
          j++;
if(j==0)<br>    cout<<"NO FLAMES";

Here, we remove all '0's that are present in both names. Therefore, finally, all the same, characters are removed. Then the j is incremented that it is the count of the letters that are present in both names after removing the same characters. Now we need to check whether it contains at least one character or not. To make the code efficient we need to tell there is no possibility to play the flames game if it contains no unique characters.

Description:

string a="flames";

First, create a global string that contains "flames".

typedef struct node<br>{
    
    char data;
    
    node *next,*prev;
}node; 
node *top=NULL,*temp;

Now, create a structure that contains a character data, next address pointer, and previous address pointer.

Then create a pointer that points towards the top of the linked list.

node* ins(char a)<br>{
    
node *new1;
    
new1=new node;
    
new1->data=a;
    
new1->next=NULL;
    
new1->prev=NULL;
    
if(top==NULL)
    
{
        
      top=new1;
        
      temp=top;
}
    
else
   
{
        
temp->next=new1;
        
new1->prev=temp;
       
 temp=new1;
    
}
   
 return top; 
}

Then, insert the "flames" string into the doubly linked list by characterwise.

void check(int j)<br>{      
int count1,flag=0;      
for(int i=0;a[i]!='\0';i++)     
    
top=ins(a[i]);
}

Description:

void check(int j)
{
    
int count1,flag=0;
    
for(int i=0;a[i]!='\0';i++)
    
    top=ins(a[i]);
   
 node *cur=top,*prev1;
    
temp->next=top;
   
 top->prev=temp;
    
while(1)
    
{
    
   count1=1;
   
    while(count1<j)
{
       cur=cur->next;
        
       count1++;
   
 }
    
node *temp1=cur;
   
 prev1=cur->prev;
    
cur->prev->next=cur->next;
    
cur->next->prev=cur->prev;
    
temp1->next=NULL;
    
free(temp1);
   
 cur=prev1->next;
    
node *test=cur;
    
if(test->data==test->next->data)
        
break;
    
}
}

we need to run the circular list that is the "flames" string according to the count of unique characters. Then we need to remove the character in "flames" that coincide with the count. We should realize the usage of a doubly linked list in this code snippet. It helps a lot to remove a particular character. It removes continuously. Until it reaches the condition that the same characters come repeatedly.

if(test->data==test->next->data)
break;

Description:

switch(cur->data)

{

case 'f':cout<<"FRIENDS&&";

break;

case 'l':cout<<"LOVE<3";

break;

case 'a':cout<<"AFFECTION$";

break;

case 'm':cout<<"MARRIAGE:)";

break;

case 'e':cout<<"ENEMY:(";

break;

case 's':cout<<"SIBLING";

break; }

Use this switch statement to tell the final result that is the last character remains after removing all other characters according to the count.

Now you can play flames easily by just entering the names, It's funny right. Play this game using your friend's names and make them angry LOL. Thank you.

Description:

The complete code for FLAMES is available here,

https://github.com/naveeen684/Flames-code-using-C-/tree/master


YOU MIGHT ALSO LIKE