- Use polymorphism to refactor source code
- Use Typescript to build robust, testable code
- Run
npm i
to install dependencies - Run
npm test
to run the tests (src/index.spec.ts
)
The src/index.ts
file contains a Player
class with a single method inside. That method has a lengthy if-else-if chain; your task is to clean it up using polymorphism.
- Use interfaces to define common attributes / logic for attacks
- Try to reduce the
takeHit
method to as few lines of code as possible - You will need to create new classes and define at least one interface
- You may need to update the tests in the
src/index.spec.ts
file, or even create more of them
This exercise is the early stages of your own RPG! Take it further by adding:
- Enemies
- Equipment
- Specific combat encounters
- Spells
- A command-line or user interface to transform it into an interactive text adventure
- A character builder
- Character classes (the RPG kind, not the programming kind)
- Character races