Designing a Java Game

I have contemplated designing a serious Java game many times, but never really considered myself up for the challenge. 3D graphics are too much of a challenge, and building some sort of 2D sidescroller proved to be extremely CPU intensive using the java libraries. I came upon a suitable challenge over Spring break, and have since begun working on a turn based model war game.

Warhammer 40k is a tabletop game in which players collect plastic miniatures which are fielded as their army. Lots of six-sided dice are used in firing, dealing damage, etc. The greatest thing about it is that it is turn based, the events of the game split between moving, shooting, and melee combat. This means I don’t need to worry about the real-time graphics problem, resulting in a game which isn’t beyond the scope of my abilities.

Another reason why I chose Warhammer is because I have marveled at the idea of how cool it would be to see this game officially released on the PC. The game’s problem of arguing over rules and the judgement of distance or line of sight would be eliminated, for the computer would calculate all of that for you. Things would move much faster, you wouldn’t have to spend hundreds of dollars (thousands?) on models, and some sort of campaign mode would let you slowly accumulate a dominating force. After seeing Spore, I thought of how cool it would be to customize your own models, purchase armies, and create striking color schemes. Seeing your models come to life in the 3D virtual world of modern day video games would be breathtaking. Basically, it would be awesome, and getting an extremely basic, 2D version of it up and running is a task worth working on.

Seeing as I am not using any third party software to help me out, (no premade GUIs, OpenGL, etc, except whatever NetBeans provides) I figured it was time to learn how to use the JPanel form in NetBeans. The online tutorial on this is pretty good, and covers the basics for writing an extremely simple temperature converter.

For my game, I figured that a larger layout similar to that of Starcraft would be best, with a large panel depicting the battlefield, a small battlefield map in the bottom left, a central area for depicting the stats of selected units, and an area on the right for buttons such. My crude version still in development looks like this:

This was created, as mentioned, but using the NetBeans JPanel form (right click on your project, new → JPanel form). Netbeans will open up a nice graphical user interface which will help you automatically generate your own user interface for your game. You can design the layout in the GUI section, then modify the code by switching tabs. Swing elements such as buttons, JFrames, borders, and labels can be dragged and dropped in, and the code to create it is automatically written to the file.

I simply added four JFrames and a label for my four panel areas, and set the variable values. A first I was stumped on how to write the code for what is displayed in these frames, but found that creating JFrame classes for each and then editing the code in the auto-generated code to implement these classes worked best.

The end result? A simple GUI I can develop into a decent version of Warhammer 40k!

One thought on “Designing a Java Game

  1. Tim – this web log of yours is growing and is quite comprehensive in a variety of subjects. Keep up the good work.

Comments are closed.