Game Creation — Version 0.7

This guide will take you from freshly pulled source code to having your game apart of the KardsGT family. We start off with the assumption that you already have compiled the code successfully before you begin. If you have not done so, read the INSTALL file before continuing. This is a guide for both patchers and developers.

Preparing the files

A handy tarball filled with the basics of a card game can be downloaded . After downloading the file extract the tarball into the game folder of KardsGT. Rename the demo folder to reflect the game you're going to make. For example, if you're going to make the game Cribbage rename the folder cribbage.
Each file represents a class for the game. Each of the classes handle a specific aspect of the game. The purpose of each class is: Now, that you know what each class is for, you can now rename the Demo part of each file to the name of your game. You will also need to do this inside each file.

Creating the Game

The Interface

Finally, we can start to create our game. First thing to do is create the interface. You could code the interface directly into the class, but an easier approach is to use the QT Designer. When you use the designer call the interface class: DemoInterfaceBase. Of course change the name to fit the name of your game. Once you have your new base widget you can create the game layout by using the KardsGT widgets. Since we have a base interface now, we need to modify DemoInterface. Setup DemoInterface to inherit QWidget and DemoInterfaceBase. Be sure to have the QWidget inheritence before the interface inheritence.

Widget Dimentions

The following are the standardised dimentions used in KardsGT.
Widget Name Width Height Widget Usage
Interface 790 550 N/A
Kard Player 90 140 <= 4 Players
Kard Player 60 90 > 4 Players
Kard Sequence 570 100 Horizontal <= 4 Players
Kard Sequence 285 100 Horizontal > 4 Players
Kard Sequence 120 280 Vertical <= 4 Players
Kard Sequence 120 145 Vertical > 4 Players
Kard Play Sequence 400 200 2 Players
Kard Play Sequence 140 300 > 2 Players
Kard Pile 70 90 N/A
Trump Widget 50 40 N/A
The widget usage column lists the condition needed to use that widget.

The Remainder

All of the remaining files are going to be specific to the game you're creating. Each class already has the stubs for all the required methods. How you design your game is up to you, and what you need for your game. You can save a tremendous amount of time by creating a dummy loader for your game, before adding it to KardsGT.

KardsGT Semantics

All of our base classes are designed to remove much of the redundant code from the game classes themselves. As with any generalisation, problems occur. You may not need all the methods, or you might need more. Obviously when you need more the methods go into your game classes. What do you do when you don't need a method? The best option is to throw a KardsGTError, the KardsGT error class, explaining that this method is not to be used. This way if someone calls your method nothing bad will happen to their code, because they will know immediately.
In our rule generalisations we have some specific states that need to be defined. The three distinct states of game play in KardsGT:
  1. Phase:
    The idea is if there are two distinct modes of play, then the "phase" is the first mode in the game play.
  2. Round:
    The idea is if there are two distinct modes of play, then the "round" is the second mode in the game play. If there is only one distint mode of play, the round should be the prefered state over the phase state.
  3. Game Over:
    This is obvious as its when game play can progress no further.

Adding the Game to KardsGT

Add the Menu

Open KardsGTInterfaceBase.ui in QT Designer. Add the name of your game to the menu option under the menu Game->Select. Make the menu option a checkable action. Add the tooltip and status text.

Turn it on

In the KardsGTInterface class create a slot called turnOnDemo. The code to place inside the slot is:
The string passed to selectGameAction should be the name of your game. This string is used to reference the game through-out the programme from now on. Now, connect the menu action to the slot we've just created using the activated signal.

Add the following code to each of these methods: After doing all this you should be able to select the game, but if we're to do that right now KardsGT would throw an exception. This happens because we haven't told our game factory how our new game is to be loaded.

Adding the game to the GameFactory

Now that we have our game available from the interface we want to add it to our game factory. This is done easily enough by first including the interface header to our game in the gamefactory.cpp file. This can be found at the top of the definition file in a block of similar statements.
Now in the method setupGame(UserProfileDatabase &profileDatabase, const QString &game, QWidgetStack &layout) add the following code to the if branch:
else if (game == "demo")
m_pGame = new DemoInterface(profileDatabase, &layout);

Adding the game to the PlayerFactory

In our list of inclusions we have a player listing, it is here we need to add: #include "demoplayer.h".
Inside the player factory class add this code:
setupGamePlayer(const QString &game)
else if (game == "demo")
m_players.push_back(new DemoPlayer(*m_ais.back()));

Adding the source to the project files

Add your game directory to TARGETDEPS, LIBS, and INCLUDEPATH to the file. In the file add your game project directory location in the SUBDIRS location. Also make sure your game project file is setup correctly to compile.
After all this work, we finally have our game finished. Now, you can go bug hunting. Happy hunting. :)
Valid HTML 4.01! Valid CSS! © 2006 - 2008 by John Schneiderman, released under the GNU FDL .
Last Updated: 13 Aug 2008