PDA

View Full Version : Any peeps in here know how to.....



bluehead
11-06-2001, 04:05 PM
anyone know how to move the character @ up, down, left, and right when the specific buttons are pressed?
dank you

Hillbillie
11-06-2001, 04:59 PM
Like this?:



#include <iostream.h>
#include <conio.h>
#include <stdlib.h>

void main()
{
char ch;
int x = 10, y = 10;

gotoxy(x, y);
cout << "@";

while(1)
{
ch = getch();
gotoxy(x, y);
cout << " ";

switch(ch)
{
case 'a': x--;
break;

case 's': x++;
break;

case 'z': y++;
break;

case 'w': y--;
break;

default: exit(0);
}

gotoxy(x, y);
cout << "@";
}
}


Sorry about not commenting....

bluehead
11-06-2001, 05:03 PM
well, not like that. that code closes when a button is pressed. How about using the getch(); command??

Hillbillie
11-06-2001, 05:14 PM
>well, not like that. that code closes when a button is pressed. How about using the getch(); command??<

What do you mean the code closes when a button is pressed?

And, if you pay attention to the code, you'll notice I do indeed use getch().

Press [a] to move the character left.
Press [s] to move the character right.
Press [w] to move the character up.
Press [z] to move the character down.

Hope that helps...