Pages

💡 Now You Can Get your Assignments Sollution here... .💡 100% plagiarism Free Service...💡 Responsibility, punctuality and on-time delivery... 💡 Furnishing you with experts... 💡 experienced in your subject 100% privacy... 💡 helping you with the highest efficiency , professionalism Affordable and budget-friendly costs that do not make a hole in your wallet

Word Search Consol + OpenGL

// Members

// MUEEZ AHMED
// JAHANZAIB
// M.ADEEL
// ADEEL NASIR
// ALI KAMRAN
//GAME WORD SEARCH
#include<iostream>
#include<stdio.h>
#include<string>
#include<fstream>
#include<windows.h>
#include<conio.h>
#include<glut.h>
#include<gl/GL.h>
#include<time.h>



using namespace std;
void random(char**, int*, int*);
void zeros(char**, int*);
void mouse(int, int, int, int);
void display(void);
void createMenu(void);
void output_game(int x, int y, char string);
void continue_game(void);
void menu(int);
void square(void);
void reshape(int, int);
void output(int, int, char *);
void orthogonalStart(void);
void orthogonalEnd(void);
void drawBitmaptime(double, float,float);
void drawBitmapText(char *, float, float);
void remove_old();
void *font = GLUT_BITMAP_TIMES_ROMAN_24;

int count_word = 0;
int *rowcol = new int;
int *word = new int;
string word_found;
char **game = new char*[36];
static int window;
static int menu_id;
int value;
bool mouseleftdown = false;
int mousex, mousey;
double time1=0;


int main(int argc, char **argv)
{
if (remove("wordlist.txt") != 0)
perror("...");
cout << "NOTE::\"Please Close the Game Properly\"\n ";
system("pause\n");
glutInit(&argc, argv);
*rowcol = 17;
*word = 15;
for (int i = 0; i < 36; i++)
{
game[i] = new char[36];
}
zeros(game, rowcol);
random(game, rowcol, word);
cout << "Total Aviable Words are :" << count_word << "\n";
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(720, 650);
window = glutCreateWindow("Word Puzzle");
glClearColor(1.0, 0.2, 0.2, 1.0);
glutDisplayFunc(display);
createMenu();
glutReshapeFunc(reshape);
glutMainLoop();

return EXIT_SUCCESS;
}
void output(int x, int y, char *string)
{
int len, i;
glRasterPos2f(x, y);
len = (int)strlen(string);
for (i = 0; i < len; i++)
{
glutBitmapCharacter(font, string[i]);
}
}
void output_game(int x, int y, char string)
{
glRasterPos2f(x, y);
glutBitmapCharacter(font, string);
}
void orthogonalStart(void)
{
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluOrtho2D(0, 720, 0, 650);
glMatrixMode(GL_MODELVIEW);
}
void orthogonalEnd(void)
{
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
}
void mouse(int button, int state, int x, int y)
{
if (button == GLUT_LEFT_BUTTON)

{
mouseleftdown = (state == GLUT_DOWN);
}
mousex = x;
mousey = y;
int c_mouse = 0;
for (int i = 250; i < 300; i++)
{
if (i == mousey)
{
c_mouse++;
}
}
for (int j = 200; j < 500; j++)
{

if (j == mousex)
{
c_mouse++;
}
}
if (c_mouse == 2)
{
continue_game();
}
c_mouse = 0;
for (int i = 325; i < 375; i++)
{
if (i == mousey)
{
c_mouse++;
}
}
for (int j = 200; j < 500; j++)
{

if (j == mousex)
{
c_mouse++;
}
}
if (c_mouse==2)
{
string val;
string val1;
ifstream out;
out.open("highscore.txt", ios::app);
cout << "Name" << "\t" << "Time" << "\n";
for (int i = 0; i < 10; i++)
{
out >> val;
out >> val1;
cout << val << "\t" << val1 << "\n";
if (out.eof())
break;
}
out.close();
}
c_mouse = 0;
for (int i = 400; i < 450; i++)
{
if (i == mousey)
{
c_mouse++;
}
}
for (int j = 200; j < 500; j++)
{

if (j == mousex)
{
c_mouse++;
}
}
if (c_mouse == 2)
{
int x = MB_DEFBUTTON1;
MessageBox(NULL, L"History Removed", NULL, x);
if (x == 0)
{
remove_old();
}
}
}
void drawBitmapText(char *string, float x, float y)
{
char *c;
glRasterPos2f(x, y);
for (c = string; *c != '\0'; c++)
{
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *c);
}
}
void drawBitmaptime(double time1, float x, float y)
{
glRasterPos2f(x, y);
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_10, time1);
}
void continue_game(void)
{
int c = 0;
string word1;
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.0, 0.0, 1.0);
drawBitmapText("Game Start", 250, -100);
glColor3f(0.0, 0.0, 0.0);
for (int i = 0; i < *rowcol; i++)
{
for (int j = 0; j < *rowcol; j++)
{
output_game(i * 30, j * 30, game[i][j]);
}
}
drawBitmapText("Enter Name on Console", 00, -80);
glutSwapBuffers();

