Java 7 for Absolute Beginners

(nextflipdebug5) #1

C H A P T E R 1 2


221

Video Games


By “video games,” I mean games which have very limited controls and a primary interface that is
somehow animated. Other computer games still use animation but aren't video games in classic
parlance. For example, an old game called BattleZone (which I used to play in college) is a video game.
Civilization, in all of its incarnations, is a computer game but not a video game. What's the difference?
Complexity and the skill used to play the game. Video games tend to be simple and require dexterity.
Other games tend to be more complex and rely on intelligence. As an avid gamer, I enjoy both,
depending on my mood.
I bet a lot of the people who read this book want to learn to write video games. Fair enough. I
probably would do that, too. If you love games so much that you jumped to this chapter first, I suggest
you at least read the chapter on animation as those concepts very much apply to programming video
games.


The Mechanics of a Video Game


Before we plunge into the game, let's first consider the core components of a video game in terms that
aren't specific to any programming language, including Java. Then, as we go through a couple of
examples, we can talk about how the examples implement these mechanics. Video games consist of
three main pieces:



  • The user interface

  • The game logic

  • The game loop


The User Interface


As we have seen in the previous chapters, any program with a graphical user interface devotes much of
its code to creating and responding to that user interface. Unfortunately, that can mean losing sight of
the game logic in the user interface code. Complex games (such as most modern video games) separate
the logic from the presentation (another name for the user interface) by having the logic in one set of
classes and having the presentation in another set of classes. Simple games may blend logic and
presentation in the same classes (though probably in different methods). The sample games in this
chapter use the latter organization as they are very simple games. We've already discussed the idea of
blending logic and presentation in Chapter 6, “Object-oriented Programming.”


Java 7 for Absolute Beginners

© Jay Bryant 2012


J. Bryant,

Free download pdf