Jump to content

  • Log In with Google      Sign In   
  • Create Account


Console Game Problem


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 Xperience   Members   -  Reputation: 806

Like
0Likes
Like

Posted 13 February 2013 - 07:35 AM

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!



Sponsor:

#2 rip-off   Moderators   -  Reputation: 7963

Like
2Likes
Like

Posted 13 February 2013 - 08:12 AM

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



#3 rip-off   Moderators   -  Reputation: 7963

Like
4Likes
Like

Posted 13 February 2013 - 08:16 AM

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.



#4 DaDweeDow   Members   -  Reputation: 133

Like
1Likes
Like

Posted 13 February 2013 - 02:54 PM

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.  



#5 Xperience   Members   -  Reputation: 806

Like
0Likes
Like

Posted 13 February 2013 - 11:55 PM

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






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS