Computer Science 1xx – Assignment #N

DUE DATE: mmddyyyy  

 

The Famous 'Burst-A-Bubble' Game!

 

Learning Objectives:
(This is a list of the major topics that you, as students, will learn in this assignment:)

  1. Inheritance
    In this assignment, you will have to derive a class from the Projectile class, and make use of the inherited methods and/or data fields
     
  2. Overriding / Polymorphism
    In this assignment, you will have to derive a class from the Projectile class, and then override several methods in order to correctly implement the Fireworks class.
     
  3. Understanding and Modifying Existing Code
    In this assignment, a major goal is to expose you to a non-trivial amount of code that someone else has written, and make sure that you can add you code to it.  Further, it is not sufficient to just add code until things work - you need to add a minimum amount of code, that exploits and builds upon the provided code, so that your code is really an extension of the provided code (rather than a hacked together after-thought)
     

Grading Rubric: This document is available for you use - you should use it to  to help guide your work. The rubric is a document which explains how your work will be evaluated, and is located here.


 

In this assignment, you are going to implement a new class, in order to add a feature to a somewhat simple text game. 

 

·         The overall objective of this assignment is for you to create a new class, within an existing, non-trivial program.

 

·         The overall objective of the game is to allow the player to throw small things at floating bubbles, and thus break the bubbles. 

 

The person who's throwing things will be represented by a point at the origin (0,0).  The person initially can only throw small rocks.  Each rock that's thrown will be represented by a circle that has a radius of 1. 

 

Your primary task for this assignment will be to implement a 'Fireworks' class. In order to successfully accomplish this, you'll need to fill in a small (but important!) amount of code in the Fireworks.cs file itself (which is located in the Projectiles folder).  The key difference between a Fireworks object and Rock object is that the Rock object will always be the same size (until it is removed from the screen), whereas a Fireworks object will stay the same size for predetermined number of iterations through the main loop, and then explode.  When it explodes it expand to a radius of 20 units (after is explodes, the fireworks is removed from play, no matter where it is on the screen).  As you're implementing the Fireworks class, keep in mind that our fireworks aren't affected by gravity – they change their X & Y position based on their X & Y speed each round, and nothing else.

 

Since one of the objectives for this assignment is to start getting used to working with non-trivial amounts of pre-existing code, you will need to utilize existing code, rather than (re)writing the logic from scratch.  For example, you'll notice that the starter code (in Fireworks.cs) that has been provided to you already inherits from the Projectile class.  Thus, you'll need to first spend some time examining how the existing game code decides to remove an object from the screen, how to set the size of an object, etc, etc, and only after you've done that, will you then implement your Fireworks class.  It is recommended that you find something similar to the Fireworks class (such as the Rock class), and spend some time examining how that similar class works, in order to figure out what abstract & virtual methods you need to override, and how you should go about overriding them. 

If you wish to improve the game (i.e., go above and beyond the requirements of this assignment, and add a feature(s) that aren't already present in the program), you should talk to the instructor, first, in order to make sure that you don't accidentally violate the rule that you're not allowed to unnecessarily modify code to complete the assignment.

 

 

Your secondary objective is to randomly place the bubbles that are used in the game:

 

As part of creating a new game, the BurstABubble class will place bubbles on the screen.  You will need to modify this, so that the Bubbles are placed randomly, rather than in fixed locations, which is how they are currently placed, in the student starter project.

Each Bubble has an (X,Y) location (which is the center point of the circle), and a radius between 4 and 10.  Each bubble should be at least 10 units away from the player on each of the X axis, and at least 10 units away on the Y axis – in other words, far enough away that there's a chance the player might miss them (e.g., they don't overlap the origin, etc). Four bubbles should be pretty close (under 30 units' distance on each axis), and four should be farther away (at least 30, and no more than 70 units of distance on the X axis, and at least 10, and no more than 50, units up on the Y axis).  It is fine for any randomly placed bubbles to overlap.  Make sure that you avoid the use of magic numbers in your code.

 

As you examine the code, you'll notice that the m_bubbles array will have more than 8 spaces in it  - the total number of bubbles will always be 40.  You are required  to place the remaining bubbles on the screen, in one of three ways:

  1. Randomly, anywhere on the screen 
    It is fine for a randomly placed bubble to be partially off the screen, but at least 50% of every bubble must be on the screen.  It is fine for any randomly placed bubbles to overlap.  If you chose this option, it must be possible for a bubble to place at any location that's on the screen (i.e., you can't chose to only place bubbles within a subsection of the screen)
     

  2. In a nice, visually pleasing (and non-random) pattern of your choosing
    You're welcome to come up with some sort of interesting pattern here - circles, stars, spirals or anything else you can think of.  The only requirements are that
    (a) no two bubbles can be at the exact same location, and
    (b) the 'shape' can't be too simple (i.e., don't use choose this option, then put all the bubbles in a line, in
    order to avoid the work of having to figure out how to randomly place the bubbles anywhere on the board :)  )
    (c) you need to place the bubbles with a (reasonable) minimum of code.  In particular, simply creating 32 ( = 40 - 8) bubbles on 32 separate lines, and hard-coding the location of each individual bubble on each of those lines, will get you no credit.
     

  3. A combination of the above
    For example, maybe you'd like to create a spiral of 20 bubbles, then place the rest randomly, anywhere on the screen.

 

An outline, in pseudocode, of the game is as follows:

 

