![]() |
Re: OT: Stupid c++
I don't really know what you're doing, so NarfClass was just an example. NarfClass would be any class that wants to be able to use some external object, without requiring the external object to actually be defined as a global with a certain name in the class definition.
Actually, the classic approach to doing what I think you probably really want to do is to make the Character Vector into a singleton class - a class designed to ensure there is only one of something, and provide access to it to other classes. I don't really know what your class design is like - that is, how you've decided to divide up the things in your game into classes. extern is a keyword for referring to objects or variables defined in other files, which would be how you can refer to globals created in other files. The syntax is, for example: extern int X9B; This lets you use X9B, but in one and only one other file you need to have the actual declaration: int X9B; So you can see that can make your code hard to read and use the more you do that, because it means you have to remember where that global is actually defined, etc. PvK |
Re: OT: Stupid c++
If you want, I can send you the source code. Right now, the character stuff is mostly in one character class, with a vector for the list of characters and some external functions that deal with that vector class.
Yeah, I think I'll stay away from multiple cpp files if it means externs. Thanks. |
Re: OT: Stupid c++
Multiple cpp files means externs if you use globals to share info between them.
But for an object-oriented design, you have a class definition file (Foo.h) and a class implementation file (Foo.cpp) for each class, and then you use them in the context of other classes. This way, almost all the code you write solves problems for general cases, and the specific application implementation (e.g. the actual Main function of an application) can then be something more general, simple and high-level. So Character defines a character object in so general a way, that its .h and .cpp files don't need to refer to the instance of them at all - they refer only to the definition of other related classes, but never to a specific object (or else they'd be usable only with that specific object). So your list of classes might be something like: GameState Level Character Item Potion Weapon Armor Each would have two files, a .h and a .cpp. All would be generic implementations. Then you'd have a Main.cpp file where the entry point and specific objects are declared. In it you'd have maybe just one GameState object, and just a few calls to its methods, like: GameState.CreateNewGame(); GameState.Load( SavedGame ); GameState.Play(); GameState itself might have a protected Initialize() method which would be called by both CreateNewGame() and Load(), and GameState would have the only Vectors storing all the objects representing stuff that exists in the game universe. Etc. PvK |
Re: OT: Stupid c++
Huh. Thanks.
That is a radical departure in thinking. I'll have to think about it. Right now, I'm wanting to do some visible content. Too much code maintenance makes Narf wonder if he's making progress. |
Re: OT: Stupid c++
Ya. You might want to spend more time having fun making things work, and think about a more O.O. architecture for your next project.
|
Re: OT: Stupid c++
Heh. I added armor. Now I'm making it work. Just have to fix the load routine (Again).
Everythings fixed, and armor is now available. Just check the floor in your nearest dungeon. |
Re: OT: Stupid c++
Anyone know how to turn off the generation of debugging information in Dev c++? I think it's padding my program.
|
Re: OT: Stupid c++
Updated. A couple of weapons with actual names. Savegames should still work.
On the downside, characters aren't properly re-located after descending stairs. Not a game-breaker. |
Re: OT: Stupid c++
Update: Simple Roguelike v0.1.5.0
Breaks savegames. A few different item properties. Items are now more of a trade-off. |
Re: OT: Stupid c++
Dev C++ doesn't seem to like one of the include files that came with the DirectX SDK.
It's one of the ones used in: '(SDK root)\Samples\C++\Direct3D\Tutorials\Tut01_CreateD evice' I think I have the Directx include and lib folders linked in the right place, but just to check, can somone tell me how to link the Dx SDK into Dev C++? Thanks. |
All times are GMT -4. The time now is 04:47 AM. |
Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©1999 - 2025, Shrapnel Games, Inc. - All Rights Reserved.