easy question???

Hello guys, i would like to ask you about c++ language. i have an assignment and i want to do a movement for the hero?
i have an assignment and i want to do a movement for the hero which will be controled by the keyboard.i apologise because my english isn't very well

the map is similar to this:

|------|------|------|
| h
|------|------|------|

h = the hero, d= move right , a= move left ,if the user enter 'd' so i want the hero to move to next room and when the user press 'd' again so the hero should move to the last room , i tried many times just know but i couldn't do it

i tried to do this soultotion

1- i use a lot of functions to do the movement for the hero but my problem is i put every room for each of functions
for example if the user key 'a' so the hero will be in the left room, but if he key 'd' to go back to the middle , the hero will move to the right room because i put the function called 'hero_right' and the position of the hero is alaways right
thats why i put another key (control by keboards) called 'm' for the middle position
a = left room
d = right room
m = middle room

but my solution not very well because i want the hero to move freely

waiting for you
this is my last solution

1- i declare many functions for each room , for example

void left_room()
{
cout << " the hero position is in the left room" <<endl;
}

so my qustions is how can i use this functions with if statment

for example i want to do this code

if (left_room == 'd' || left_room == 'D')
{
'show the middle room functions'
}
else if (middle_room == 'd' || middle_room == 'D')
{
cout << " the hero position is in the right room " << endl;
}

i tested this code but dosen't work

i tried to declare varibles instead of functions and i use all the tybes (char,int,float,double,void)
i'll show you how i use these varibles

int hero_left= '------------'
'| |'
'| |'
'| |'
'| |'
'------------';

cout << hero_left << endl;

but still dosen't work
hey, I think you're approaching it the wrong way really. Anywho, there really isn't a standard way to access your keyboard in c or c++. if you're using windows you can use the GetAsyncKeyState() function in the win32 api, if you're using the console you can use umm _kbhit() or _getch() but they're all non-standard. And the same goes with clearing the screen. I'll show you in google talk or yahoo though if you want.
hi,

i'm biggner and i just study 'if , switch statment,loops and functions'

and this assingment should done it by these lessons

1
2
3
4
if (left_room == 'd' || left_room == 'D')
{
   left_room();
}


;)
Oh! too fast

left_room as variable and left_room as function could work but is unreadable

1
2
3
4
5
6
7

char key;

if (key == 'd' || key =='D')
{
    show_left_room();
}
Topic archived. No new replies allowed.