Game Messages
Once again, I'm not sure if this is the right place to ask about this, but here goes.
I'm still working on my space-strategy game. However, I've run into a problem with how to code "message-passing" for the players. That is, I'm not sure how to have the game tell the player that something has happened (like a ship reached a certain star system, or something is finished being built on a planet). Would creating a GameMessage class or the like be the easiest thing to do here?
Thanks,
- Rob
I don't know any better place to put this thread.
This is what I would do:
Assuming each entity in the game is derived from a base class or something, lets call it CBase. Well, in CBase, I would have a string or something called std::string gameMessage; Then, in the main game loop, right after I update that entity, I would check it's gameMessage member, if it has anything in it, I would print it on the screen or do whatever I wanted with it. If you want game messages to be more than just text displays, then I would write my own struct or class and use that instead. Like, CGameMessage gameMessage, the CGameMessage class could store a string, a message type or whatever you want.
If this post is unclear just say so and I'll explain it better.
This is what I would do:
Assuming each entity in the game is derived from a base class or something, lets call it CBase. Well, in CBase, I would have a string or something called std::string gameMessage; Then, in the main game loop, right after I update that entity, I would check it's gameMessage member, if it has anything in it, I would print it on the screen or do whatever I wanted with it. If you want game messages to be more than just text displays, then I would write my own struct or class and use that instead. Like, CGameMessage gameMessage, the CGameMessage class could store a string, a message type or whatever you want.
If this post is unclear just say so and I'll explain it better.
Quote: Original post by Samith
I don't know any better place to put this thread.
This is what I would do:
Assuming each entity in the game is derived from a base class or something, lets call it CBase. Well, in CBase, I would have a string or something called std::string gameMessage; Then, in the main game loop, right after I update that entity, I would check it's gameMessage member, if it has anything in it, I would print it on the screen or do whatever I wanted with it. If you want game messages to be more than just text displays, then I would write my own struct or class and use that instead. Like, CGameMessage gameMessage, the CGameMessage class could store a string, a message type or whatever you want.
If this post is unclear just say so and I'll explain it better.
Hey Samith,
Thanks for your reply! Yes, I think that's what I'll have to do. I think I don't even need a GameMessage class - since only human players can get messages, I just need a list of strings that can be dynamically added to. Then, when something happens in the game, a new message string can be created and added to the message list. The game core can handle creating dialog boxes for the messages. Computer players, of course, wouldn't need any of this - I can just code it so that they automatically "react" to the event (i.e. if something is done being built on a planet, the computer player automatically selects something else to be built there).
Actually, now that I think of it, I might want to create a GameMessage class inside the HumanPlayer class. This class would have (at least) two data members: a message string and a reference to the game object that sent the message.
Thanks again for your post, it really helped to clear things up!
- Rob
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement