



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Project; Professor: McCown; Class: GUI Programming; Subject: Computer Science; University: Harding University; Term: Fall 2007;
Typology: Study Guides, Projects, Research
1 / 5
This page cannot be seen from the preview
Don't miss anything!




GUI Programming Program #1 – Door Prize Due Mon, Oct. 1 100 Points
You are to write a program using C# for picking a door prize winner at the Computer Seminar. The program will allow a user to enter a listing of names and then choose 4-6 names from the list to “compete” against each other. Some type of animation with sound effects will be used in a competition to determine a winner. This program should be similar in nature to the Battleship and Boats programs which are currently being used for seminar.
This program will improve your ability to write C# programs and give you the skills to produce top-quality animation. These skills will be in high demand in your cap-stone class, the Software Development Project.
The most entertaining programs from this assignment will be used in the Computer Seminar next semester!
The following specifications must be met in order to receive all 100 points:
Keep in mind that this program should not have an extremely complicated heuristic- a simple animation path from left to right or top to bottom is sufficient. Be creative, but don’t be overly ambitious; don’t run the risk of turning in a late program. Don’t waste a whole lot of time designing elaborate graphics or finding wave files. Create a basic program that completes from start to finish, and add-on as time permits.
Make your application as intuitive as possible, use helpful user feedback, and make sure your animation is smooth and controlled.
All files required for execution (executable, sound files, bitmaps, etc.) of your program should be in the same directory.
Submit your program before class on the due date with Easel as a zip file. Zip up all your files together along with all your source code. I will not re-build your program from scratch, but I will look through your source code.
Everyone who competes in the games goes into strict training. They do it to get a crown that will not last; but we do it to get a crown that will last forever.
1 Corinthians 9:
public Image Image { get { return image; } }
public int X { set { x = value; } get { return x; } } public int Y { set { y = value; } get { return y; } } public void Draw(Graphics g) { g.DrawImage(image, X, Y); }
public void Draw(Graphics g, int x, int y) { g.DrawImage(image, x, y); } public void Move(Graphics g, Image background, int incx) { // Move player from current location to next one using double buffering. Write your code here… // Update player's location x += incx; } } }
The appropriate use of sound in your program will make it much more exciting. You could use a short “BANG!” wave file that you play when your competitors collide, or maybe use a song wave file to play in the background while the competitors compete.
Sound files can be downloaded off the Internet or obtained from various applications on your computer. The most popular types of sound files are:
There are two ways of playing sound files in a C# application: using a Windows Media Player COM component or using the PlaySound Win32 API function.
Using the Windows Media Player:
The Windows Media Player can play WAV, MIDI, and MP3 files. WMP must first be installed on the computer. The following instructions describe how to add the WMP COM component to your project:
To open and play a sound file: axWindowsMediaPlayer1.URL = "test.mp3";
If you prefer to open the file and not play it until later, set the media player’s autoStart property to false before you load the media file: axWindowsMediaPlayer1.settings.autoStart = false;
Once a file has been opened, it can be replayed using Play: axWindowsMediaPlayer1.Ctlcontrols.play(); You can stop the player by calling Stop: axWindowsMediaPlayer1.Ctlcontrols.stop();
Using PlaySound:
PlaySound API function is only capable of playing WAV files which is sufficient for your project. To use the PlaySound function, you must import the function from winmm.dll. Place the using line at the top of your class file: using System.Runtime.InteropServices; // for DllImport
In your class’s method declaration section, add:
[DllImport("winmm.dll")] private static extern int PlaySound(String filename, int handle, int mode);
Now place a WAV file in the same directory as your executable, and play it like so:
PlaySound("test.wav", 0, 0x0001); // 0x0001 means to play asynchronously
Asynchronous play tells Windows to play the sound and immediately return control to the program. This enables the animation to continue while the sound is being played. To play a sound synchronously, change the last argument to 0x20000.
To stop a sound while playing: PlaySound(null, 0, 0);
You can use PlaySound to play a sound while the MediaPlayer is also playing a sound. Combining the two methods will allow your app to have a “BANG!” at the same time a song is playing.
To randomly select contestants and make the player move randomly, you will need to use the Random class. The following code shows how to get a random number from 1-10:
Random random = new Random(); int num = random.Next(10) + 1;
Each of the contestants should move a random amount throughout the race. You may want to experiment with different increments to see which one produces the best effect.