I generally think that using namespace std; is a bad idea.
Putting using namespace std; in a header is a very bad idea.
buf should probably be some kind of smart pointer, and be careful about
where you make it, and how you use it.
Your code is scattered with magic numbers. This should be avoided. And
remember that in C++, a char is really an integral type.
What is a magic number and how do I avoid them? I have used char in
past programs where I thout approate.
When I run, all the moves cause the code to crash.
They run fine for me. I did have a problem when I was experimenting
with some display variables.
You ought to think about adding a function that adds two coords
together. Like:
Coord operator+(const Coord &c1, const Coord &c2);
not sure why but it may be a good idea.
Coord should have a default ctor. Particularly as you're using the
default value for a coord in board::move.
Not sure which game your looking at my maze game? Yes, I know that one
is very buggy. Once I got it running, I figured that while it still
often runs it was poorly designed byond repair without a complete
rewrite.
And maybe also, coord should have ctor that looks like this:
coord::coord(const int &xx, const int &yy) : x(xx), y(yy) {}
coord(const int xx, const int yy){x = xx; y = yy;}
This is what I can up with for my current project, but I can make a
change.
Also, you might want to think about something like this:
bool board::validCoordForSpaces(const Coord &c) const {
const bool result = (0 <= c.x && c.x < size) && (0 <= c.y && c.y <
size);
return result;
}
That would be a good idea I am saving this it will be very useful in
future work.
But I tend to think that class board might already do too much. For
example, it's not clear to my why you have data members e,n,s,w in
board. Think about how your ctor for board is written, and perhaps
consider adding an enum like this:
enum Direction { NORTH, SOUTH, EAST, WEST }
and a map like:
std::map<Direction, coord> keys;
then you can:
keys[NORTH] = coord(0,-1);
(Of course, there is some debate as to NORTH or North would be
preferable, you'll have to choose what you think is best.)
Actually this code has been recycled many times by me. I found it very
useful and lifted it from a perl program. I find that a bit confusing
to use
case VK_UP:
if(selectedUnit != -1){bn[selectedUnit]->mover('n');}
...........................
void unit::mover(char ch){
loc.y = loc.y + keys[ch].x;
loc.x = loc.x + keys[ch].y;
moved++;
}
Think about this code snippet and your board::move method.
const int arraySize = 10;
int a[arraySize];
if( a[103] == 0 ) { SomeErrorMessage("Oops can't check that index."); }
If you offer a reference to code that you've written in the hopes that
people will look at it, it would be best for that code to compile.
My code did compile for me. I do rember writing this code that was a
real challenge to get to compile and run without crashing.
Also, I still have the opinion that you are biting off more then you can
reasonably chew at this point. I think you'd do better to try some
simpler programs and build up to your game.
This game was a challenge but I learned from it. I have simple board
game which I am trying to improve. That game would require a full
re-write to improve. I would like to get back to it some time but find
my current work more intersting.
You can goback and see my old perl work:
http://www.planetsourcecode.com/vb/...setAllVariables=TRUE&lngWId=6&B1=Quick+Search
I realy enjoy the comments I get from people who take the time and look
at what I have writtem. My dream job would be able to design and
create strategy games. I am not very satisifed with the kind of
war/strategy games out there. I have come up with ideas for some game
I would like to write. The ideas I have are far byond my ability to
create. I am in the military and have seen how an army actualy
functions in war. For example, I have learned about all the behind the
scenes stuff that goes into combat. The logistics intelligence
comunications the management of information these aspects are just as
important that firepower and manuver. I have a few other ideas as
well.
For me the games I play are loosing the game and the power of the
computer is not being used for simulation but for overdone graphics.
Civ 4 is a great example of a great game being lost in the graphics and
the game lost.
If I can't write games, I will if my skill programming can get me a
job. I am always pushing what I can do trying to write better code. I
do have a few books that are actually helpful in my projects but most
of what I write I come up with. I am always looking to improve my
techniques of improving my code. How can I make that into a function,
how can I seperate that out it to its own objects. Breaking my current
simple and basic ideas down into parts that work well together. The
project I am working on is an improvment on similliar gam e I have many
challenges and I don't yet even have a clue how I would implement a
computer player.