Programming Games With Java
Table of Contents
1. Introduction
Preview 1-1
Introducing Games With Java 1-2
Requirements for Games With Java 1-3
Downloading and Installing NetBeans 1-4
Testing the Installation 1-7
Getting Help with a Java Program 1-13
Structure of a Java Program 1-14
Structure of a Java GUI Application 1-15
Swing Controls 1-17
Stopwatch – Creating a Java Project with NetBeans 1-20
Stopwatch – Create a Frame 1-26
Saving Java Projects with NetBeans 1-29
NetBeans and Java Files 1-30
Create the User Interface 1-31
Stopwatch – Adding Controls 1-35
Adding Event Methods 1-41
Stopwatch – Writing Code 1-45
Chapter Review 1-53
2. Safecracker Project
Review and Preview 2-1
Safecracker Project Preview 2-2
Frame Design – GridBagLayout Manager 2-10
Safecracker Frame Design 2-15
Code Design – Initializing Stopped State 2-36
Code Design – Stopped to Playing State 2-39
Code Design – Playing to Stopped State 2-42
Code Design – Generating Secret Combination 2-44
Code Design – Accepting Player Input 2-49
Code Design – Checking Player Input 2-54
Sounds in Java 2-59
Code Design – Adding Sounds 2-61
Safecracker Project Review 2-68
Safecracker Project Enhancements 2-69
Safecracker Project Java Code Listing 2-70
3. Tic Tac Toe Project
Review and Preview 3-1
Tic Tac Toe Project Preview 3-2
Tic Tac Toe Frame Design 3-10
Code Design – Initializing Stopped State 3-33
Code Design – Stopped to Playing State 3-36
Code Design – Playing to Stopped State 3-39
Code Design – Marking Grid 3-41
Code Design – Checking for Win 3-45
Code Design – Number of Players Selection 3-52
Code Design – Random Computer Moves 3-53
Code Design – Smart Computer Moves 3-58
Code Design – Adding Sounds 3-62
Tic Tac Toe Game Project Review 3-68
Tic Tac Toe Game Project Enhancements 3-69
Tic Tac Toe Project Java Code Listing 3-70
4. Match Game Project
Review and Preview 4-1
Match Game Project Preview 4-2
Match Game Frame Design 4-10
Photo Selection 4-40
Code Design – Initializing Stopped State 4-43
Code Design – Integer Shuffling 4-50
Code Design – Stopped to Playing to Stopped State 4-54
Code Design – Displaying Photos 4-60
Timer Object 4-67
Code Design – Adding Delays 4-70
Code Design – One Player, Solitaire Game 4-78
Code Design – Computer Moves 4-84
Code Design – Random Computer 4-91
Code Design – Smart Computer 4-96
Match Game Project Review 4-108
Match Game Project Improvements 4-109
Match Game Project Java Code Listing 4-110
5. Pizza Delivery Project
Review and Preview 5-1
Pizza Delivery Project Preview 5-2
Pizza Delivery Frame Design 5-11
Code Design – Initializing Stopped State 5-44
Code Design – Clock 5-45
Code Design – Phone Orders 5-52
Code Design – Pizza Oven 5-59
Code Design – Load Car 5-68
Code Design – Move Car 5-73
Code Design – Deliveries 5-86
Multiple Frame Java GUI Applications 5-95
Frame Design – Sales Results 5-97
Code Design – Sales Results 5-114
Pizza Delivery Project Review 5-122
Pizza Delivery Project Improvements 5-123
Pizza Delivery Project Java Code Listing 5-124
6. Moon Landing Project
Review and Preview 6-1
Moon Landing Project Preview 6-2
Moon Landing Frame Design 6-12
Code Design – Initializing Options, Clock 6-44
Code Design – Physics of Moon Landing 6-54
Remaining Work 6-63
Code Design – Landing Pad Distances 6-64
Code Design – Landing Detection 6-72
Code Design – Pilot Levels and Sounds 6-75
Graphics Methods 6-88
Graphics2D Object 6-89
Stroke and Paint Objects 6-90
Shapes and Drawing Methods 6-91
Line2D Shape 6-93
Code Design – Trajectory Display, Suggested Path 6-95
Persistent Graphics 6-102
Ellipse2D Shape 6-108
Code Design – Trajectory Display, Actual Path 6-111
Rectangle2D Shape 6-116
Code Design – Guide Display 6-119
Scrolling Background – drawImage Method 6-123
Code Design – Scrolling Landscape 6-125
Sprite Animation 6-135
Code Design – Lander Animation 6-140
Code Design – Autopilot 6-148
Moon Landing Project Review 6-160
Moon Landing Project Improvements 6-161
Moon Landing Project Java Code Listing 6-162
Appendix. Installing Java and NetBeans