SSE643Project3-OTVClassStructure

=OTV Miner Class Structure =

=2. OTV Miner Class Structure=

 2.1. The OTV Miner game concept has been laid out. The next part of the process is to define the class objects that will make up the game play. My partner and I decided on the following class structure. This class is the base for all of our objects.



 2.1.1. Here is the code implementation:



 2.1.2. The GameObject has one constructor.



 2.1.3. And the remaining components in the class are get/set methods to access the individual class components.



 2.2. The Ship class inherits from the GameObject and is used as the main object for the game. The main ones completed are the movement actions.



 2.2.1. The class starts off by implementing the characteristics that the ship class has that are unique to it.



 2.2.2. The ship class has one constructor.



 2.2.3. Here are the standard get/set methods.



 2.2.4. The LoadContent method sets us the sound for the ship. At this time I don’t have a sound attached to it.



 2.2.5. The RotateShip gets input from the gamepad of keyboard and translates it to movement.



 2.2.6. The MoveShip method takes input from the keyboard/gamepad and translates it to movement. This method works with the new quadrant class and looks for the ship to leave the screen. When the ship reaches the top of the screen, for example, the method checks if the current quadrant can exited. If it can the quadrant is changed based upon the direction you are going and the ship is drawn to the appropriate part of the screen. It also looks to see if the ship is moving (by using the up or down arrows). If it is the moving variable is set to true so the ship animation can be drawn.



 2.2.7. The method continues with the key down logic.



 2.3. The Quadrant class was created so I can track movement in the game and distribute rocks, elements, and enemies in the game. It is a straight forward implementation of a square grid with odd number dimensions. The smallest size (used in testing) is a 3x3 grid with a total of nine quadrants. By setting the constants in the code you can easily change the size of the quadrant space.



 2.3.1. The class starts with the main variables that keep track of the actions. The curquad member holds the current quadrant. The MaxQuadrants (in the Constants Class) variable defines the quadrant size you want. In the game we are using a 5x5 playing area which gives us 25 areas where we can place objects to interact with. STARTQUAD (in the Constants Class) is the middle position where you start. I also set up a random variable to put objects in the game with. The constructor sets the starting quadrant.



 2.3.2. The property setting is for the most part straight forward. QUADOFFSET (in the Constants Class) is how many quadrants you need to move when you go up or down. The MoveUp method subtracts the offset constant and updates the current quadrant. The CheckMoveUp method calls a private function that iterates through the quadrants to find the current row you are at. If the row is one than your current position you can’t move up.



<span style="font-family: Tahoma,Geneva,sans-serif; font-size: 12pt;"> 2.3.3. The next set of methods are the remaining movement checks. You have to verify you can move before you actually move.



<span style="font-family: Tahoma,Geneva,sans-serif; font-size: 12pt;"> 2.3.4. The two private functions in the class find the current row or column based upon the current quadrant. The main part of this function is to check the modulus of the loop counter and compare it to the offset constant. If it is zero then you are at the last column and thus the next number will be the next row. The loop goes until the loop counter is equal to the current quadrant.



<span style="font-family: Tahoma,Geneva,sans-serif; font-size: 12pt;"> 2.3.5. The last method returns a random quadrant for object population.



<span style="font-family: Tahoma,Geneva,sans-serif; font-size: 12pt;"> 2.4. The Animation class was modeled after the class used in the book “A Simple Introduction to Game Programming With C# and XNA 3.1 (C. Bennett)”. The class offered all of the functionality that I needed to make my animation work in this project.



<span style="font-family: Tahoma,Geneva,sans-serif; font-size: 12pt;"> 2.4.1. The class starts out by creating a structure object to hold each image in the animation.



<span style="font-family: Tahoma,Geneva,sans-serif; font-size: 12pt;"> 2.4.2. The class defines several tracking variables. One to check to see if looping is enabled, it the animation is stopped, and if the animation is playing. The most important part of the class is the List object that holds all of the frames for the animation. I added the position, rotation and center members to fit in with my objects.



<span style="font-family: Tahoma,Geneva,sans-serif; font-size: 12pt;"> 2.4.3. The add cell method is how you add each image for the animation. I modified this from the original by centering the image location. When I was first using this class everything was centered on the bottom left corner. When you create an Animation object all you have to do is pass a position variable to establish a location. There are also two ways to set the position, you can pass in the X & Y coordinates or you can vend in a Vector2 object. I added the SetRotation method so I could use the ship animation in the game. The SetMoveRight and SetMoveLeft methods are not used in the game in this point. It flips the image back and forth for side to side movement.



