CS-360
Assignment # 3
Due Date: 10/14/08
This assignment will be the first step in building an interactive "Air
Hockey" game for Windows. You must use the Visual C# programming
language on the Microsoft .NET platform. It will be a Windows Form
application. The animation should be done using a timer and, in this
first version of the program, should start when the application begins
execution. It should also restart any time the user resizes the window.
In this version, the game runs without user intervention in "demo"
mode. Details on what should happen are given below.
The best approach is to modify the Bouncing Ball program discussed in
class so that there is a blue "paddle" (vertical rectangle) moving
continually up and down in the middle of a "playing field". Each time
the ball "hits" the paddle, it should reverse the x component of its
velocity thus giving the impression of an elastic collision with the
paddle. Make the playing field a rectangle that occupies the entire
width of the window's client area. Leave space at the top of the client
area for an information/input/output area that you will use in a later
version of the assignment.
There should be yellow "goals" (vertical rectangles or broad vertical
lines) centered on each end of the playing field. These should be
bigger than the size of the ball. The righthand goal is "your" goal and
the lefthand goal is "my" goal. The program should keep track of and
display the number of goals scored in each. These values should be shown
in the top input/output area of the window's client area and should
appear as something like: "My Score: 2", "Your Score: 3". (The values
displayed will, of course, change as the program runs.) If, when
the ball strikes the right window border, it is entirely within the
vertical extent of the right goal, "your" total should be incremented.
If the ball strikes the left window border within the confines of the
left goal, "my" goal total should be incremented. In either case the
corresponging new total should be displayed.
When either total has reached 10 goals, a message box should declare the
winner of that game ("me" or "you"). Then the score should be reset and
a new game begun.
Whenever a new game is begun and also whenever the user resizes the
window, the ball should be given a random starting position (that does
not coincide with the initial position of the paddle) and a random
velocity in a random direction (i.e. the x and y components of the
velocity should change randomly with each new game and each window
resize). Be sure that none of the new values for the new components of
the velocity are zero. Also be sure that the initial position of the ball
lies within the client area of the window.
The playing field should be a bitmap image that will form the background
over which the game is played. (You may create the image file with any
"painting" editor (Paintbrush, etc.) or use an image in .bmp, .jpg, or
.gif format that you've downloaded or scanned in.) As the ball and
paddle move, the background should not be destroyed. (Hint: look at the
"ImgShadowBitmap" example to be discussed in class, whose link is on the
CS-360 Example Programs web page.)
The following is a "snapshot" of one possible implementation of the game.