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

first this is the map

http://img694.imageshack.us/img694/7904/42695322.jpg

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

Edited 3 Years Ago by mike_2000_17: Fixed formatting

You probably want to use string variables. You can do that with either a char pointer or a string class. As such:

#include <iostream>
#include <string> // Header for string class.
using namespace std;

int main()
{
  char *str = "--------";
  string str_ = str;
  cout << str << endl << str_;
  // Produces the same output
}

There are also more ways to do it. If you are not going to manipulate the string I'd recommend using char*.

This article has been dead for over six months. Start a new discussion instead.