Console Game Problem

Started by
3 comments, last by Xperience 11 years, 2 months ago

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!

Advertisement

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

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.

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;
    if (map[y][x] != OBSAD)
    {
        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 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;
    if (map[y][x] != OBSAD)
    {
        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

This topic is closed to new replies.

Advertisement