2006-03-21

On Menu actions

Step 7: All of the menu items concerned with changing the game (its size or colour cycle) can be written the same way.

Example;
on selecting size X by X
{
Set Document's changed size flag to true.

Set Application's size variable to X.

Call OnNewDocument() to recreate Board.

Update View.
}

on updating size X by X menu item
{
Set check if Application's size variable == X.
}


Note 1: Accessing the Application class's members is not hard but there is one trick to remember. AfxGetApp() returns a pointer to the CWinApp base class, not a pointer to the Application class. You will need to cast the pointer in order to get to the Application's class members, i.e. (CPoggle*)AfxGetApp().
And yes it would be better to use dynamic_cast to recast the pointer. Just remember use a try and catch structure for possible mis-casting.
[UPDATE] Standard OO mistake here. Directly accessing the Application's variables is not good form. It would be much better to use Set / Get functions.

Note 2: Changing the Board's size and the Board's colour cycle really do not need to be handled in the same manner as only changing the size means re-allocating memory. So this is another item that can be improved later on.

No comments: