   making a text game and seem to be stuck here..
  (Making this in C++ by the way)I'm having problems actually making the code to get me started here. I am fooling around right now with, W goes north, s goes south, a goes west, and e goes east. By pressing w you assign yourself the cell id number of (lets say 1). Then I should display options again (this time you can only move south). But it doesn't seem to be working for me. After I make an input the screen accepts it then just skips a space down and never does anything again.I need to get around this problem, and I need to find a way to stop people from, say jumping from north all the way to the bottom south. (Grid of map here):    1  2 0 3    4Here is what I have so far:# include <iostream># include <cstdlib> //for randomusing namespace std;char location; //cell id numberbool gameover = false;int main(){    cout<<"Welcome to the game!"<<endl;//welcome    cout<<"Press 'w' followed by enter to move north,"<<endl;//instructions    cout<<"'s' followed by enter to move south,"<<endl;    cout<<"'d' followed by enter to move east,"<<endl;    cout<<"and 'a' followed by enter to move west."<<endl;    location = 0;    while (gameover == false){  if (location == 0){//start location    cout<<"You can move north, south, east or west."<<endl; cout<<"What would you like to do?"<<endl; cin>>location; }  if (location == 1){//this is north location    cout<<"You can now move south."<<endl; cout<<"What would you like to do?"<<endl; cin>>location; }  if (location == 2) {//this is south location    cout<<"You can now move north."<<endl; cout<<"What would you like to do?"<<endl; cin>>location; }  if (location == 3) {//this is east location    cout<<"You can now move west."<<endl; cout<<"What would you like to do?"<<endl; cin>>location; }  if (location == 4) {//this is west location   cout<<"You can now move east."<<endl; cout<<"What would you like to do?"<<endl; cin>>location; }   }//ends while game over   }//ends int mainI know my code is way off of where I need to go, I think I will be fine I just need a bump in the right direction. Thanks,Axis   
  Hmm...  First of all, I don't see any logic here that interprets the keys 'w', 'a', 's' or 'd' into the numbers used by your game logic - unless you simply haven't included that here, of course.More to the point, I think that what you might be missing is information on where one may go from any given point - at the moment there doesn't seem to be anything stopping a player entering whatever direction they please, and being told that they have gone in that direction.There are a few ways that you might encode this - implicitly, such as in the neighbours of a given node of a two-dimensional array, or explicitly, as in creating a "node" class or struct, which holds pointers to nodes accessible from it or directions in which one may exit it.  When the player provides a direction, this is checked against what is currently allowed, and if it is allowed, enacted.Good luck with your project! ^_^   ;Quote:Original post by ThaumaturgeHmm...  First of all, I don't see any logic here that interprets the keys 'w', 'a', 's' or 'd' into the numbers used by your game logic - unless you simply haven't included that here, of course.More to the point, I think that what you might be missing is information on where one may go from any given point - at the moment there doesn't seem to be anything stopping a player entering whatever direction they please, and being told that they have gone in that direction.There are a few ways that you might encode this - implicitly, such as in the neighbours of a given node of a two-dimensional array, or explicitly, as in creating a "node" class or struct, which holds pointers to nodes accessible from it or directions in which one may exit it.  When the player provides a direction, this is checked against what is currently allowed, and if it is allowed, enacted.Good luck with your project! ^_^Thank you very much for your reply, I understand that nothing interprets the keys 'w' etc.etc. to equal 1. One of my problems is that I am not quite sure how to go about doing that.The same applys with preventing a player from jumping from the top to the bottom without going to the middle first. I am not quite sure how to go about doing that either. And your response is a bit too much for me to swallow it would seem.;  I am confused on how your game will work with that code you have now. Here is some psuedo code for you to possibly ponderchar Input;while (gameover != 1){   cout << "Where would you like to go?";   cin >> Input;   switch(Input) case 'W':    //Move west case 'N':    //Move north case 'S':    //Move south case 'E':    //Move east}If you plan on doing N/S/E/W you need more than 1 number specified as a location. Maybe think of using like LocationX and LocationY, one being used for north/south and the ladder being used for east/west.Edit: You should make some maps based on number schemes, for example:1 1 1 1 1 1 11 0 0 0 1 3 11 0 0 1 1 0 11 2 0 0 0 0 11 1 1 1 1 1 10 being open space, 1 being walls, 2 and 3 being an item (like a weapon or something)Make moving functions for each direction like MoveNorth(), MoveSouth(), etc. and in them put your collision detection.[Edited by - phear- on January 2, 2008 10:33:41 PM];  Ive decided to go more along the lines of. "You can go this way or this way, or take this""What do you want to do?"1. do action a2. do action b3. move direction aetc.It seems to be working out so far (was just using if, then now redoing everything in switch cases instead). Will repost source asap for critiquing.   ;Quote:Original post by phear-Edit: You should make some maps based on number schemes, for example:1 1 1 1 1 1 11 0 0 0 1 3 11 0 0 1 1 0 11 2 0 0 0 0 11 1 1 1 1 1 10 being open space, 1 being walls, 2 and 3 being an item (like a weapon or something)Make moving functions for each direction like MoveNorth(), MoveSouth(), etc. and in them put your collision detection.In my opinion this is actually the best way to do it. Let me give you a more detailed example.lets say that your map like phear said is based on a 2d array, map[Y][X] where X and Y are the coordinates(remember that coordinate (0,0) is the top left corner). You are probably thinking about how to make your player move in a map like this. Its pretty easy if u think about it. Lets say that our player is currently at position map[y][x]. We ask the player in which direction he would like to move. If the player chooses east or west, he should move along the x axis only. West: map[y][x--] east: map[y][x++].If the player chooses north or south, he should move along the y axis only. North: map[y--][x] south:[y++][x].You might also want to add collision detection which is basically an if statement to check if the area the player wants to move to is an open(has a value of 0) or restricted space(has a value of 1).I hope that this helped   ;Quote:Original post by Axis304And your response is a bit too much for me to swallow it would seem.Ah - I do apologise. ^^;I suspect that you'll find that the system described by phear- and Ne_cro is probably simpler to implement than that which you describe.Your idea isn't impossible, however, and could potentially be more flexible.  I would imagine that it would mean storing information about a player's current position, such as what actions they are allowed to perform.In the case of the system described by phear- and Ne_cro, deciding on whether the player can move in a given direction is simply a matter of checking whether the position in the array that they want to move to is available or not.  (But don't forget to check for the edges of the array!)Tell me please (and I apologise again if this seems condescending; I don't know what you have learned thus far), do you know about classes and structs?  If not, I suggest looking them up, as one or the other is likely to be rather useful to you, I imagine.  Since you're using C++ instead of C, I would recommend classes.As to converting an input of 'w' to '0', for example, try something like this:cin >> input;if(input == 'w') {  cout<<"W detected!"; }orcin >> input;switch(input) {  case('w'):  {   cout<<"W detected!";   break;  } };(Altered to fit your goals, of course.)There are two things to note, I think:1) There are single quotes around the 'w' - not double, and not none.2) The check that I have given above should be case-sensitive, I believe, so you might want to check for 'W' as well.   ;  Thank you all very much. I do know a little about structs and classes, but I will look them up again in my book to refresh my memory.I will take all of those ideas into consideration when deciding how to make the player move.Thanks again, and still plan on posting the new source as soon as I get it finished.   