# need help with a number game

Show 80 post(s) from this thread on one page
Page 2 of 2 First 12
• 10-15-2008
razzaz
Quote:

Originally Posted by citizen
Redraw the grid for each move.

Unless you do something like clear the screen older grids will scoot up the screen, with the most recent at the bottom.

ah... what i tryed now as seen below is that i put the loop above the grids and threw in a "system ("cls");" under them, what i however dont know now is if i made this work corrently or not as X is still not moving anywhere :/ but everyting is looping.

Code:

```#include <iostream>  #include <fstream> #include <string> using namespace std; void jump(char start[][3],int x, int y); int main() { //deklarerade variabler f&#246;r mail int yes,abryt,x,y; //b&#246;rjan p&#229; mitt grid char start[3][3], goal[3][3];         int loop2 = 0;         while (loop2 == 0){ //l&#228;ser in filen som blivit vald ifstream infil("start.txt"); infil >> start[0][0] >> start[0][1] >> start[0][2]       >> start[1][0] >> start[1][1] >> start[1][2]           >> start[2][0] >> start[2][1] >> start[2][2]; //tar reda p&#229; vart X &#228;r p&#229; gridet och skriver ut positionen i toppen av spelet.                   for(int i=0;i<3;i++){                 for(int j=0;j<3;j++){                         if (start[i][j] == 'X'){                         y=i;                         x=j;                         cout << "your on Square: " << "Y: " << y << " X: " << x << endl << endl;                                                 }                 }         } //skriver ut mitt start grid cout << start[0][0] << " " << start[0][1] << " " << start[0][2]     << endl << start[1][0] << " " << start[1][1] << " " << start[1][2]         << endl << start[2][0] << " " << start[2][1] << " " << start[2][2]         << endl << endl; ifstream infil2("goal.txt"); //l&#228;ser in mitt m&#229;lgrid fr&#229;n vald fil infil2 >> goal[0][0] >> goal[0][1] >> goal[0][2]       >> goal[1][0] >> goal[1][1] >> goal[1][2]           >> goal[2][0] >> goal[2][1] >> goal[2][2]; //skriver ut mitt m&#229;l grid cout << goal[0][0] << " " << goal[0][1] << " " << goal[0][2]     << endl << goal[1][0] << " " << goal[1][1] << " " << goal[1][2] << endl     << goal[2][0] << " " << goal[2][1] << " " << goal[2][2] << endl << endl; //loop f&#246;r att ladda om spelplanen n&#228;r n&#229;got blir inmatat         /*int loop = 0;         while (loop == 0){ */                 jump(start, x, y);           system ("cls");         }                 return 0; } void jump(char start[][3], int x, int y) {         string jump2;         cout << "You move by using W A S D on you keyboard: ";         cin >> jump2;         //funktion f&#246;r att avbryta spelet n&#228;r man vill.         if(jump2 == "avbryt")         {                 string quit;                 cout << "Want to quit the game eh? Yes/no" ;                 cin >> quit;                 if(quit == "yes")                 {                         cout << "bye message" << endl;                 } else                         cout << "stay message";         } else         //switch sats f&#246;r att r&#246;ra p&#229; sej med tangenterna W A S D         switch(jump2[0])         {                 case 'w':                         y--;                         if (y < 0 ){                                 y = 0;                                 cout << "lol, you cant move here" << endl;                         }                         break;                 case 'a':                         x--;                         if (x < 0 ){                                 x = 0;                                 cout << "lol, you cant move here" << endl;                         }                         break;                 case 's':                         y++;                         if (y > 2 ){                                 y = 2;                                 cout << "lol, you cant move here" << endl;                         }                         break;                 case 'd':                         x++;                         if (x > 2 ) {                                 x = 2;                                 cout << "lol, you cant move here" << endl;                         }                         break;         } }```
[/CODE]

Quote:

Originally Posted by master5001
What OS are you writing this for? And do you care if you implement non-standard functions?

Im writing in windows vista using Microsoft Visual C++ 2008, and no i would not mind.
• 10-15-2008
master5001
In that case, look and see if you have conio.h. If not, I can upload some old code I have from way back when to compile conio into your project. Then you can more easily move the cursor to arbitrary screen locations.
• 10-20-2008
dwks
• 10-20-2008
master5001
Well aren't you just a bundle of useful information.
Show 80 post(s) from this thread on one page
Page 2 of 2 First 12