Table of Contents
1. Building Projects Using Visual C# Express
Preview 1-1
Introducing Programming Games With Visual C# Express 1-2
Requirements for Progrmming Games With Visual C# Express 1-3
Introducing Visual C# Express 1-4
Structure of a Visual C# Express Project 1-6
Steps in Developing a Visual C# Express Project 1-8
Starting Visual C# Express 1-9
Visual C# Express Integrated Development Environment (IDE) 1-10
Drawing the User Interface 1-19
Setting Properties of Controls at Design Time 1-22
Setting Properties at Run Time 1-27
How Names are Used in Control Events 1-28
Use of the Form Name Property 1-29
Writing Code 1-31
Saving a Visual C# Express Project 1-40
Running a Visual C# Express Project 1-42
Chapter Review 1-44
2. Overview of Visual C# Express Objects
Review and Preview 2-1
Form Object 2-2
Button Control 2-5
Label Control 2-7
TextBox Control 2-9
CheckBox Control 2-12
RadioButton Control 2-14
GroupBox Control 2-16
Panel Control 2-19
ListBox Control 2-21
PictureBox Control 2-23
ProgressBar Control 2-30
Timer Control 2-32
Random Number Object 2-34
SoundPlayer Object 2-36
Chapter Review 2-38
3. Overview of Visual C# Express Programming
Review and Preview 3-1
A Brief History of C# 3-2
Rules of C# Programming 3-3
Variables 3-4
Visual C# Express Data Types 3-5
Variable Declaration 3-7
Arrays 3-10
Constants 3-11
Variable Initialization 3-12
Intellisense Feature 3-13
Visual C# Express Statements and Expressions 3-14
Type Casting 3-16
Visual C# Express Arithmetic Operators 3-18
Comparison and Logical Operators 3-20
Concatenation Operators 3-22
String Functions 3-23
Math Functions 3-28
Visual C# Express Decisions – If Statements 3-30
Switch – Another Way to Branch 3-35
Visual C# Express Looping 3-38
Visual C# Express Counting 3-41
Chapter Review 3-43
4. Debugging a Visual C# Express Project
Review and Preview 4-1
Errors in Visual C# Express Projects 4-2
Debugging Visual C# Express Projects 4-3
Opening a Visual C# Express Project 4-6
Debugging Example 4-8
Using the Debugging Tools 4-10
Writing to the Output Window 4-11
Breakpoints 4-13
Viewing Variables in the Locals Window 4-16
Viewing Variables in the Watch Window 4-18
Call Stack Window 4-19
Single Stepping (Step Into) an Application 4-20
Procedure Stepping (Step Over) 4-22
Procedure Exit (Step Out) 4-23
Debugging Strategies 4-24
Project Design Considerations 4-25
Chapter Review 4-26
5. Safecracker Project
Review and Preview 5-1
Safecracker Project Preview 5-2
Safecracker Form Design 5-10
Code Design – Initializing Stopped State 5-18
Code Design – Stopped to Playing State 5-21
Code Design – Playing to Stopped State 5-24
Code Design – Generating Secret Combination 5-26
Handling Multiple Events in a Single Event Procedure 5-30
Code Design – Accepting Player Input 5-33
Code Design – Checking Player Input 5-38
Code Design – Adding Sounds 5-43
Safecracker Game Project Review 5-50
Safecracker Game Project Enhancements 5-51
6. Tic Tac Toe Project
Review and Preview 6-1
Tic Tac Toe Project Preview 6-2
Tic Tac Toe Form Design 6-10
Code Design – Initializing Stopped State 6-19
Code Design – Stopped to Playing State 6-22
Code Design – Playing to Stopped State 6-25
Code Design – Marking Grid 6-27
Using General Functions in Projects 6-30
Code Design – Checking for Win 6-33
Code Design – Number of Players Selection 6-40
Code Design – Random Computer Moves 6-41
Code Design – Smart Computer Moves 6-46
Code Design – Adding Sounds 6-50
Tic Tac Toe Game Project Review 6-57
Tic Tac Toe Game Project Enhancements 6-58
7. Match Game Project
Review and Preview 7-1
Match Game Project Preview 7-2
Match Game Form Design 7-10
Form Design – Photo Selection 7-23
Code Design – Initializing Stopped State 7-27
Code Design – Integer Shuffling 7-33
Code Design – Stopped to Playing to Stopped State 7-37
Code Design – Displaying Photos 7-43
Code Design – One Player, Solitaire Game 7-51
Code Design – Computer Moves 7-57
Code Design – Random Computer 7-65
Code Design – Smart Computer 7-69
Match Game Project Review 7-81
Match Game Project Improvements 7-82
8. Pizza Delivery Project
Review and Preview 8-1
Pizza Delivery Project Preview 8-2
Pizza Delivery Form Design 8-11
Adding Controls at Run-Time 8-22
Form Design – Building Delivery Grid 8-24
Code Design – Initializing Stopped State 8-28
Code Design – Clock 8-29
Code Design – Phone Orders 8-35
Code Design – Pizza Oven 8-41
Code Design – Load Car 8-53
Code Design – Move Car 8-57
Code Design – Deliveries 8-73
Multiple Form Visual C# Express Applications 8-82
Form Design – Sales Results 8-86
Code Design – Sales Results 8-95
Pizza Delivery Game Project Review 8-103
Pizza Delivery Game Project Improvements 8-104
9. Moon Landing Project
Review and Preview 9-1
Moon Landing Project Preview 9-2
Moon Landing Form Design 9-13
Code Design – Initializing Options, Clock 9-26
Code Design – Physics of Moon Landing 9-36
Remaining Work 9-45
Code Design – Landing Pad Distances 9-46
Code Design – Landing Detection 9-54
Code Design – Pilot Levels and Sounds 9-60
Graphics Methods 9-74
Graphics Object 9-75
Colors 9-78
Pen Object 9-80
DrawLine Method 9-81
Code Design – Trajectory Display, Suggested Path 9-82
Rectangle Structure 9-88
DrawEllipse Method 9-90
Code Design – Trajectory Display, Actual Path 9-91
DrawImage Method – Scrolling Background 9-95
Code Design – Scrolling Landscape 9-96
Sprite Animation 9-106
Code Design – Lander Animation 9-109
Code Design – Autopilot 9-117
Moon Landing Game Project Review 9-130
Moon Landing Game Project Improvements 9-131