Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Microsoft CSharp Programming For The Absolute Beginner (2002) [eng]-1.pdf
Скачиваний:
46
Добавлен:
16.08.2013
Размер:
15.71 Mб
Скачать

Chapter 8: Arrays: The Soccer Game

By now, you know how to control the logical flow of a program. Although this logical control is important, experienced programmers know that understanding how information is stored in your programs can be even more critical. By carefully designing your data schemes, you make your programs easier to read and maintain. Now you will find out how arrays are used to store lists of information. In this chapter you will learn how to

Create and use single−dimension arrays.

Use two−dimensional arrays to create tables.

Work with the various methods and properties of the array object.

Use the foreach loop with arrays.

Write custom event handlers.

Build visual components without the Form Designer.

Register event listeners without using the Form Designer.

Create arrays of visual controls.

The Soccer Game

The final project for this chapter is a simple game of soccer, as shown in Figure 8.1. The user is in control of a simplified team of five players: a goalie, fullback, halfback, wing, and center. At any time, only one of these players can have control of the ball. The user can click a player to attempt a pass to that player or can take a shot on the goal. The likelihood of a pass's being successful depends on which player has the ball and to whom he is kicking. For example, the goalie will more likely pass successfully to the fullback than to the center, who is usually lurking all the way down the field, because it’s almost impossible for the goalie to successfully shoot on the opposing goal. If the user is unsuccessful in a pass or shot attempt, the opposing team gets the ball and earns the chance to score. The game plays for one minute.

203

Соседние файлы в предмете Программирование на C++