Followers 0

# Console Game Problem

## 4 posts in this topic

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!

0

##### 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].

2

##### 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.

1

##### 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

0

## Create an account

Register a new account