pls help

This is a discussion on pls help within the C Programming forums, part of the General Programming Boards category; hi i wrote a programme that has an object( :-> ) and you can control this object by "w" for ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    80

    Exclamation pls help

    hi

    i wrote a programme that has an object( :-> ) and you can control this object by "w" for moving it up and "s" for moving it down
    my code is;

    ......
    char key;
    int i;
    .
    .
    .
    key = getch();
    if (key==s) {
    i--;
    }
    .
    .
    .this works very well if i push JUST one time and in the second time the program terminates itself
    so i used do..while


    do {
    .
    .
    .
    } while(key=='q')
    but still i have same problem
    i want to push "s" or "w" unlimited nor just one time

    how can i do this?

  2. #2
    Registered User
    Join Date
    Jan 2002
    Posts
    49
    while(key=='q')
    I think you mean :

    PHP Code:
    while(key!='q'

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    43
    Yeah I did the same thing on a program of mine only i used the keys E=left, D=down, E=up, and F=right. In my program I put it in it's own function so I only had to type PLAYER(); in the main() function. The code is this.

    Code:
    void player()
    {
    
    /* int X and Y tell where the player is
       int oldX and oldY tell where the player moved from (to clear that spot)
    
       int X=1, Y=1, oldX, oldY;
       char move;
    
       while(1)
       {
    
    /* This is where the computer knows where to put
    the player and set it up to clear the last place
    the player was so you don't see a trail of O's. */
    
    	        gotoxy(X,Y);
    	        oldX=X;
    	        oldY=Y;
    	        printf("O");
    
    
    /* This is the part where it gets the input
    and sees if they moved left, right, up, or down. */
    
               move=toupper(getch());
    	   switch(move)
    	   {
    
    		   case 'S':
                                                            X--;
                                                            break;
    
    		   case 'D':
                                                            Y++;
                                                            break;
    
    		   case 'F':
                                                            X++;
                                                            break;
    
    		   case 'E':
                                                            Y--;
                                                            break;
    
    		   default:  //if they hit keys other then EDSF print this
    			gotoxy(1,24);
    			printf("Move with E, D, S, F\n");
    			printf("Make your next move.");
    			move=toupper(getch());
    	   }//end switch
    
    // puts a space where the player was after they moved	
          gotoxy(oldX, oldY);
          printf(" ");
    
       }//end while loop
    
    }//end player
    Tell me if that solves your question.
    ()()() MonKey ware
    Kyle J. R.

  4. #4
    Registered User
    Join Date
    Jan 2002
    Posts
    80

    Talking

    thanks for your answer
    it works great
    but i have quesitons to you:

    how could i terminate the program??and
    how can i hide the cursor "_"?
    Last edited by condorx; 02-22-2002 at 03:05 PM.

  5. #5
    Registered User
    Join Date
    Jan 2002
    Posts
    49
    Are you using Goof Program program ,

    Well it's always the same answer, instead of :

    while(1)

  6. #6
    Registered User
    Join Date
    Jan 2002
    Posts
    49
    Are you using Goof Program program ,

    Well it's always the same answer, instead of :


    while(1)
    use


    while(move != 'Q')

  7. #7
    Registered User
    Join Date
    Oct 2001
    Posts
    43
    I deleted some of the code that killed the while loop because that might not be what you wanted. so i left it up to you so you can use what you need. thats just the base of it. It is a function on it's own, not part of main() all though you can put it in main().
    ()()() MonKey ware
    Kyle J. R.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Basic port scanner code .. pls help ???
    By intruder in forum C Programming
    Replies: 18
    Last Post: 03-13-2003, 07:47 AM
  2. i dont know what to do. pls. help!!!!
    By Unregistered in forum C++ Programming
    Replies: 14
    Last Post: 03-14-2002, 02:24 PM
  3. help me pls..... :(
    By mocha_frap024 in forum C++ Programming
    Replies: 2
    Last Post: 02-22-2002, 09:46 AM
  4. pls help me!!
    By hanseler in forum C++ Programming
    Replies: 1
    Last Post: 12-05-2001, 07:46 PM
  5. Pls Help Me In This Question!!!
    By Joanna in forum Windows Programming
    Replies: 1
    Last Post: 10-20-2001, 02:05 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21