You will continue to add functionality to your existing project from the previous task. There is no new repository to clone.
For this task, you will be writing code in the following classes:
SampleTopDownGame
, located in the package app.games
Enemy
, located in the package app.games.topdownobjects
You will also need to create new classes in these locations with these names (case-sensitive):
Pathfinding
, in the package app.gameengine.model.ai
(You will also need to create the ai
package in the specified location. To do this,
right-click the model package and choose new -> package)
TestTask2
, in the package tests
You will also be using the provided LinkedListNode
class from the app.gameengine.model.datastructures
package. You may find it helpful to add methods to this class, however you cannot modify or remove
any of the given code.
You can use these additions in your implementation, but not in your tests (the TestTask2 class). The
solutions in Autolab will use this class as given so using extra methods in your tests will cause errors
when your tests are ran against these solutions.
Video link: https://youtu.be/kNhIJL5VPkk?si=i3aTK3mdM4OSiZfA
Our amazing TA Josh has made another overview video for Task 2. This video goes over the specifications for the task, the LinkedListNode class you will be using, and a conceptual overview of the goals for this task. It also covers some practical examples of using recursion in this task, which is not required, but is highly recommended. It is available on the cse116 Youtube channel, and is linked above
As before, watching this video is optional, and all of the information you need for this task is contained within this page. However, you may find it helpful for getting a better understanding of the task, and what is expected of you
In this task, you will test and implement the following specs. All methods are public and non-static, except
for the findPath
method which is static.
First, we'll update the SampleTopDownGame
to use a Linked List of levels to control the flow of
the game. Players will travel through each level in this list as they play through the game
SampleTopDownGame
- Linked List Operations
SampleTopDownGame
class named llL
for linked list level. Then, add the following
methods in this class that will interact with your instance variable. This list should initially
be empty (Please use the provided
app.gameengine.model.datastructures.LinkedListNode
class for your linked list)
getLevelList
: Take no parameters and returns the head of the
LinkedListNode of Levels stored in your instance variable
null
setLevelList
: Takes a LinkedListNode of Levels and returns void
addLevel
: Takes a Level and returns void
removeLevelByName
: Takes a String and returns void
getName
method within a level to get the name of that level
as a String
SampleTopDownGame
- Modifications
init
method will be modified to add the three given levels to the Linked List
before the given loadLevel
call. The resulting list should contain the
levels returned by the methods levelZero
, levelOne
, and
levelTwo
in this order and call loadLevel
on the first level
in the list ("level0")
advanceLevel
method to use the Linked List
of levels. When this method is called, call this.loadLevel
on the
next level in the list. To do this, first find the current level in the list then get the
level at the next node
getCurrentLevel
method to access the current
level.
getName
method within a level to get the name of
that level as a String
loadLevel
with an argument of null
)Now, will see another application of Linked Lists by adding movement to the enemies of our game. Your code will compute paths for enemies to follow and set their velocity to travel these paths. With these updates, the enemies will hunt the player.
Pathfinding
- findPath
method
Pathfinding
in the app.gameengine.model.ai
package (You'll also have to create this ai
package)
Pathfinding
class you created, write a static method
called findPath
that takes in two Vector2D objects as parameters and returns a
LinkedListNode of Vector2Ds.
Enemy
Movement - Path Operations
app.games.topdownobjects.Enemy
class
setPath
: Takes a LinkedListNode of Vector2D objects and returns void.
This method sets an instance variable (That you'll create) representing the Enemy's path that
they'll follow
getPath
: Takes no parameters and returns a LinkedListNode of Vector2D objects.
This method returns the instance variable representing the Enemy's path
null
update
: Takes a double and a Level and returns void. This method is called
every frame (60 times per second) and the double represents the
number of seconds that have passed since the last update which won't be used in this task. You
will add functionality to this method so enemies will "hunt" the player:
null
, use the findPath
method
from the Pathfinding
class to generate a path from the Enemy's location to
the Level's Player's
location. You have access to the player through the level object parameter. This path
will then be stored in your instance variable (The same one
controlled by setPath
and getPath
)
1.0
Note: You can see feedback in Autolab for your testing utilities and tests without completing the programming portion of this task, but you must at least create the classes and methods that you test. You can "stub out" these methods by having them always return a fixed value, but they must exist so the grading code, and your tests, can compile and run.
Create a class named TestTask2 in the tests package and write the following methods in that class (Note: Do not add the @Test annotation to these methods since they are not tests):
validatePath
- Write a method named validatePath
that:
findPath
method to determine validity
of a path. This means that every pair of vectors in the path must be horizontally or vertically
adjacent (no diagonals), and each vector must have x and y components that are whole numbers.
Add test methods to the tests.TestTask2 class, using the @Test annotation, that tests the following method from the specification:
findPath
method from the Pathfinding
class
validatePath
testing utility method can make this much simpler to test.
Don't forget to also check that the length of the returned path matches the shortest length
Implement all the functionality from the specification.
The feedback in Autolab will be given in 4 phases. If you don't complete a phase, then feedback for the following phase(s) will not be provided.
Once you complete all 4 phases, you will have completed this Task and Autolab will confirm this with a score of 1.0 for complete.