Reversi Skeleton

From Gardenwiki

Jump to: navigation, search

This page is part of the Reversi Tutorial.

Step 1. Generate the Game Skeleton

Now that you have the GGDK (Game Gardens Development Kit) unpacked and Java and Ant installed, you can go into the games directory and create the skeleton of your new game.

Game Gardens comes with a tool to generate the basic skeleton of a game which is run like so:

 % cd games
 % ant newgame

This will display the following output (you will need to enter the text shown in bold and then press return):

 Buildfile: build.xml
 
 newgame:
   [newgame] Please enter a string that will be used to identify your game (e.g. reversi):
 reversi
   [newgame] Please enter the package to use for your game classes (e.g. com.something):
 com.samskivert
   [newgame] Please enter the prefix to use for naming your game classes (e.g. Reversi):
 Reversi
   [newgame] We will generate classes named:
   [newgame]   com.samskivert.reversi.ReversiObject
   [newgame]   com.samskivert.reversi.ReversiPanel
   [newgame]   com.samskivert.reversi.ReversiController
   [newgame]   com.samskivert.reversi.ReversiManager
   [newgame] Is this OK? [y/n]
 y
   [newgame]   Creating 'reversi/build.xml'.
   [newgame]   Creating 'reversi/reversi.xml'.
   [newgame]   Creating 'reversi/rsrc/i18n/reversi.properties'.
   [newgame]   Creating 'reversi/src/java/com/samskivert/reversi/ReversiBoardView.java'.
   [newgame]   Creating 'reversi/src/java/com/samskivert/reversi/ReversiController.java'.
   [newgame]   Creating 'reversi/src/java/com/samskivert/reversi/ReversiPanel.java'.
   [newgame]   Creating 'reversi/src/java/com/samskivert/reversi/ReversiManager.java'.
   [newgame]   Creating 'reversi/src/java/com/samskivert/reversi/ReversiObject.java'.
   [newgame] Done! Your new game has been created in 'reversi'.
 
   [newgame] Go into that directory and try the following commands:
   [newgame]   Build the game: ant dist
   [newgame]   Run the server: ant server
   [newgame]   Run a client: ant -Dusername=NAME client
 
   [newgame] Have fun making your new game.

This creates a number of important classes for you as well as some configuration files. We'll describe each of these files as we progress through the process of creating our game.

First, however, let's make sure that what we've generated works. We should be able to compile the generated code and run our game even though it won't do anything because we haven't made a game yet. We do this using ant, like so:

 % cd reversi
 % ant dist

This will compile all of our code and create a jar file with the compiled classes and resource files.

Because Game Gardens games are multiplayer, they have a client component and a server component. Each client connects to the server and the server passes information between the clients that are involved in a game. The server can also mediate the actions taken by the client to prevent players from cheating by hacking their client, but we won't go into that too much yet. First let's run the server:

 % ant server

This will generate a bunch of logging output and then wait for clients to connect. You will need to open up another terminal window in order to run a client. Do the following in your new terminal window:

 % cd games/reversi
 % ant -Dusername=laurel client

If everything went according to plan, you should see a window pop up that displays the lobby of your game.

Image:Reversi_Lobby_Shot.png

Click on the "Create table" button to create a table at which you can play your game. Notice that there's a second button. By default, the skeleton game is a two player game, so you're going to need another client to test out your game. This means you'll need one more terminal window open so that you can run a server and two clients at once. Open up that terminal and enter:

 % cd games/reversi
 % ant -Dusername=hardy client

Then join your table with your second client and you should see your new game in action:

Image:Blank_Game_Shot.png

It's not very exciting yet, but at least we can see everything working. You should be able to enter chat in one client and see it show up on the other client. So at least we know they're talking to each other.

Now that we've got everything set up, we can get down to the real work of making our game! The next section will talk about defining the state that represents the game and is shared between the clients and server.

Next step: Define the Shared Game State

Up to the Reversi Tutorial.

Personal tools