Clippy Game using c++ programming


 #include <iostream>

#include <conio.h>

#include <cstdlib>

#include <ctime>

#include <string>

#include <sstream> 

using namespace std;

void guide();

void body();

void display(char[][9]); 
// For display of screen

void Hint(int);

int main()
{


char choice;

body();
	
cout << "Enter N for new game Q to quit the game";
	
cin >>  choice;
	
if (choice == 'N' || choice == 'n')
	
{
		
system("cls");
		
body();
	}
	
else if (choice == 'q' || choice == 'Q')
	
{
		
exit(0);
	
}

}


void body()

{
	
srand(time(0));
	
int x, y;
	
int arr[9][9];
	
string enter;
	
char ar[9][9]{ { '.', '.', '.', '.', '.', '.', '.', '.', '.' },
	{ '.', '.', '.', '.', '.', '.', '.', '.', '.' },
	{ '.', '.', '.', '.', '.', '.', '.', '.', '.' 

},
	{ '.', '.', '.', '.', '.', '.', '.', '.', '.' },
	{ '.', '.', '.', '.', '.', '.', '.', '.', '.' },
	{ '.', '.', '.', '.', '.', '.', '.', '.', '.' 

},
	{ '.', '.', '.', '.', '.', '.', '.', '.', '.' },
	{ '.', '.', '.', '.', '.', '.', '.', '.', '.' },
	{ '.', '.', '.', '.', '.', '.', '.', '.', '.' 

} };;
	
x = (rand() % 9) + 1; 
//Generate first random number as Row.

y = (rand() % 9) + 1; 
//Generate first random number as Column.
	
string s1 = to_string(x);
 //Convert the string into integer
	
string s2 = to_string(y);
	
string s = s1 + s2;
	
int c = stoi(s);
	
guide();
	
display(ar);
	
for (int i = 0; i < 5; i++)
	
{
		
cout << endl;
		
cout << "Enter the Row & Column " << endl;
		
cout << endl;
		
getline(cin, enter);
		
stringstream geek(enter);
		
int convert = 0;
		
geek >> convert;

		
if (convert == c)
		
{
			
ar[x][y] = 'C';
			
display(ar);
			
cout << ".....Gameover" << endl;
			
cout << "You Found the clippy";
			
exit(0);
		}
		
else {
			
// Break the string into two int variables
			
int n1 = convert % 10;
			
convert /= 10;
			
int n2 = convert % 10;
			
convert /= 10;
			
//n2 used as row and n1 used as column
			
ar[n2][n1] = 'x';
			
display(ar);
			
cout << endl;
			
cout << endl;
			
cout << "\t\t\t\t\tTurns=" << i + 1 << "\t\t\t";
			
Hint(c);
		}
	}
	
cout << endl;
	cout << "You failed to found the clippy";
	
cout << endl;
	ar[x][y] = 'C';
	
display(ar);
}

void Hint(int c)
{
	
if (c == 04 || c == 14 || c == 24 || c == 34)
	
{
		
cout << "Hint: North";
	}
	
else if (c == 54 || c == 64 || c == 74 || c == 84)
	
{
		
cout << "Hint: South";
	}
	
else if (c == 48 || c == 47 || c == 46 || c == 45)
	{
		
cout << "Hint: East";
	}
	
else if (c == 40 || c == 41 || c == 42 || c == 43)
	
{
		cout << "Hint: West";
	}
	
else if (c == 05 || c == 06 || c == 07 || c == 8 || c == 15 || c == 16 || c == 17 || c == 18 || c == 25 || c 

== 26 || c == 27 || c == 28 || c == 35 || c == 36 || c == 37 || c == 38)
	{
		

cout << "Hint: North-East";
	}
	
else if (c == 00 || c == 01 || c == 03 || c == 11 || c == 02 || c == 10 || c == 12 || c == 20 || c == 13 || c 

== 21 || c == 23 || c == 22 || c == 31 || c == 32 || c == 33 || c == 30)
	{
		

cout << "Hint: North-west";
	}
	
else if (c == 50 || c == 51 || c == 52 || c == 53 || c == 60 || c == 61 || c == 63 || c == 62 || c == 70 || 

c == 71 || c == 72 || c == 73 || c == 80 || c == 81 || c == 82 || c == 83)
	{
		

cout << "Hint: South-West";
	}
	
else if (c == 56 || c == 55 || c == 58 || c == 65 || c == 57 || c == 77 || c == 78 || c == 66 || c == 86 || 

c == 87 || c == 88 || c == 85 || c == 76 || c == 75 || c == 68 || c == 67)
	{
		

cout << "Hint: South-East";
	
}
}

void display(char arr[][9])
{
	
cout << "\t\t\t\t\t\t" << "   " << "  0 " << " 1 " << " 2 " << " 3 " << " 4 " << " 5 " << " 6 " << " 7 " << " 8 " << endl 

<< endl;
	
for (int i = 0; i < 9; i++)
	
{
		
cout << "\t\t\t\t\t\t" << i << "    ";
		
for (int j = 0; j < 9; j++)
		
{
			
cout << arr[i][j] << "  ";
		}
		
cout << endl;
	}
}
void guide()
{
	
cout << "\t\t\tFINDING CLIPPY!!\t\t\n\n\n";
	
cout << "In this game you will find clippy that is hidden somewhere in the 

board.\n";
	
cout << "\t\tyou get '5' tries  to find clippy,thats your mission.\n";
	
cout << "You will enter row number(0 to 8) and coloumn number (0-8) to find 

the clippy" << endl;
	
cout << "\t\t\tEnjoy the Game\t\t\n\n";
}    

          

       
 

Comments

Popular posts from this blog

Multiple inheritance,friend function and multiple file in oop(object oriented programming)

Concepts of OOP (object oriented programming)

Concepts in c++........