hi.. i'm new here
i try to do bingo program in separated file but my class name is not declare.. i search on internet on how to solve it but still gives me error
can some one help me???
#ifndef BINGO_H
#define BINGO_H
#include<iostream>
#include<stdlib.h>
#include <time.h>
#include <string.h>
using namespace std;
class game
{
public:
void display();
void rules();
void gen_rand(int size, int* array);
void print_map(int size, int array[]);
void start(int size, int* array, int x);
void play(int* array1, int* array2, int size, int x);
void word( int* array1, int* array2, int size);
game();
private:
int size=25;
int P1[size];
int P2[size];
int x;
int y;
int num;
char bingo1[]=" ";
char bingo2[]=" ";
char choice;
};
#endif
#include<iostream>
#include<stdlib.h>
#include <time.h>
#include <string.h>
#include "BINGO.h"
using namespace std;
game::game()
{
}
void game::display()
{
system("cls");
cout <<"WELCOME TO BINGO" << endl<< endl;
cout <<"+-----------------------------------+" << endl;
cout <<"|Select: |" << endl;
cout <<"|1 => Rules |" << endl;
cout <<"|2 => Play |" << endl;
cout <<"|Q => Quit |" << endl;
cout <<"+-----------------------------------+" << endl;
cout <<"Number selected:";
}
void game::rules()
{
cout << endl;
cout <<"This game require 2 players.\nEach player is holding 25 numbers (1-25).\nThey will plot these numbers randomly on a 5 by 5 square plane.\nPlayer 1 will guess a number both the players must mark this\nnumber on their square planes.\nNext, player 2 will do the guessing and both the players will mark the\nguessed number on their planes. E.g. " << endl;
cout <<endl;
cout <<"Assume that player 1 has the following plane:"<< endl;
cout <<"1 8 6 18 17" << endl;
cout <<"14 11 16 5 22" << endl;
cout <<"20 2 10 24 13" << endl;
cout <<"4 15 25 19 23" << endl;
cout <<"9 21 3 12 7" << endl;
cout <<endl;
cout <<"and player 2 has the following plane:" << endl;
cout <<"25 13 17 21 22" << endl;
cout <<"1 24 4 16 12" << endl;
cout <<"2 8 11 9 5" << endl;
cout <<"20 19 23 15 18" << endl;
cout <<"7 14 3 10 6" << endl;
cout <<endl;
cout <<"Player 1 guesses number 10 and both player\nwill plat the number in their plane." << endl;
cout <<"Player 1 plane" << endl;
cout <<"1 8 6 18 17" << endl;
cout <<"14 11 16 5 22" << endl;
cout <<"20 2 X 24 13" << endl;
cout <<"4 15 25 19 23" << endl;
cout <<"9 21 3 12 7" << endl;
cout <<"Player 2 plane" << endl;
cout <<"25 13 17 21 22" << endl;
cout <<"1 24 4 16 12" << endl;
cout <<"2 8 11 9 5" << endl;
cout <<"20 19 23 15 18" << endl;
cout <<"7 14 3 X 6" << endl;
cout <<endl;
cout <<"The game goes on.\nAssume that player 1 square plane has the following pattern" << endl;
cout <<"1 8 6 18 X" << endl;
cout <<"14 11 16 X 22" << endl;
cout <<"20 2 X 24 13" << endl;
cout <<"4 X 25 19 23" << endl;
cout <<"X 21 3 12 7" << endl;
cout <<endl;
cout <<"This indicates that, player 1 got B from the B-I-N-G-O letters.\nPlayer 1 will win the game if he manages to guess \nthe correct numbers to obtain all the 5 letters before player 2. E.g." << endl;
cout <<"X X X X X" << endl;
cout <<"X 11 X X 22"<< endl;
cout <<"X 2 X 24 13" << endl;
cout <<"X X X X X" << endl;
cout <<"X 21 X 12 7" << endl;
system("pause");
}
void game::gen_rand(int size, int* array)
{
srand ( time(NULL) );
for(int x=0; x<size; x++) {
array[x] = rand()%25 + 1; //generate random number between 1-25 for array
for(int y=0; y<x; y++) {
if(array[y]== array[x]){
x=x-1;
y=x;}
}
}
}
void game::print_map(int size, int array[])
{
int x;
cout<<endl; // ________________________
cout<<"\t\t ________________________"<<endl; // | | | | | |
cout<<"\t\t| | | | | |\n"; // | 0 | 1 | 2 | 3 | 4 |
for(x=0; x<size; x++) { // |____|____|____|____|____|
// | | | | | |
if(x%5==0) // | 5 | 6 | 7 | 8 | 9 |
cout<<"\t\t| "; // |____|____|____|____|____|
if (array[x]!=0) // | | | | | |
cout << array[x]; // | 10 | 11 | 12 | 13 | 14 |
else // |____|____|____|____|____|
cout<<"X"; // | | | | | |
if(array[x]<10) // | 15 | 16 | 17 | 18 | 19 |
cout<<" "; // |____|____|____|____|____|
cout<<" | "; // | | | | | |
if((x+1)%5==0 && x!= 24) { // | 20 | 21 | 22 | 23 | 24 |
cout<<endl<<"\t\t|____|____|____|____|____|"; // |____|____|____|____|____|
cout<<endl<<"\t\t| | | | | |"<<endl;}
if (x==24)
cout<<endl<<"\t\t|____|____|____|____|____|"<<endl;
}
}
void game::start(int size, int* array, int p)
{
char choice;
bool proceed = false; //set proceed = 0//
do
{
cout<<"\n\tPlayer "<<p<<" please press any key to view your plane...\n\n";
system("pause");
system("cls");
gen_rand(size, array);
print_map(size, array);
bool invalid = false;
do{
cout<<"\n\tDo you want to keep this plane and proceed? (y/n) :";
cin>>choice;
if(choice=='y' || choice=='Y') {
cout<<"\n\tThis will be your plane!\n\n";
invalid = true;
proceed = true; }
else if(choice =='n' || choice=='N')
invalid = true;
else {
cout<<"\tInvalid choice..";
invalid = false;}
}
while (!invalid); // terminate the program//
}
while (!proceed); // terminate the program//
(system("pause"));
}
void game::ins_x(int size, int* array, int num)
{
int x;
for(x=0; x<size; x++) {
if (array[x]==num){
array[x]=0;
x=size;}
}
}
void game::check_bin( int* array, char* string, int start, int end, int add)
{
int x, count=0;
for(x=start; x<=end; x+=add) {
if(array[x]==0)
count++;}
if(count==5){
for(x=0; x<5; x++){
if(string[x]==' ') {
switch(x) {
case 0: string[0]='B';
break;
case 1: string[1]='I';
break;
case 2: string[2]='N';
break;
case 3: string[3]='G';
break;
case 4: string[4]='O';
break;
default: break;}
//x=5;
}
}
}
}
void game::check_end(int* array, char* string)
{
check_bin(array, string, 0,4,1);
check_bin(array, string, 5,9,1);
check_bin(array, string, 10,14,1);
check_bin(array, string, 15,19,1);
check_bin(array, string, 20,24,1);
check_bin(array, string, 0,20,5);
check_bin(array, string, 1,21,5);
check_bin(array, string, 2,22,5);
check_bin(array, string, 3,23,5);
check_bin(array, string, 4,24,5);
check_bin(array, string, 0,24,6);
check_bin(array, string, 4,20,4);
}
void game::play(int size, int* array1, int* array2, char* string1, char* string2, int p1, int p2, bool &done, bool &replay )
{
int num;
system("cls");
cout<<"\n\tPlayer "<<p1<<" ready?\n\n";
system("pause");
system("cls");
print_map(size, array1);
cout<<"\n\t\t"<<string1<<endl<<endl;
strncpy(string1, " ", 5);
bool valid = true;
do{
cout<<endl<<"\tPlayer "<<p1<<" please choose a number(1-25): ";
cin>>num;
if(num<1 || num>25){
cout<<"\tInvalid number!";
valid = false;}
else
valid = true;
} while(!valid);
ins_x(size, array1, num);
ins_x(size, array2, num);
check_end(array1, string1);
strncpy(string2, " ", 5);
check_end(array2, string2);
system("cls");
print_map(size, array1);
cout<<"\n\t\t"<<string1<<endl<<endl;
if(strncmp (string1, "BINGO",5) == 0) {
system("cls");
cout <<"\n\t\tPlayer "<<p1<<endl;
print_map(size, array1);
cout<<"\n\t\t"<<string1<<endl<<endl;
cout <<"\n\t\tPlayer "<<p2<<endl;
print_map(size, array2);
cout<<"\n\t\t"<<string2<<endl<<endl;
cout <<"\n\t\tCONGRATULATIONS!!!\n\n\tPlayer "<<p1<<" WON!!!!\n";
system("pause");
}
}
#include<iostream>
#include<stdlib.h>
#include <time.h>
#include <string.h>
#include "BINGO.h"
using namespace std;
int main()
{
game().display();
game().rules();
game().gen_rand(int size, int* array);
game().print_map(int size, int array[]);
game().start(int size, int* array, int x);
game().play(int* array1, int* array2, int size, int x);
game().word( int* array1, int* array2, int size);
return 0;
}