A little help with oop

Started by
3 comments, last by GameDev.net 24 years, 5 months ago
I usually just keep a global variable of type Game. I use a pointer, but it's up to you, I guess.

It fits in with OOP because the game object should be global - it's the only one that can (and should) be accessed by every class.

Advertisement
I have to agree with null_pointer on this one. If you keep the game object global you will save yourself time. For one, the game object remains persistent throughout the windows application so there is no need to force local scope on it because it will not be recycled until the application closes.

The next thing I would do is use the standard windows menu classes for implementing a menu for this type of game. It will place your menu object in the windows framework which will allow easier access to Game->Board.

Once the Game is running and you have setup a Board you primarily should work within the Board class and its members to perform the individual user functions. A array of tiles(or tile objects) would work nicely here with member functions corresponding to selecting and matching the tiles up.

The Game class should track things that are needed to setup a board, and maybe the time the user has spent playing. Anything that is actually on the board surface should be tracked and manipulated using the board object and possibly a tile object.

These are just my thoughts on the whole subject. I hope they help.

Kressilac

------------------
Derek Licciardi

Derek Licciardi (Kressilac)Elysian Productions Inc.
My menu is graphical so I don't think I can use windows menus.
But thanks anyway.
The game itself is actually finished, but I need a way for Board to tell Game if it is finished and in what way(no more moves left or really finished) and also how long it took.
I'm trying to make a mahjongg game for a c++ project usig objects. My first object called Game has al the information about the state of the game and send the windows messages to my other objects : Board(the game itself) and Menu(my graphical menu). So Game has an object Board and Menu.
Each class is defined in an other file to keep it readible. But now i want to be able to change variables in Game from within Board and Menu. I use return variables right now but that is not good enough. I want to be able to call a member funtions from Game from within Board. Should I use extern Game in my file with the board class or pass a pointer to my Game object to Board when I create Board?
Also would this be a correct way for making a game (using a game object that keeps track of the status of everything) or is this normaly done in a completely ohter way.

Hope anybody can understand what I mean

Track your time in the Game class and check the state of the Board class during your input or output routine. Set the state of Board to completed when the Match member function matches on the last tiles. There are many ways to do it. If you iterate the rest of the board and come up with hints you can even use the lack of hints(a.k.a. no more tiles match) to stop the game when no new combinations are possible. Hope this helps.

As for your menu situation since this is more a piece of the GUI then it is a piece of the game, you might want to try to make the menu global as well. This will allow you to access the menu function in the same manner you do the game functions. *shrug*

Kressilac
ps When your input/output routine finds that board is flagged completed it should then perform the cleanup necessary to finish the game.

[This message has been edited by kressilac (edited November 24, 1999).]

Derek Licciardi (Kressilac)Elysian Productions Inc.

This topic is closed to new replies.

Advertisement