Dungeon Exercise - open for comments

Pages: 123
chrisname +1

When developing, turn your compiler's lint mode to maximum and test on at least two platforms.
I tend to try my code on every OS I have installed -- at the moment, Linux, FreeBSD, OpenSolaris and windows 7.
Thats smart, I just stick to windows though. Can never be bothered going back to Linux or Ubuntu or what not.
Good grief, you have all those installed? Wow. Are they on one machine, or do you have more than one box sitting around?
Well, OpenSolaris is on QEMU... If I were to test software on it (I haven't done so yet) I would put it on a flash drive or something.

I'm about to completely recreate my partition table with 4 Linux OSes + 2 extras + windows 7 on it.
Wow, thats a lot of OSes. You like your portability ey?
Yes. I'm not good at optimizing C code (I can optimize asm ok though) so I go for portability instead.
Thats pretty cool. I usually never take the portability road which is probably a bad thing for my line of study. But I do focus on optimizing a lot. I don't have a lot of knowledge in asm (never looked into it) but I would love to check it out some time soon.
Hi Mythios. Finally I got some time to go thru your code, and as far as I can tell, I seem to understand it without problems - which makes me feel good since I started with C++ just a month ago.

Using a vector for this seems the right thing to do, because of the fact that the number of monsters is not a constant (I mean, in my Dungeon code) and the vector is by definition dinamically resizeable. My only question is: why prefer using a struct over a class to define the "monster" objetc?
@Duoas
I tried -ansi on the compiler options and tried a hello world program but the compiler throws this error.
||=== h, Debug ===|
C:\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\include\c++\3.4.5\cwchar|161|error: `::swprintf' has not been declared|
C:\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\include\c++\3.4.5\cwchar|168|error: `::vswprintf' has not been declared|
||=== Build finished: 2 errors, 0 warnings ===|


The error is pointing to cwchar header of the compiler. I tried to comment the lines the error is pointing to and everything works fine but it bothers me since this is a compiler header (supplied by MinGW).

thanks for any help.
What is the code of your hello world program?
@Duoas
1
2
3
4
5
6
7
8
9
#include <iostream>

using namespace std;

int main()
{
    cout << "Hello world!" << endl;
    return 0;
}


I tried -pedantic and it gives no error.
I updated to the latest version of Mingw and now there are no problems. The latest version links all programs to shared libraries libgcc_s_dw2-1.dll and libstdc++-6.dll but still have an option to link to static library..

Thanks again Duoas.
I think I had a similar problem a short while back -- it was because I installed a later version over an existing version and broke some libraries. I had to completely wipe and re-install the correct version of MinGW to clean it up.
What version are you using? I am using 4.5.0-1, is that good?
Can I ask a question . How do you refresh the dungeon without the redrawing ?
In the console? What do you mean?
@blackcoder41
GCC 4.4.0
IDK. (Presumably.)

@Morph
You always have to redraw if you want changes to appear on the screen.
Position the cursor "home" and then start drawing again.

What OS are you using? What assumptions are you making about the display?
but i couldn't get the idea of erasing the old ones ?

ok ok i saw that you used system cls
Last edited on
I never use system cls.
http://www.cplusplus.com/forum/articles/11153/
http://www.cplusplus.com/forum/articles/10515/

If you are doing a full-screen display, it will work better if you do not "clear" it and instead just position the cursor at "home", then rewrite all positions (or just all positions that have changed).

On Windows:

 
#include <windows.h> 
1
2
3
4
5
bool gohome()
  {
  COORD homeCoords = { 0, 0 };
  return SetConsoleCursorPosition( GetStdHandle( STD_OUTPUT_HANDLE ), homeCoords );
  }

On POSIX:

1
2
#include <term.h>
#include <unistd.h> 
1
2
3
4
5
6
7
8
9
10
11
bool gohome()
  {
  if (!cur_term)
    {
    int success;
    setupterm( NULL, STDOUT_FILENO, &success );
    if (success <= 0)
      return false;
    }
  return putp( tigetstr( "home" ) ) != ERR;
  }

The POSIX code is a little simplistic. Typically applications that manipulate the cursor should output the enter_ca_mode string when initializing and the exit_ca_mode before terminating. (Above we manipulate the cursor with the home string.)

See this for more:
http://linux.die.net/man/3/tputs

Hope this helps.
Pages: 123