A Continuing Example Brickles


A Continuing Example Brickles

We will use an example throughout the book to illustrate various testing approaches and techniques. This will allow us to focus on the testing techniques rather than taking space to set up a variety of examples. In this section we will introduce the game of Brickles, an interactive computer game. This game is very similar to Breakout, one of the first commercial video games and a popular game played on Apple II computers.

This example has its origins in a course we developed to teach object-oriented design concepts and C++ programming. Our goal was to find an application whose design was simple enough to understand and complete in a week of training, while at the same time it was both conducive to enhancements and interesting to programmers whose backgrounds range over a variety of application domains and environments. Our goal for this example, both in that course and in this book, is solely to illustrate concepts about the design and testing of object-oriented programs.

Basic Brickles Components

Brickles is an arcade game whose starting configuration is shown in Figure 1.1. The play field is rectangular, bounded by two walls, a ceiling, and a floor. The play field contains an array of bricks referred to as the "brick pile." A player's objective is to break all the bricks in the brick pile by hitting each brick with a puck that can be struck by a paddle under the player's control. When the puck hits a brick, the brick breaks. A puck bounces off walls, the ceiling, bricks (as they break), and the paddle. At the start of play, a player is given three pucks with which to destroy the bricks. A player wins a game when all bricks have been broken. A player loses if the supply of pucks is exhausted before all of the bricks are broken.

Figure 1.1. The Brickles start-up configuration

graphics/01fig01.gif

When play starts, a puck placed in the center of the play field begins to move in a downward direction. The paddle is controlled by the player with a mouse attached to the computer. The player must move the paddle so that the puck hits the paddle and not the floor. When the puck hits the paddle, it bounces upward. Whenever the puck hits a brick, the brick is destroyed. If the puck misses the paddle and hits the floor, it is removed from play and one of the remaining pucks is put into play. If all pucks are lost to the floor, play ends and the player loses.

Brickles Physics

As the puck moves through the play field, it encounters various components of the play field. The interactions between them are as follows (see also Figure 1.2, Figure 1.3, and Figure 1.4).

Figure 1.2. Interactions between puck and boundaries

graphics/01fig02.gif

Figure 1.3. Puck interactions with bricks

graphics/01fig03.gif

Figure 1.4. Puck interactions with the paddle

graphics/01fig04.gif

Ceiling and walls The puck bounces off the ceiling and walls in accordance with the laws of physics, neglecting friction and gravity that is, the angle of reflection equals the angle of incidence.

Floor The floor absorbs pucks. A puck that hits the floor does not rebound, but is removed from play.

Bricks The puck bounces off a brick such that the angle of reflection equals the angle of incidence. Upon being struck, a brick is destroyed. Note that bricks can be hit by a puck from above as well as from below. They also have sufficient thickness that they can be hit from the side. For the sake of simplicity, it is acceptable to assume that bricks are treated as though they have no thickness. Thus, it is only the vertical component of the puck's direction that is changed when the puck hits the brick.

Paddle The player uses a paddle to control the direction of the puck. The puck bounces off the paddle based on both the direction of the puck as it hits the paddle and the part of the paddle that's hit. Divide the paddle into thirds and define the near third as being the left third of the paddle if the puck is coming in from the left, and the right third if the puck is coming in from the right. Define the far third similarly, and the middle third as the remaining third. The rules of reflection are as follows:

  • If the puck hits the paddle on its near third, then the puck returns in the exact opposite direction from which it came.

  • If the puck hits the paddle on the middle third, then the angle of reflection is a little steeper than the angle of incidence. The puck's movement is constrained such that it must never be completely vertical.

  • If the puck hits the paddle on the far third, then the angle of reflection is a little shallower than the angle of incidence. The puck's movement is constrained such that it must never be completely horizontal.

Puck The player is given a fixed number of pucks at the beginning of the game, but only one is in play at any given time. Once one puck hits the floor, the next is brought into play (assuming another is available). The puck has a current direction and speed and moves according to an automatic timer. Collisions may change the direction of the puck, but not the speed.

Game Environment

The first implementation of Brickles runs as an application within a Microsoft Windows environment and behaves as follows:

  • The game shall start when the program is launched.

  • A player can "exit" the game at any time before it is won or lost.

  • A player can "pause" the game at any time until play ends.

  • A player can "resume" a paused game.

  • A congratulatory message shall be displayed in the case of a player winning the game. Similarly, a consolation message shall be displayed in the case of a player losing the game.



A Practical Guide to Testing Object-Oriented Software
A Practical Guide to Testing Object-Oriented Software
ISBN: 0201325640
EAN: 2147483647
Year: 2005
Pages: 126

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net