|
The "Same Game" tutorial"The Same Game": A Simple Game from Start to Finish I like the look of this example as it shows a point and click game that does a bit more than "hello world", but hopefully not enough to be incomprehensible.So I'm looking at this tutorial from cprogramming.com and it is clear that things have moved on a little, at the time of the tutorial's writing the lowest tier of Visual Studio was "express" which did not include the required libraries. At this time (2022) the entry tier of Visual Studio is the "community" version, which does include the required "Microsoft Foundation Classes", though they do need to be selected in the installer. The MFC project template is easy enough to find: Following the tutorial things start to go a little bit "off the rails"so I'll do my best to muddle through matching the VS2022 options to the VS2005 tutorial images I got that one wrong, and I might have to go back and do it all again as I don't know how to correct it later but apart from the Generated Classes page looking totally different I think things are going OK so I'll finish the "Wizard". At this point something actually builds and runs: though to be fair at this point it doesn't actually do anything except show an about box and close. page 2: Document/View Architecture Document/View ArchitectureThere's a brief discussion of document/view architecture which I won't repeat except to note that:
The Document: Keeping Your DataIn which we finally come into contact with some code. Note that #include "StdAfx.h" is now #include "pch.h", don't worry. The "#pragma once" directive indicates that the header file should only be included once even though it may be reached multiple times, in the same way that "include guards" do in "C". The advantage of #pragma once is it doesn't need macro names for each file and by skipping whole files it makes the build process more efficient. A disadvantage is not all build environments recognize it. Also note that if the application is still running then you'll get an error when you recompile as it can't overwrite a running program. There is a lot of template "boilerplate" code that you need to leave untouched. More than there is in the tutorial so it is tricky to work out exactly what to add. Another "Gotcha" to watch for is that when you go to add a class called "CSameGameBoard" the names of the files also get the extra letter and end up as "CSameGameBoard.h" and "CSameGameBoard.cpp". These need to be corrected to "SameGameBoard.h" and "SameGameBoard.cpp" to match the tutorial. If they've already been created and then renamed then the #include line in "SameGameBoard.cpp" will also need correcting. Page 3: The View: Drawing your Game This stage is where I start to come seriously unstuck. I'm having the utmost difficulty reaching the correct "properties" window. First I need to look in the "View" menu and select "Object browser".
With CSameGameView selected the Properties box (bottom right) finally shows the required view. After the changes have been made we get: The section across the bottom shouldn't be there, but I don't know how to remove it. Removing the unwanted status barIt turns out the bar is only referenced in two places and these are easily commented out: The Declaration in MainFrm.h:
and the initialization in MainFrm.cpp:
At this point the application runs as expected. |