CSE1301 Lab 3 – Defining Classes

advertisement
CSE1301 Lab 3 – Defining Classes
Grading




Did not complete lab - 0%
Submitted a minimal solution with major problems - 33%
Submitted a nearly-complete solution with some minor problems - 66%
All tasks completed correctly - 100%
Objectives



Understand how to define classes
Establish private and public accessible methods and attributes/variables
Instantiating classes into objects
Background
Remember that classes are defined to hold data and behaviors (functions/methods).
Sometimes these should be public (and visible to users of the classes) while other times
these should be private (accessible only within the class itself).
Directions
1. Begin with your lab 2 solution or create a new PSM application
2. Create a new class “Player” that represents your player. This class should have
o a sprite to hold the sprite for the player
o an integer “player number”
o a string “player name”
o a constructor that takes a string (representing the name of the sprite file to
load and use as part of the player), Vector2 (the position of the player –
where they start), an int (the player’s ID), a GraphicsContext, and a string
(representing the name of the player)
 Initialize each variable within the class using these parameters to the
constructor
o a method “Render”
 Use the stored GraphicsContents to draw the sprite that represents
this class
o a method “Update” that takes in two integers, X_change, and Y_change
 modify the position of this player by adding the X_change to the
horizontal and Y_change to the vertical
3. Create two instances of the Player class and position them on different locations
initially, given them different player IDs and different player names.
4. Allow the user to move one player object using Up/Down/Left/Right arrow keys
5. Allow the user to move player two object using different buttons/keys
Challenge
If you feel like it (this is not required), add the ability for a total of four players to control
four different sprites, moving them on the screen using different keys.
If you feel like it (this is not required), use different color modifiers for the Texture2D
sprites for each player (i.e., color one with a red hue and another with a yellow hue, for
example).
Submitting your project
1. ZIP/compress the entire project file for this solution/application.
2. Submit this ZIP file via email to the teaching assistant for the course (or have him
come by and check of you completed the lab during lab hours)
Download