Home > Articles > Software Development & Management > Object Technology

  • Print
  • + Share This
From the author of

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.

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.1 The Brickles start-up configuration

Figure 1.2 Interactions between puck and boundaries

Figure 1.3 Puck interactions with bricks

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.

Figure 1.4 Puck interactions with the paddle

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.

Exercises

  1. Consider an application that will be used to schedule conference rooms in an office. The application has a graphical user interface that allows a user to indicate a date, a time of day, and a duration (in fifteen-minute increments). It then shows a list of conference rooms available at that time and allows a room to be reserved. The system also allows a user to cancel a room reservation. The project is to be developed incrementally—that is, in increasing amounts of functionality. Consider the following two plans. Which is more likely to succeed? What testing can be done at the end of each increment?

  2. Plan A

    Plan B

    Increment 1: Develop user interface

    Increment 1: Develop capability to enter date, time, and duration, and show room availability

    Increment 2: Develop data storage subsystem

    Increment 2: Develop capability to reserve a room

    Increment 3: Develop application subsystem (reservation handling)

    Increment 3: Develop capability to cancel a reservation


  3. Make a list of the features in the object-oriented programming language(s) your company is using that have no counterparts in a language used previously. Next to each feature, jot down how you might approach testing software that's using your specific language.

  4. If you are currently working on a project, identify increments or major milestones. Some of them might be informal. Think about the testing activities that you can do during each increment and what you can test at the end of each.

  • + Share This
  • 🔖 Save To Your Account