The game starts out by creating a BurstABubble object (described briefly, below), which in turn creates 4 Bubble objects.  Each Bubble has an (X,Y) location, and a radius between 4 and 10.  In addition to your above task, you should also modify the program so that it chooses the radii and location randomly.  Each bubble should be at least 10 units away from the player on each of the X and Y axes – in other words, far enough away that there's a chance the player might miss them (e.g., they don't overlap the origin, etc). Two bubbles should be pretty close (under 30 units' distance), and two should be farther away (50-70 units' distance).  The bubbles never move.  The game will then enters the main loop.

 

The game mostly consists of a main loop (in the PlayRound method), whose underlying purpose is  to move everything that the user has thrown (according to the speed each thing is traveling at), then print out the state of the game, then to ask the user if they want to throw another thing.  Keep in mind that most of this logic has been implemented for you – I’m including this description here to help you figure out what you'll need to do.

First , the game will go through the array of things that have been thrown, and moves each thing (by calling the DoUpdate method).  Each Rock is moved based on the X, Y speed of the Rock. After moving each thing, the program simulates the effect of gravity on each Rock by adjusting the vertical speed of the thing (gravity should pull the rock downward at a rate of 2 units of speed per update).  Fireworks aren't affected by gravity – they change their X & Y position based on their X & Y speed each round, and nothing else. 

As the program moves each thing, it checks to see if the thing overlaps one of the Bubbles.  If the thing does, then a message will be printed to the screen telling the user that the Bubble has been burst.  If a thing hits the ground (it's vertical height becomes zero), then it is removed from play (it doesn't bounce, etc).  Each thing disappears once it's clear that the rock/Firework/etc can't possibly interact with any bubbles (i.e., once the rock has gone past the bubbles, or hit the ground)

Having done that, the game will then print out the state of each object in the game – every single Rock, Firework, and Bubble.  AGAIN, THERE IS NO GRAPHICAL COMPONENT FOR THIS GAME.  Simply calling the Print method on each object is fine.  The objective here is that since there's no graphical display, the user needs some way of knowing where everything is.  The game ends once the player has thrown all of his/her rocks,  and all of the thrown rocks have been removed from play (i.e., all the rocks have been thrown, and either hit the ground, or sailed past all the bubbles).

Having done all that, the user is asked if they want to throw a rock, shoot a firework, just wait for a round (and do nothing), or quit the game.  If the user chooses to throw a rock, they get to choose the speed in the horizontal (X-axis) direction, and in the vertical (y-axis) direction.  The game then creates a new Rock object, which consists of the speed components (X,Y), starts off with the location being at the origin (0,0), and a Circle that's of radius 1.   The player isn't allowed to throw rocks at a horizontal or vertical speed of greater than 10 units per round.  If the player elects to shoot a firework, they also get to choose their initial horizontal & vertical speed, but are limited to a maximum of speed of 20 in either direction, and a minimum speed of 10 in each direction (since they're not really throwing the fireworks, as aiming it).  They also have to select how many round (iterations through the main loop) will pass until the firework explodes.

The game limits the player to 3 rocks, and 3 fireworks.  If the player runs out of things to throw before breaking all the bubbles, then the player loses.  If the player bursts all the bubbles, the player wins.

 

            You are provided with a starter project for Visual Studio 2005.  You NEED to use the starter project for this assignment.  Also, the .ZIP of the starter project contains a .EXE named Sample_Solution.exe, which has the Fireworks implemented (although the bubbles locations' aren't randomized), in case you want to play around with how the game 'should' work.

 

 

Group Work, Commenting:

 

            You are not allowed to work in groups for this assignment.  You should start, finish, and do all the work on your own.  If you have questions, please contact the instructor.

 

            Additionally, you should aggressively comment your code, paying particular attention to areas that are difficult to understand.  If you found something to be tricky when you wrote it, make sure to comment it so that the next person (the instructor, who's grading you) understands what your code is doing.  It is not necessary to comment every single line.

 

The purpose of this requirement is to both help you understand, and have you demonstrate, a thorough understanding of exactly how your program works.

 

Every file that you turn in should have:

·        At the top of each file that you normally edit     , you should put your name (first and last), the name of this class (“BIT 142”), and the year and quarter, and the assignment number, including the revision number, which starts at 0 (“A4.0”).  If you’re handing this in again for a regrade, make sure to increase the minor version number by one (from “A4.0”, to “A4.1").
You normally edit the C# source code files (.CS files), and any Word documents that you're handing in (if any).
You do not normally edit the .SLN or .CSPROJ files, and so you should not try to put this identifying information in those files.

 

In general, you should make sure to do the following before handing in your project:

·        All variables used should have meaningful names.

·        The code should be formatted consistently, and in an easy to read format.   

 

What to turn in:

 

·        A single electronic folder (a directory).  This folder should contain:

o       The source code for the classes.  For this assignment, each class should go into a separate .CS file.

o       The project files – stuff ending in .SLN and .VCPROJ, so I can build your project more easily.

o       You have to name the folder with your last name, then first name, then the assignment number (both the major version – 4, and the minor (revision) number – 0).  Example: "Panitz, Mike, A4.0"

 

·        You should not include the bin or obj subdirectories, or anything from it.  I will dock you a couple points if you do.  Also, you don't need to include your .NCB file, or the .SUO file, if it's present.

 

How to electronically submit your homework:

There's a link on the homework page to the document that guides you through handing in your work, using the SourceGear Vault program.

 


This document and the related materials are developed with support from Microsoft Research Computer Gaming Initiative under the Computer Gaming Curriculum in Computer Science RFP, Award Number 15871.