the code is posted below but what i'm having troubles with is around line 153 at the end of func2 and what i want it to do is only refresh the array but let the user still input and then increase the sleep speed, or to say make the array refresh faster, and i don't know how to do that. any ideas? any questions go ahead and ask.
#include <iostream>
#include <time.h>
#include <stdlib.h>
#include <windows.h>
usingnamespace std;
// global variables
conststaticint iMAX = 40;
char cArray[iMAX][iMAX];
int iSize; // currents size
int iAns; //what the answer should be
char cStart;
char cBase; // base characters in array
char cDiff;// the one character thats different
int iUAns; //user answer
// func1 is used to ...
int func1()
{
system("cls");
cout << " -------------------------------------------------------------------" << endl;
cout << " | You have chosen the Hidden Characters game. |" << endl;
cout << " | You will be looking for a specific character in this game. |" << endl;
cout << " | All of the characters will be the same save for one. |" << endl;
cout << " | You will be looking for that one character. |" << endl;
cout << " | If you see the character, enter the key '1'. |" << endl;
cout << " | If you do not see the character, enter the key '2' |" << endl;
cout << " | Each time you pass a level the size of the field will increase |" << endl;
cout << " | Are you ready? |" << endl;
cout << " -------------------------------------------------------------------" << endl;
iSize = 8;
// Loop below this line
do
{
iSize +=1;
switch(iSize)
{
case 9: cBase = char(36); cDiff = 'S'; iAns = 1; break;
case 10: cBase = char(229); cDiff = 'o';iAns = 1; break;
case 11: cBase = char(228); cDiff = 'E';iAns = 1; break;
case 12: cBase = char(225); cDiff = 'B';iAns = 1; break;
case 13: cBase = char(46); cDiff = char(44);iAns = 1; break;
case 14: cBase = char(54); cDiff = char(54); iAns = 2; break;
case 15: cBase = char(230); cDiff = 'u';iAns = 1; break;
case 16: cBase = char(141); cDiff = 'i';iAns = 1; break;
case 17: cBase = char(58); cDiff = char(59);iAns = 1; break;
case 18: cBase = char(205); cDiff = char(61); iAns = 1;break;
case 19: cBase = char(196); cDiff = char(45);iAns = 1; break;
case 20: cBase = char(240); cDiff = char(240); iAns = 2; break;
case 21:
{
system("cls");
cout << "\n\n\n\n\n\n\n\n\n\n\n\n" << endl;
cout << "The game is now over! You Won! You have an excellent mind, user!" << endl;
cout << "\n\n\n\n\n\n\n\n\n\n\n\n" << endl;
return 1;
}
}
// initialize the array
for (int x = 0; x < iSize; x++)
{
for (int y = 0; y < iSize; y++)
{
cArray[x][y] = cBase;
}
}
// put one char in random spot
int x = rand()% iSize;
int y = rand()% iSize;
cArray[x][y] = cDiff;
// display everything in array
for (int x = 0; x<iSize; x++)
{
for (int y = 0; y<iSize; y++)
{
cout<< cArray[x][y];
}
cout << endl;
}
cout << endl;
cout << "Enter '1' if you see the character which is different." <<endl;
cout << "If there is not one, enter '2'" << endl;
cin >> iUAns;
if(iUAns != iAns)
{
system("cls");
cout << "You lost the game." << endl;
return 1;
}
system("cls");
}while(true);
return 0;
}
/*I'm currently writing the part of the array that will display the random characters
which none of them will be repeated in the array.*/
void func2()
{
system("cls");
cout << "----------------------------------------------------------------------------" << endl;
cout << "| You have chosen the Moving Menace game. |" << endl;
cout << "| You will be looking for a specific character in this game. |" << endl;
cout << "| When you see the character, enter the key 'G'. |" << endl;
cout << "| Just as a warning the more you find the character, the faster it moves. |" << endl;
cout << "| Are you ready? |" << endl;
cout << "----------------------------------------------------------------------------" << endl;
Sleep(1000);
//It's over 9000!
cout << "3" << endl;
Sleep(1000);
cout << "2" << endl;;
Sleep(1000);
cout << "1" << endl;
Sleep(1000);
system("cls");
cout << "GO!";
Sleep(1000);
system("cls");
// initialize the array
while(1)
{
cout << "Look for this character: '*' \n" << endl;
char cTest;
iSize = 16;
for (int x = 0; x < iSize; x++)
{
for (int y = 0; y < iSize; y++)
{
cTest = char(rand() % 223 + 33);
cArray[x][y] = cTest;
}
}
// display everything in array
for (int x = 0; x < iSize; x++)
{
for (int y = 0; y < iSize; y++)
{
cTest = cArray[x][y];
cout<< cTest;
}
cout << endl;
}
Sleep(1500);
system("cls");
}
}
int main()
{
/* initialize random seed: */
srand ( time(NULL) );
cout << "---------------------------------" << endl;
cout << "| Walker Andreasen's Mind Games |" << endl;
cout << "---------------------------------" << endl;
cout << "What game would you like to play?" << endl;
cout << "1: Hidden Characters" << endl;
cout << "2: Moving Menace" << endl;
cin >> cStart;
switch (cStart)
{
case'1': if(func1() == 1) {return 0;} ; break;
case'2': func2(); break;
}
return 0;
}
Hi , system("cls");
is not used for clearing the buffer or an array it is used to clear the screen .
try flush() to clear the input buffer and memset() to clear the array .