Overview
In this lab you will continue to use control structures such as if statements and loops. You will also continue to create your own classes and work with instances of those classes. New to you in this lab will be the introduction of logical operators and writing your own methods.
Procedures
- Sphere volume application
- View a finished release candidate
- Open a new instance of VS08
- New Project... > Console Application > Name it: SphereTest (pay attention to where you save it)
- Right click on the project name in Solution Explorer (in bold), select Add > New Item...
- Choose Class
- Name it: Sphere.cs
- Click Add
- Inside class Sphere
- Create a method: public void DetermineSphereVolume()
- Inside Main
- Instantiate a new instance of Sphere
- Use that instance to call DetermineSphereVolume()
- Inside DetermineSphereVolume()
- Prompt the user for the radius of a sphere
- Convert the response into a double and store it
- Call SphereVolume
- Write out the response
- Pause for the Enter key
- Create a new method: public double SphereVolume
- Accepts one parameter of type double
- Uses that parameter in the equation for the volume of a sphere
- Returns the volume
- Test your project
- Block Shooter
- View a finished release candidate
- Open a new instance of VS08
- New Project... > Windows Forms Application > Name it: BlockShooter (pay attention to where you save it)
- Layout
- Use these images:
- plane, laser, background, icon
- Layout the controls in the application similar to what you see in the release candidate
- form should be 1024 x 768 pixels
- add background image
- add icon
- add a pictureBox containing the plane (initial location: 477, 438)
- name the pb appropriately
- remove the form border
- add buttons for: Start Game, Pause Game, New Game, Quit, and Fire!
- name the 5 buttons appropriately
- add 2 labels: one that says "Score: " and one to contain the score
- name the changeable label appropriately
- add a "Game Over" label in the center of the screen
- name the label appropriately
- add 36 buttons - 3 rows of 12 - evenly spaced
- add a label containing your name in the lower right corner (10pt)
- Coding
- Declare private variables:
- bool: stopGame, isMovingRight, kill
- int: numKills, numBlocks, pointTotal
- Laser: laserGun
- Create the method: public void ChangeColor(Button btn, int level)
- set the FlatStyle of the button
- set the color of the button using RGB based on which row the block is in
- Form Constructor
- set the scoreTotal text
- set the game over visibility
- call the ChangeColor method for each block(button)
- Add an event handler for the Quit button -- Application.Exit()
- Add an event handler to Start Game button - this makes the plane move
- set stopGame to false
- set the focus to the Fire button
- while stopGame is false
- Sleep value of 1 (number can vary depending on speed you want)
- Logic to move the plane left or right
- Add an event handler to Pause the game
- Add a new class: public class Laser
- Declared variables: PictureBox pbLaser, bool stopLaser
- Constructor:
- Create the method: public void ShootLaser(int startX)
- set the laser beam top and left
- add the laser beam to the form
- Create the method: public void StopLaser()
- Add an event handler to Fire the laser
- Check to see if the game is paused
- Instantiate a new instance of Laser
- Call ShootLaser to set the position of the laser beam and add to form
- Remove the Fire! event handler (prevents user from firing multiple times)
- Call the moveLaser method
- Add the Fire! event handler back
- Create the method: public void moveLaser()
- add a while loop to move the laser beam up the screen, pausing each time
- call detectKill() for each block(button) to see if we hit anything
- set kill back to false for next firing of laser
- Create the method: public void detectKill(Button btn, Laser laser)
- Use logical operators to determine if you've destroyed a block
- i.e.: top middle of laser beam is between left & right edges of block
- If it's a kill
- set the button visibility
- set the laser visibility
- set kill to true
- increase numKills
- Calc point total for the kill based on the color of the block(button)
- increase the scoreTotal
- check to see if the number of kills equals the number of blocks
- end of game - set stopGame to true
- display game over label
- If it's not a kill
- set the laser visibility
- set the laser to null
- Add an event handler to start a new game
- reset the values for the declared variables
- set game over label visibility
- set plane position
- set visibility for 36 buttons
- call the Start Game event handler
- Test your project
- Finalization
(do this for both applications)
- Build > Configuration Manager
- Change "Active solution configuration" to Release.
- Make sure "Configuration" changes to Release.
- Close
- Rebuild
- Look in <project folder> / bin / Release
- Double click <projectName>.exe
- On your own
- Write the pseudocode for each application in a large comment block at top of the .cs files. Be thorough with your pseudocode. It should be easily readable by anybody (regular english terminology). Essentially, if there's a line of code, there should be a line of pseudocode. You do not have to write pseudocode for the "layout" code.
- Turn in both entire projects.
Grading
Console App |
5 pts |
Block Shooter App |
10 pts |
Commenting of Code |
5 pts |
|
|
Total |
20 pts |
|