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

oppScore.ToString(); } // end updateScore

To update the score, all I had to do was convert the playerScore and oppScore values to strings and copy them to the appropriate labels.

Summary

This chapter helps you begin thinking like an experienced programmer. The way you work with complex data has a profound effect on how successfully you solve interesting programming problems. In this chapter you learned how to build arrays to store lists of information. You learned how to use the properties and methods of the array class to inspect and modify an array. You learned how to build arrays of simple elements such as integers and strings and more complex elements such as picture boxes. You learned how to build a form without using the Visual Designer and how to add event handlers to components you have built by hand. Finally, you put all these skills together to build an interesting game. In the next chapter you will move on to another important part of data manipulation: moving data to and from files.

Challenges

Add multiple difficulty levels to the game. Let the user choose a difficulty, and adjust the opponent’s likelihood of scoring based on the difficulty factor.

Change the likelihood of a pass so that it is related to the distance between the shooter and

the target. You might recall the distance formula from math class: distance = square root of ( (x2 – x1)2 + (y2 – y1)2)

Write a method that accepts two picture boxes, calculates the distance between them, and makes the likelihood of success dependent on that distance.

Make a Windows version of the Snowball Fight program from Chapter 5, “Constructors, Inheritance, and Polymorphism: The Snowball Fight.” Use picture boxes to indicate the players' behavior and buttons to get commands from the user.

Modify the behavior and performance of the Soccer game to mirror a similar sport (hockey, basketball, and volleyball make interesting candidates). Change the images and behavior to mimic the sport. For example, basketball is a much higher scoring game than soccer, so the likelihood of scoring has to be much greater.

235

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