Worksheet 5

COMP140 - Worksheet 5

UML Design Patterns

6. Data Structures

EXERCISE 1

Collections

  1. Fork the following repo
  2. Open the main scene in Unity
  3. Add at least 20 additional items to the collection
  4. Display these to the screen

Start point for Exercise 2 Screenshot of Collections Exercise - Start Point

EXERCISE 2

Sorting

  1. Write a default sort, so that the items are sorted by name
  2. Sort the collection when the s key is pressed
  3. Write another sort, to sort by score, trigger this with a key press
  4. Write another sort, to sort by age, trigger this with a different key press

EXERCISE 3

Searching

  1. Investigate how to search for items in collections
  2. Add code to search for specific items in the collections
  3. Add visual representation to show that the search has completed, this could be a colour change or just displaying the found item elsewhere on the screen.

STRETCH GOAL

ICompare & IComparable

  1. Using this data set which is in CSV format.
  2. Develop a method to parse the data in the file using a struct into either Unity or a VS Console App.
  3. If your using a Unity here’s a clue for parsing the data. It reads all the contents of a file into a single string, splits that string into an array of records, take the first record and splits it on commas, and converts the first value in the split array to a string:
     var fileData : String  = System.IO.File.ReadAllText(path)
     var records : String[] = fileData.Split("\n"[0]);
     var recordData : String[] = (records[0].Trim()).Split(","[0]);
     var name : String;
     string.TryParse(recordData[0], name);
    

    This may also help: https://www.youtube.com/watch?v=xwnL4meq-j8

  4. Create a highscore table that sorts the data to only show the first 20 records with the highest scores.
  5. Create a button or text input instruction to remove all players that are not members from the highscore table.
  6. Extra stretch - Add a sort that shows the 20 most recent high scores in the table.

You may find these articles useful. Find out more: https://dev.to/digionix/icomparable-vs-icomparer-274f https://unity3d.com/learn/tutorials/modules/intermediate/scripting/lists-and-dictionaries

Tasks for the rest of the week

Consider your individual project and implement a data structure class in your code that processes a feature of your game/experience.

For example, you could use them to process:

  • enemies
  • score
  • bullets
  • resource management
  • pick-ups

Please use at least one of these: Lists, LinkedList, Stack, Queue or Dictionary Please bring your code to discuss with your programming tutor in your seminar group.

VIDEO LECTURE

It is assumed that you have watched the video lecture before this workshop. If not you should find time to watch them during the week.

Lecture - Data Structures Part 1

Lecture - Data Structures Part 2