VCL.Football Sample

From RAD Studio Code Examples
Jump to: navigation, search

Language:

This sample simulates a desktop football game, using the TImage class to perform drawing on the window client area.

Contents

Location

You can find the Football sample project at:

Description

This application consists of a football game. The user controls the running back. There are two difficulty levels: PRO1 and PRO2. PRO2 is for more advanced levels and the tacklers move quicker than in PRO1 level.

For more information on the gameplay, select Help > About from the main menu of the application.

How to Use the Sample

  1. Navigate to Start > Programs > Embarcadero RAD Studio > Samples and open Football.dproj.
  2. Press F9 or choose Run > Run.

Files

File Contains

about

The form displayed when the user chooses Help > About.

Main

The form for the game itself.

Classes

  • TAboutForm represents the class for the about form. It contains a TMemo object to display the gameplay instructions.
  • TMainForm is the class for the game form. It contains multiple TImage objects to display the field and the controls. To display the score, the statistics, and the players (the running back controlled by the users and the tacklers controlled by the computer), simple TLabels are used.

Implementation

  • Two TTimer components are used: one for displaying the time on the form (Clock) and the other for simulating the play of the computer (Timer).
  • sndPlaySound from the MMSystem unit is used to play a sound.
  • The spot record is used to handle an item in the field. Each spot is empty if no player exists in that place, or contains a red underscore otherwise. It also stores a Boolean value that indicates whether that player is a running back or not. The field is a two-dimensional array of spots.
  • The Timer.OnTimer event handler is used to randomly move a tackler in the field. The Clock.OnTimer event handler is used to change the time displayed on the form.

Uses

See Also

Personal tools