CSE1301 Lab 4 – Collections

advertisement
CSE1301 Lab 4 – Collections
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 use the List<> collection class
Background
Recall that the List<> class can hold any number of items, and these items can be of
any type. Just specify which type of thing you want to hold in the list using the syntax
List<TYPE> collection = new List<TYPE>();
Be sure to use this “new” command to allocate memory for the list before using the
Add() method on the list.
Additionally, the “foreach” loop is useful to process all the elements within a
list/collection.
Directions
1.
2.
3.
4.
5.
Begin with your lab 3 solution or create a new PSM application
Add a “score” integer to your player class from lab 2
Make sure the player name and score are public within your player class
Create a list collection of the player objects
Add four players into this collection
o Provide whatever names you’d like
o Initialize the scores to be 0
6. Modify your PSM game to display the name and score of each player
o Your drawing of the names/scores should be flexible to handle lists of
different lengths, i.e., don’t “hardcode” the positions of the display strings to
the screen; rather, mathematically calculate the correct positions of the output
based upon the overall width of your game and the number of elements to
display. For example, if your list contained 6 elements (use the Length to
determine how many elements are in a list) and your game was 960 wide,
then each name/score would appear at positions ~160 pixels apart.
Draw the name/scores for the four players in your player list
7. Set up your game such that when the keys Z, X, Q, and E are pressed, the scores
are increased for each corresponding player; this should call an IncreaseScore()
function/method that you add to your player class
8. You must use the foreach structure to display all the names/scores
o
Challenge
If you feel like it (this is not required), change the colors that the names/scores use
when they are displayed. Use the Color(R,G,B) structure to do this with different values
for the Red, Green, and Blue to your liking, but you can determine these
mathematically.
Submitting your project
1. ZIP/compress the entire project file for this solution/application.
2. Submit this ZIP file into the D2L system for this lab in the appropriate lab
assignment location.
Download