BIT 142: Assignment 5 Page 1/4 2/12/2016 Functions: Class Composition Due: Wednesday, Nov 23rd In this assignment, you are going to write the backend of a somewhat simplified game. The overall objective of this assignment is for you to create an object-oriented game, and to figure out/implement the logic needed to detect when two circles overlap. The overall objective of the game is to allow the player to throw small stones at floating bubbles, and thus break the bubbles. If you want to substitute another, perhaps less violent, pretense for the game (that still achieves the objectives of the assignment), feel free. You're only allowed to do this if you first get your alternative assignment approved by the instructor. You do not need to provide a graphical (WinForms) interface to this game. If you'd like to you're welcome to, but it's not required. The person who's throwing rocks will be represented by a point at the origin (0,0), and each rock that's thrown will be represented by a circle that has a radius of 1. The floating bubbles will be represented by Circles of radii between 4 and 10, and they're floating far enough away that there's a chance the player might miss them (e.g., they don't overlap the origin, etc). An outline, in pseudocode, of the game is as follows: The game should start out by creating a RockThrowingGame object (described briefly, below), which in turn creates 3-4 Bubble objects. Each Bubble has an (X,Y) location, and a Circle, of radius between 4 and 10. You should choose the radii and location randomly. Each bubble should be at least 10 units, and no more than 30 units, away from the player on each of the X and Y axes. The game will then enter the main loop. The game will consist of a main loop, whose underlying purpose is to ask the user if they want to throw another rock, then move everything a bit, and then print out the state of 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 should then create 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 game should not allow the user to have more than 10 Rocks "in flight" at any one time, even if the player has more rocks, total (e.g., if the player Page 1/4 2/12/2016 BIT 142: Assignment 5 Page 2/4 2/12/2016 were to start with 25 rocks, they could throw 10, but would then have to for a rock to disappear before throwing any of their remaining 15 rocks). The player isn't allowed to throw rocks at a horizontal or vertical speed of greater than 10 units per round. Next, the game will go through the array of Rock objects, and moves the location of each Rock based on the X, Y speed of the Rock. As it moves each Rock, it checks to see if the Rock overlaps one of the Bubbles, then a message will be printed to the screen telling the user that the Bubble has been burst. After moving each rock, you should simulate the effect of gravity by adjusting the vertical speed of the rock (gravity should pull the rock downward at a rate of 2 units of speed per update). If a rock hits the ground (it's vertical height becomes zero), then it is removed from play (it doesn't bounce, etc). Each rock should disappear once it's clear that the rock 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 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). In order to do this assignment, you need to create the following classes. You don't need to create any methods on the classes that you don't use. Feel free to create more classes, if you want to. This table explains what the table following it is intended to convey: Class (inherits from this class, if any) Composed of Used for Point Integers for the X, Y location Circle The radius GameEntity To track the location of things To track things that are circular Circle Point Rock Integer for the speed in the X direction Integer for the speed in the Y direction Bubble <This class has no additional data To represent the space occupied by something in the game To represent the entity's current location Inherits from GameEntity To represent the speed of the rock Inherits from GameEntity Page 2/4 2/12/2016 BIT 142: Assignment 5 fields> Player <Decided by the programmer> RockThrowingGame A collection of Bubbles A collection of Rocks A Player Page 3/4 2/12/2016 Keeps keeping track of the number of Rocks that are left Stores where the bubbles are Represents the rocks that the player has thrown, and are still 'in flight' Represents the data about the player. Note: Main should basically create a RockThrowingGame, and then call a method named something like playGame on the RockThrowingGame object. You need to create a .CS file for each class that you create. Make sure to name the file so that it's the same as the name of the class it contains. Notice that the Bubble and Rock classes inherit from the GameEntity class – if you see any other opportunities for inheritance, please feel free to use inheritance there, too! 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 the file, 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 (“A5.0”). If you’re handing this in again for a regrade, make sure to increase the minor version number by one (from “A5.0”, to “A5.1"). 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. Page 3/4 2/12/2016 BIT 142: Assignment 5 Page 4/4 2/12/2016 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 – 5, and the minor (revision) number – 0). Example: "Panitz, Mike, A5.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. Page 4/4 2/12/2016