Mar 27, 2013 at 3:44pm UTC
i have project with guess word game. I have done a Beginner . Game including 3 level is beginner,Intermediate,Complex be saved in 3 file text. I need your help about the selected level of the game and complete the code for the two rest. thank you very much
Beginner.txt : have#loca#test#team#anal#tool#edit#file#help#auto#
:
#include<iostream>
#include<fstream>
#include<time.h>
using namespace std;
class GameVOC
{
public:
void ShowWord(int arr1[10],char arrword[10][4],int arr2[10],char arr3[10]);
void GetWord(char arr[10][4]);
void generateRandomNumbers(int arr[],int a);
void GetSlution(int arr1[10],int arr2[10],char arrword[10][4],char arr3[10]);
};
void GameVOC::generateRandomNumbers(int arr[10],int a)
{
int i = 0,j=0;
int flag = 0;
int chk = 0;
time_t t;
int rnd;
srand((unsigned) time(&t));
while (chk < 10)
{
rnd=rand()%a;
if (i == 0)
{
arr[i++] = rnd;
chk++;
}
else
{
if(a==4 && chk==3)
j=3;
if(a==4 && chk==7)
j=7;
for(j; j < i; j++)
{
if (arr[j] == rnd)
{
flag = 1;
break;
}
}
if (flag!=1)
{
arr[i++] = rnd;
chk++;
}
}
flag = 0;
}
}
void GameVOC::GetWord(char arr[10][4])
{
ifstream ob("beginner.txt");
int i=0,j=0;
char ch;
while(ob)
{
ob.get(ch);
if(ch!='#')
{
arr[i][j++]=ch;
}
else
{
i++;
j=0;
}
}
ob.close();
}
void GameVOC::ShowWord(int arr1[10],char arrword[10][4],int arr2[10],char arr3[10])
{
int no1=0, no2=0,dem=0;
char x;
for(int i=0;i<10;i++)
{
no1=arr1[i];
no2=arr2[i];
for(int k=0;k<4;k++)
{
if(k!=no2)
cout<<arrword[no1][k];
else
cout<<"...";
}
cout<<"\n"<<"tra loi: ";
cin>>x;
if(arr3[i]==x)
dem=dem+1;
cout<<endl;
}
cout<<"ban tra loi duoc"<<dem<<" cau"<<endl;
}
void GameVOC::GetSlution(int arr1[10],int arr2[10],char arrword[10][4],char arr3[10])
{
int no1,no2;
for(int i=0;i<10;i++)
{
no1=arr1[i];
no2=arr2[i];
arr3[i]=arrword[no1][no2];
}
}
void main()
{
try{
GameVOC a;
int arr1[10],arr2[10];
char arr[10][4],arr3[10];
a.generateRandomNumbers(arr1,10);
a.generateRandomNumbers(arr2,4);
a.GetWord(arr);
a.GetSlution(arr1,arr2,arr,arr3);
a.ShowWord(arr1,arr,arr2,arr3);
system("pause");
}catch(exception e)
{
}
}