In this sprint challenge, you will demonstrate your understanding of loops, arrays, the UPER framework, and pass-by-value concepts by implementing a data processing system.
You will be using the same repository from Sprints 1 and 2, and should be completing Mastery Tasks 7, 8, and 9 as part of this challenge.
In this task, you will implement an automated combat system using loops and a file reader to demonstrate your understanding of loops in Java.
Inside of com.adventure.settings.AppSettings
, update the story MT7_MonsterScene
.
You will be working with the following classes:
Monster
(already built) - adventure.world.Monster
CombatController
- adventure.CombatController
Player
- adventure.player.Player
SceneDescriptionFileReader
- adventure.scenes.SceneDescriptionFileReader
When a Player encounters a Monster, the game will build a CombatController that will pit the player and the monster into a battle.
Each fighter takes a turn hitting the other and the one that gets the other fighter to 0 health first, wins.
The amount of health points that are taken away is based on the fighter's power. So if the player has 10 health and the monster has a power of 2, then when the monster hits the player, the player's health goes down by 2 points and the player now has 8.
See the CombatController file for more information on how to properly implement its behavior.
Hint: only one loop should be necessary to complete this task.
You will need to update Player.setWeapon()
. See the function's comments to see how it should work.
Reading files is perhaps the most common use case for while loops. That's because when you read in a file, you don't actually know how long the file is. For loops are used when we know how many iterations are required, so using a for loop here would not work.
This Sprint introduces the capability of scenes to have their descriptions inside of text files as opposed to being hardcoded in classes.
Read the class SceneDescriptionFileReader
to learn about BufferedReader
which is a class commonly used to read in files. It will tell you the essential characteristics of BufferedReader and how to successfully use it to read in a text file's contents.
For Windows Users: To avoid unnecessary errors, make sure the path to your project does not contain spaces.
Bad path: /my project/bd-java-fundamentals-1... Good path: /MyProject/bd-java-fundamentals-1...
To run the tests for this assignment, run the following:
./gradlew test --tests com.adventure.MT7
or by right-clicking the MT7 file and selecting "Run 'MT7'"
You can check your code styling by running the linter with the following command:
./gradlew checkstyleMain
You can run the game by going to the Main class and clicking on the run icon to the left of the main() method.
In this task, you will implement an array-based inventory system to demonstrate your understanding of arrays and loops in Java.
We are going to change how the player object stores items like keys and shovels. Instead of storing them in separate objects, we're going to store them in an array. This will require us to loop through the array to perform various actions.
Open the Backpack
class and read the comments.
Fill in the TODOs to complete the object.
In the Player
object, do the following:
addItem
that takes an item of type Tangible. This method will then pass the item onto the backpack's addItem call.getItem
that takes a String name and returns an object of type Tangible. It will pass this along to the backback's getItem method.removeItem
that takes a Tangible item. This will pass the item onto the backpack's removeItem method.printItems
that calls the backpack's printItems method.With the backpack now complete, we need to include logic for the CommandVerb INVENTORY (you may need to update CommandVerb to account for the INVENTORY enum if it's not already handled).
In GameController
find the method applyCommand
. Add INVENTORY to the switch statement's cases and have it call player.printItems
.
To run the tests for this assignment, run the following:
./gradlew test --tests com.adventure.MT8
or by right-clicking the MT8 file and selecting "Run 'MT8'"
You can check your code styling by running the linter with the following command:
./gradlew checkstyleMain
You can run the game by going to the Main class and clicking on the run icon to the left of the main() method.
In this task, you will implement OmniDoor and OmniKey objects using the UPER problem-solving framework.
In this Mastery Task, we're going to introduce two new objects: OmniKey and OmniDoor. You will want to read the documentation in each of their files carefully and use UPER to come up with the correct solution. Open each of their files and fill in the TODOs to complete the objects.
To run the tests for this assignment, run the following:
./gradlew test --tests com.adventure.MT9
or by right-clicking the MT9 file and selecting "Run 'MT9'"
You can check your code styling by running the linter with the following command:
./gradlew checkstyleMain
You can run the game by going to the Main class and clicking on the run icon to the left of the main() method.