Header Ad

C++ program to create a game [Find Hidden Word]

In this post, we will write a C++ program to create a game [Find Hidden Word]. The first user will enter a word that is not more than 10 characters long. after that in that he will enter a character and the program will check if that character is available in the word. if the character is available then the program will print that character. as you could see in the below given image in output section 

C++ program to create a game [Find Hidden Word]


C++ program to create a game [Find Hidden Word]

#include<iostream>
#include<conio.h>
#include<windows.h>

BOOL gotoxy(const WORD x, const WORD y) {
    COORD xy;
    xy.X = x;
    xy.Y = y;
    return SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), xy);
}


int main()
{
    system("cls");

    char a[10],b[10];
    int i,n,j,k,p,no;

    std::cout<<"Enter the word of maximum ten characters = ";
    std::cin>>a;

    system("cls");

    k=0;

    while(a[k] != '\0')
    {
        gotoxy(40+k,3);
        std::cout<<"-";
        k++;
    }

    no = k*2;
    gotoxy(70,1);
    std::cout<<no;
    p=0;

    for(int m=1;m<=2;m++)
    {
        i=0;

        while(a[i] != '\0')
        {
            gotoxy(1,1);
            std::cout<<"Enter any character = ";
            b[i] = getch();

            if(b[i] == a[0])
            {
                gotoxy(40,3);
                std::cout<<b[i]<<std::endl;
                p++;
            }
            if(b[i] == a[1])
            {
                gotoxy(41,3);
                std::cout<<b[i]<<std::endl;
                p++;
            }
            if(b[i] == a[2])
            {
                gotoxy(42,3);
                std::cout<<b[i]<<std::endl;
                p++;
            }
            if(b[i] == a[3])
            {
                gotoxy(43,3);
                std::cout<<b[i]<<std::endl;
                p++;
            }
            if(b[i] == a[4])
            {
                gotoxy(44,3);
                std::cout<<b[i]<<std::endl;
                p++;
            }
            if(b[i] == a[5])
            {
                gotoxy(45,3);
                std::cout<<b[i]<<std::endl;
                p++;
            }
            if(b[i] == a[6])
            {
                gotoxy(46,3);
                std::cout<<b[i]<<std::endl;
                p++;
            }
            if(b[i] == a[7])
            {
                gotoxy(47,3);
                std::cout<<b[i]<<std::endl;
                p++;
            }
            if(b[i] == a[8])
            {
                gotoxy(48,3);
                std::cout<<b[i]<<std::endl;
                p++;
            }
            if(b[i] == a[9])
            {
                gotoxy(49,3);
                std::cout<<b[i]<<std::endl;
                p++;
            }
            no--;
            gotoxy(70,1);
            std::cout<<no;
            i++;
            gotoxy(1,1);
        }
    }

    std::cout<<"Your correct sentence = "<<a;

    getch();
    return 0;
}



Output

C++ program to create a game [Find Hidden Word]


Post a Comment

0 Comments