How to Design Games in Java
This article gives an overview of designing games in Java. At the end of it, you will have a better understanding of how to design games your game using this program.
Things You'll Need
- Paper or index cards
- Java JDK
- NetBeans IDE
- jMonkeyEngine or other Java Games engine
Instructions
-
How to Design Games in Java
-
1
Take a sheet of paper and write out how the game works (or use index cards).
Most Java applications follow the Model-View-Controller (MVC) design. For games, the 'Model' is the game mechanics, the 'View' is the display graphics and the Controller' handles the inputs to the game (keyboard, mouse, joystick).
Get the model working before worrying about graphics. If the model doesn't work, the graphics and sound are pointless.
-
2
The example shows a very simple shooter game with two players. Each player has a rifle and bullets. The shooters can only hit if they can see the target.
Design Java classes from the drawing. In our example we have:
1. Rifle
2. Bullets
3. Shooter
The three classes could be wrapped into one class--ShooterWithRifleAndBullets--but three separate classes allow for the rifle to jam, for the Shooter to get a new rifle, for the Shooter to run out of bullets, for the Shooter to find bullets.
-
-
3
Refine the model.
Java allows objects to be built hierarchically, and we could replace our Rifle and Bullets with more generic classes, Weapons and Ammo.
Pistol, Rifle, MachineGun and Bazooka are sub-classes of Weapon. Bullet and Rocket are sub-classes of Ammo. The diagram also shows that Pistols, Rifles and Machine Guns shoot Bullets while the Bazooka fires Rockets.
Pistol, Rifle, Machine Gun, and Bazooka are sub-classes of Weapon. Bullet and Rocket are sub-classes of Ammo. The diagram also shows that Pistols, Rifles and MachineGuns shoot Bullets, while the Bazooka fires Rockets.
Spend time refining the model. Each Shooter needs to know where he is on the game terrain and where he's looking, so the Shooter class will need a "Location" attribute and a "Facing" attribute. Each Shooter may have a "Health" attribute.
-
4
Code the model classes
Write and test the Java code for the base model classes. A great advantage of working this way is that the Model can be integrated with different Viewers and different Controllers.
-
5
Once the Model is working, integrate it into the View and the Controller. For example, the Model could be integrated with advanced Games Engines such as jMonkey to produce high-speed, high-res, brilliant graphics. The same Model can be used again, or expanded, to allow new features.
Integrating the Model into the Games Engine will require developing graphic images and sounds.
With all the images, sounds, and the Games Engine you're ready to play--and sell--your game!
-
1
Tips & Warnings
Start simple. Consider using Swing and AWT for simple games. Plan for re-use. Generalize your code so that you can use it again and again. Be certain to familiarize yourself completely with Java and your chosen IDE. Be sure to follow the tutorials for your chosen Games Engine (like jMonkey).
Never use graphics or sounds for which you don't have distribution rights.