# Console Game Problem

This topic is 1797 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello, I want to create small 2D game(only console).I have done movement and map.But I want to control movemet, example:

There is a small part of map:

#             @                           #

I am @(I control it) and I want that I cann't go to the position where is  #.

I have done a function which control movement but this function dosn't work correctly.

Sometimes I can go to the position where is # and sometimes can't. And this function not allow to go where should be a white mark.

There is a Microsoft project + source codes:

Thanks for help!

##### Share on other sites

In level.cpp you populate the map using [y][x], but in drawengine.cpp you test the map using [x][y].

##### Share on other sites

Also consider having a single enumeration to represent the "tile type", and using that in both places. Make the type of Level::level and DrawEngine::map to be of this type.

You might also want to eliminate this problem by having the Level class encapsulate this information. The DrawEngine might take a Level reference/pointer, which it can use when drawing. The Character might query the level, rather than the DrawEngine, about whether a tile can be moved into. You could also invert some of the dependencies, so that game checks if the tile is free before moving the player.

##### Share on other sites

In level.cpp you populate the map using [y][x], but in drawengine.cpp you test the map using [x][y].

this is totally it, I just swapped them in the isValidLevelMove and it worked fine.

bool DrawEngine::isValidLevelMove(int x, int y)
{
using namespace std;
ofstream fout("Test.txt", ios_base::out | ios_base::app);
fout << boolalpha;
{
fout << map[y][x] << true << endl;
return true;
}
fout << map[y][x] << false << endl;
return false;
}


Also, for what it's worth, i'm pretty positive the nethack source is available, though I have a feeling it's fairly complicated for what it is.  Anyhow, good luck and have fun.

##### Share on other sites

Yes I done it problem was that I use [x][y] and than [y][x], thanks a lot rip-off

In level.cpp you populate the map using [y][x], but in drawengine.cpp you test the map using [x][y].

this is totally it, I just swapped them in the isValidLevelMove and it worked fine.

bool DrawEngine::isValidLevelMove(int x, int y)
{
using namespace std;
ofstream fout("Test.txt", ios_base::out | ios_base::app);
fout << boolalpha;
{
fout << map[y][x] << true << endl;
return true;
}
fout << map[y][x] << false << endl;
return false;
}


Also, for what it's worth, i'm pretty positive the nethack source is available, though I have a feeling it's fairly complicated for what it is.  Anyhow, good luck and have fun.

Yes I am solve this problem at the morning but thanks for help too

##### Share on other sites

This topic is 1797 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.