Thread: need help with a number game

  1. #16
    Registered User
    Join Date
    Sep 2008
    Posts
    15
    Quote Originally Posted by citizen View Post
    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 View Post
    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.
    Last edited by razzaz; 10-15-2008 at 07:05 PM.

  2. #17
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    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.

  3. #18
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  4. #19
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Well aren't you just a bundle of useful information.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help!!! Number guessing game
    By JesterJoker89 in forum C++ Programming
    Replies: 16
    Last Post: 10-05-2007, 12:47 PM
  2. 2D Game project requires extra C++ programmers, new or experienced
    By drallstars in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 05-16-2007, 10:46 AM
  3. Stone Age Rumble
    By KONI in forum Contests Board
    Replies: 30
    Last Post: 04-02-2007, 09:53 PM
  4. 2D RPG Online Game Project. 30% Complete. To be released and marketed.
    By drallstars in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 10-28-2006, 12:48 AM
  5. Logical errors with seach function
    By Taka in forum C Programming
    Replies: 4
    Last Post: 09-18-2006, 05:20 AM