I was trying to make the Dungeon Crawl game (again) listed here in the Beginner's Exercises Article:
http://www.cplusplus.com/forum/articles/12974/
I made a couple of changes to the game, though. Firstly I tried to make the Enemies, a bit more challenging, by making them come towards the User, A variable sized Board (with a minimum and maximum range of course!).
First the basic structure of the program:
The board is defined in a class named
DungeonC. The Board itself is a pointer which is allocated dynamically to variable sizes.
There is another
class,
Character, which has 5 protected members, of them only 3 being relevant to the problem, namely:
1 2 3
|
char Peg; //Symbol of the Peg
int X; //Height Coordinate of the 'Character' beginning at 0
int Y; //Width Coordinate of the 'Character' beginning at 0
|
There are a number of functions in the Public sections, 9 of them being to either return one of the protected members or change them.
There is one virtual Function,
virtual void Move()
Further I derived 4 classes from it:
1 2 3 4
|
Player;
Enemy;
Trap;
Treasure;
|
The Enemy is the source of the Error.
The relevant snippet of code is here (I didn't think it prudent to post over 100 Lines of code here):
http://pastebin.com/zj5qhNZj
Now before I describe the error, I should tell that all the functions declared there are working (apart from
Move(), which is the whole snippet itself!)
The error is somewhere in the Logic of the program, which I haven't been able to find.
A Basic Description of the Functions used in the Code:
[All functions with 'r' Prefixed in their name return a non-public value of the Class]
1) rPeg --> returns a
char. Symbol of the Peg concerned.
2) rWidth --> returns an
int. Width of the Board.
3) Offset --> returns an
int. I use it to get the value of the location of a point on the Board on the basis of Coordinates.
4) ShowCell --> return a
char. The Peg located on the cell passed as the Parameter
5) GetX & GetY --> The Name give it away, they return the Height and Width Coordinate of a cell respectively.
6) AddPeg & RemovePeg --> This Adds a Peg and removes on from the parameters of the Functions.
Now with all the Functions explained, the Error:
The code was supposed to work like this:
H.......
........
....X...
........
.......T
----------------
........
H...X...
........
........
.......T
----------------
........
...X....
H.......
........
.......T
----------------
........
..X.....
........
H.......
.......T
----------------
........
........
..X.....
.H......
.......T
----------------
........
........
........
..X.....
.H.....T
|
And so on...
But what happens is that The Enemy Doesn't move if my position Changes horizontally, but does if it does Vertically.
Any help regarding this problem?