clock_t start = clock();
ifstream in;
do
{
drawBitmaptime(time1, 350, -100);
in.open("wordlist.txt", ios::app);
cout << "Enter word you found :";
cin >> word_found;
for (int i = 0; i < *word+1; i++)
{
in >> word1;

if (word1 == word_found)
{
cout << "\nWord Found\n";
c++;
}
}
in.close();
} while (c != *word);
clock_t end = clock();
double time = (double)(end - start) / CLOCKS_PER_SEC;
time1 = time;
ofstream out;
out.open("highscore.txt", ios::app);
char *name = new char[20];
cout << "You take :" << time << " Sec to End the Game" << endl;
cin.ignore();
cout << "\nEnter your user Name: ";
cin.getline(name, 20, '\n');
out << *name << " " << time << "\n";
out.close();

}
void square(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f(0.0, 1.0, 0.0);
output(325, 50, "Main Menu");
orthogonalStart();
glBegin(GL_QUADS);
glColor3f(0, 0, 1);
glVertex2f(200, 250);
glVertex2f(200, 200);
glVertex2f(500, 200);
glVertex2f(500, 250);
glEnd();
glPopMatrix();
glColor3ub(255, 255, 255);
drawBitmapText("Delete Precious Record", 240, 220);
glFlush();
glTranslatef(0, 75, 0);
glBegin(GL_QUADS);
glColor3f(0, 0, 1);
glVertex2f(200, 250);
glVertex2f(200, 200);
glVertex2f(500, 200);
glVertex2f(500, 250);
glEnd();
glPopMatrix();
cout << endl;
glColor3ub(255, 255, 255);
drawBitmapText("High Score", 300, 220);
glFlush();
glTranslatef(0, 75, 0);
glBegin(GL_QUADS);
glColor3f(0, 0, 1);
glVertex2f(200, 250);
glVertex2f(200, 200);
glVertex2f(500, 200);
glVertex2f(500, 250);
glEnd();
glPopMatrix();
glColor3ub(255, 255, 255);
drawBitmapText("New Game", 300, 220);
glFlush();
glEndList();
orthogonalEnd();
glutSwapBuffers();
glutMouseFunc(mouse);
}
void display(void)
{

glClear(GL_COLOR_BUFFER_BIT);
if (value == 1)
{
glutDisplayFunc(square);
}
if (value == 0)
{
glColor3f(0.0, 1.0, 0.0);
output(325, 50, "Well Come");
output(275, 100, "Word Puzzle Game");
output(125, 170, "Heavy Programming (Dedicated to Ali Kamran)");
output(325, 200, "Members");
output(320, 300, "Ali Kamran");
output(325, 350, "M.Adeel");
output(315, 400, "Adeel Nasir");
output(310, 450, "Jahanzaib");
output(295, 500, "Mueez Ahmad");
output(0, 640, "Right Click for Main Menu");
glutSwapBuffers();
}
}
void reshape(int, int)
{
glViewport(0, 0, 720, 650);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0f, 720, 650, 0.0f, -1.0f, 1.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void menu(int num)
{
if (num == 1)
{
value = num;
glutPostRedisplay();
}
else if (num == 0)
{
glutDestroyWindow(window);
exit(0);
}
}
void createMenu(void)
{
menu_id = glutCreateMenu(menu);
glutAttachMenu(GLUT_RIGHT_BUTTON);
glutAddMenuEntry("Main Menu", 1);
glutAddMenuEntry("Quit", 0);
}
void remove_old()
{
system("cls");
if (remove("highscore.txt") != 0)
perror("...");
else
puts("Files successfully deleted\n");
}
void zeros(char**game,int*rowcol)
{
for (int i = 0; i < *rowcol; i++)
{
for (int j = 0; j < *rowcol; j++)
{
game[i][j] = '0';
}
}
}
void random(char**game, int*rowcol, int*total_word)
{
system("cls");
int c = 0;
int k = 0;
int stringlen;
char a = 'A';
string names = "word_";
names += a;
string t = ".txt";
names += t;
char word[40] = { '\0' };
ifstream in;
in.open(names, ios::app);
ofstream out;
out.open("wordlist.txt", ios::app);
for (int row = 0; row < *rowcol; row++)
{

for (int col = 0; col < *rowcol; col++)
{
int rand1 = rand() % 3;
while (1)
{
c = 0;
in >> word;
stringlen = strlen(word);
if (stringlen <= (*rowcol - 1))
{
c++;
}
if (c == 1)
break;
c = 0;
}
if (rand1 == 0 && c == 1)
{ /*Diagonal Case*/
if (game[row][col] == '0')
{
int temp = row;
int temp1 = col;
if (game[temp][temp1] == '0' || game[temp][temp1] == word[0])
{
c = 0;
for (int j = 0; j < stringlen; j++)
{
if (game[temp][temp1] == '0' || game[temp][temp1] == word[j])
{
temp++;
temp1++;
c++;
}
}
}
if (c == strlen(word))
{
k++;
temp = row;
temp1 = col;
for (int j = 0; j < stringlen; j++)
{
game[temp][temp1] = word[j];
temp++;
temp1++;
}
for (int i = 0; i < strlen(word); i++)
{
if (i == 0 || i == rand() % strlen(word) || i == strlen(word)-1)
cout << word[i];
else
cout << "*";
}
cout << "\n";
out << word << "\n";
count_word++;
}
}
}
if (rand1 == 1 && c == 1)
{ /*Top to bottom*/
int temp = row;
if (game[temp][col] == '0' || game[temp][col] == word[0])
{
c = 0;
for (int j = 0; j < stringlen; j++)
{
if (game[temp][col] == '0' || game[temp][col] == word[j])
{
c++;
temp++;
}
}
}
if (c == strlen(word))
{
k++;
temp = row;
for (int j = 0; j < stringlen; j++)
{
game[temp][col] = word[j];
temp++;
}
for (int i = 0; i < strlen(word); i++)
{
if (i == 0 || i == rand() % strlen(word) || i == strlen(word) - 1)
cout << word[i];
else
cout << "*";
}
cout << "\n";
out << word << "\n";
count_word++;
}
}
if (rand1 == 2 && c == 1)
{ /*Left to Right Case*/
int temp = col;
if (game[row][temp] == '0' || game[row][temp] == word[0])
{
c = 0;
for (int j = 0; j < stringlen; j++)
{
if (game[row][temp] == '0' || game[row][temp] == word[j])
{
c++;
temp++;
}
}
}
if (c == strlen(word))
{
k++;
temp = col;
for (int j = 0; j < stringlen; j++)
{
game[row][temp] = word[j];
temp++;
}
for (int i = 0; i < strlen(word); i++)
{
if (i == 0 || i == rand() % strlen(word) || i == strlen(word) - 1)
cout << word[i];
else
cout << "*";
}
cout << "\n";
out << word << "\n";
count_word++;
}
}
if (k <= *total_word && row == (*rowcol) - 1 && col == (*rowcol) - 1)
{
row = 0;
col = 0;
}
if (k > *total_word)
{
row = *rowcol;
col = *rowcol;
}
}
}
for (int i = 0; i < *rowcol; i++)
{
for (int j = 0; j < *rowcol; j++)
{
if (game[i][j] == '0')
{
game[i][j] = rand() % 24 + 65;
}
}
}
out.close();
in.close();
}


// A Word File name word_A required for this code https://drive.google.com/file/d/0B-J4D854FwVRSjZsaXhfY01qWk0/view?usp=sharing copy words and paste in text file named word_A.txt...
// Open GL Required...

No comments: