Lecture 2 (Examples)


TicTacToe

For this task, we have created a simple TicTacToe game. The game has room for two, one, or zero players. In this example, we shall explore the area of making an intelligent computer player and see actually how it can be integrated into this particular game. Here is the relevant code:

Pong Applet

We have created a very very simple unrefined Pong game, written as an applet. For this lecture, we shall explore some of the details of the game to improve it. In particular, we shall add an AI system to control one of the game's paddles. This task is much more difficult as the AI must work in real-time at the same time that the system is busy handling all the other tasks as well. One approach is to make a thread. Here we get in to Operating Systems programming and we'll see how far we get for this basic issue. But for starters here is the pong applet.

Before we go into some basic details about this particular applet, here are the relevant links:

Details

If you look carefully at the Pong source code, you will see three classes. One deals with the Pong game itself and the other two are for Paddle objects and Ball objects.

The code is somewhat long, about 500+ lines of programs. But, it is designed to be somewhat flexible so adding new features can be easier - sometimes.

Look through the code to get a broad idea of how it works. For example, each Paddle comes equipped with two rectangles: one describes the paddle itself, the other describes its "motion" range. This prevents a paddle from moving outside of its bounds. The reason? To allow more flexible movement while being able to easily define where it can move to.

There are a lot of features so don't try to understand all of it. Look at the method names, descriptions, my limited commenting (sorry), and such to get an idea what is going on. After you have a clear idea of what is happening, think about what you want to do to improve the game.

When it comes to actually implementing changes, you will most likely need features from the AWT package or similar classes. The Pong game currently does use some of these features but by no means does it use all. Refer to the APIs and browsing the documentation to find a method or class that suits your needs. There is a lot there and it is hard to predict exactly what you will need.

Improvements

One thing we would like to do is to improve the game, or create an entire new game with Pong as the basis.

What I recommend for improvements here is to be creative. Try to change the game as much as possible to do what you like. Here are just a very few suggestions:

Oh, and sorry there is no Pong sound available!