<span style="font-family: Tahoma,Geneva,sans-serif; font-size: 12pt;"> 2.4.4. The main method in the class is the LoopAll function. It sets the looping member variable and gives a starting and ending cell. It sets the current cell and a time shift variable. The loop method has a set starting point and ending point.



<span style="font-family: Tahoma,Geneva,sans-serif; font-size: 12pt;"> 2.4.5. The GotoFrame method sets the current image to the specified index.



<span style="font-family: Tahoma,Geneva,sans-serif; font-size: 12pt;"> 2.4.6. The PlayAll method sets the environment to play all of the frames. The Play method starts at the given start position and ends at the specified end position.



<span style="font-family: Tahoma,Geneva,sans-serif; font-size: 12pt;"> 2.4.7. The Draw method looks to see what cell is currently active and if the list is empty, before the first image, or over the total images it returns without drawing. The update method is what does all of the animation. It checks to see if the image is stopped. If so nothing happens. If the image is not stopped then it evaluates the total time against the time shift. If total time is greater than it resets the total time the variable, increments the current cell, and checks to see if looping is turned on. If it is and the cell count is at the end, it resets to the beginning. If the animation is set for one pass and it is at the end, the playing variable is turned off and the current cell is set to the last frame.



<span style="font-family: Tahoma,Geneva,sans-serif; font-size: 12pt;"> 2.4.8. The last three methods are ones I added. I placed all of the image setup in here to make my code a little cleaner.



<span style="font-family: Tahoma,Geneva,sans-serif; font-size: 12pt;"> 2.5. The AsteroidObject Class simply tracks the current state of the asteroid object.



<span style="font-family: Tahoma,Geneva,sans-serif; font-size: 12pt;"> 2.5.1. The AsteroidObject class tracks the type of asteroid the object (i.e. small, medium, or large)



<span style="font-family: Tahoma,Geneva,sans-serif; font-size: 12pt;"> 2.5.2. The AsteroidObject class also defines an enumeration of asteroid sizes.



<span style="font-family: Tahoma,Geneva,sans-serif; font-size: 12pt;"> 2.6. The ElementObject class is as simple as the AsteroidObject class. It tracks its type (i.e. os3, laser fuel, propulsion fuel) and the objects collection value.



<span style="font-family: Tahoma,Geneva,sans-serif; font-size: 12pt;"> 2.6.1. Definition of the class. Sets the current type when created and randomly finds a value for the element when collected.



<span style="font-family: Tahoma,Geneva,sans-serif; font-size: 12pt;"> 2.6.2. The ElementObject class also defines an enumeration of element types.



<span style="font-family: Tahoma,Geneva,sans-serif; font-size: 12pt;"> 2.7. The Menu class sets up the initial screen the user sees when they start the game. The can see the keyboard layout, the story behind the game, and set the difficulty level.



<span style="font-family: Tahoma,Geneva,sans-serif; font-size: 12pt;"> 2.7.1. I start the class out by defining a structure with each image for the menu item. The I establish some tracking variables and constants.



<span style="font-family: Tahoma,Geneva,sans-serif; font-size: 12pt;"> 2.7.2. Next I load all of the menu options the user will encounter. I also have the AddCell method to add each image to the objects list of menu items.



<span style="font-family: Tahoma,Geneva,sans-serif; font-size: 12pt;"> 2.7.3. The next methods set up the ExitState of the program so it knows when to exit. The StartState is used to track if the user is playing the game. I also store the difficulty level the user selects. By default it is set to 2.



<span style="font-family: Tahoma,Geneva,sans-serif; font-size: 12pt;"> 2.7.4. Next is the largest method of the class. The update method tracks the keys the user selects and shows the appropriate menu item. If the arrow keys are used it moves through the menu items.



<span style="font-family: Tahoma,Geneva,sans-serif; font-size: 12pt;"> 2.7.5. If the user hits enter the method looks to see what item was selected. If 1 is selected it starts the game. If selected is greater than zero (you are in a sub menu) it takes you back to the main menu. If you are in the main menu, it will set the selected variable to the selected menu. If the escape key is pressed it checks to see what state the game is in. If it is in the menu state it closes the program down. If you are in the middle of the game it takes you back to the main screen.



<span style="font-family: Tahoma,Geneva,sans-serif; font-size: 12pt;"> 2.7.6. The draw method looks at where the menu selection is at. It displays the appropriate menu for the current selection.



<span style="font-family: Tahoma,Geneva,sans-serif; font-size: 12pt;"> 2.8. We took all of the constants in each class and put them into the Constants class.



<span style="font-family: Tahoma,Geneva,sans-serif; font-size: 12pt;"> 2.8.1. You can control all of the constant variables from this class.



<span style="display: block; font-family: Tahoma,Geneva,sans-serif; font-size: 115%; text-align: center;">Project Home Next Section