forked from exercism/java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reformat concept exercise Wizards and Warriors (exercism#2729)
* Reformat concept exercise Wizards and Warriors Adding two new tasks so the user has to implement the classes and inheritance concept instead of being given Updating hints, instructions and introduction acordingly to the updated Adding new tests for the new tasks, and update the code given to the student * Update exercises/concept/wizards-and-warriors/.docs/hints.md Co-authored-by: Sander Ploegsma <[email protected]> * Applying suggestions * Modifying the order of the tasks Updating Fighter class to not be abstract Updating instructions and hints Updating tests accordingly * Implementing Reflection proxy for wizard and warriors exercise * Finish tests using reflection proxy * Merging preparespell and isvulnerable tasks for wizard into one task * Update test method names and descriptions * Update the exercise instructions to be less verbose * Clean up reference solution * Add if-else-statements as prerequisite, clean up design.md * Add test to check that prepareSpell is not added to base class * Add TODOs to stub --------- Co-authored-by: Sander Ploegsma <[email protected]>
- Loading branch information
1 parent
b6f79bc
commit 3c73508
Showing
13 changed files
with
833 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -217,7 +217,7 @@ | |
"prerequisites": [ | ||
"classes", | ||
"strings", | ||
"booleans" | ||
"if-else-statements" | ||
], | ||
"status": "active" | ||
}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 48 additions & 34 deletions
82
exercises/concept/wizards-and-warriors/.docs/instructions.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,83 +1,97 @@ | ||
# Instructions | ||
|
||
In this exercise you're playing a role-playing game named "Wizards and Warriors," which allows you to play as either a Wizard or a Warrior. | ||
|
||
There are different rules for Warriors and Wizards to determine how much damage points they deal. | ||
In this exercise you're playing a role-playing game where different types of fighters can combat each other. | ||
The game has different rules for each type of fighter. | ||
We are going to focus on two specific types: Wizards and Warriors. | ||
|
||
For a Warrior, these are the rules: | ||
|
||
- Deal 6 points of damage if the fighter they are attacking is not vulnerable | ||
- Deal 10 points of damage if the fighter they are attacking is vulnerable | ||
- A Warrior is never vulnerable. | ||
- A Warrior deals `6` points of damage if the fighter they are attacking is not vulnerable. | ||
- A Warrior deals `10` points of damage if the fighter they are attacking is vulnerable. | ||
|
||
For a Wizard, these are the rules: | ||
|
||
- Deal 12 points of damage if the Wizard prepared a spell in advance | ||
- Deal 3 points of damage if the Wizard did not prepare a spell in advance | ||
- A Wizard can prepare a spell in advance. | ||
- A Wizard is vulnerable unless they have prepared a spell in advance. | ||
- A Wizard deals `12` points of damage if they prepared a spell in advance. | ||
- A Wizard deals `3` points of damage if they did not prepare a spell in advance. | ||
|
||
In general, fighters are never vulnerable. However, Wizards _are_ vulnerable if they haven't prepared a spell. | ||
## 1. Create the Warrior class | ||
|
||
You have six tasks that work with Warriors and Wizard fighters. | ||
Create a new class called `Warrior`. | ||
This class should inherit from the existing `Fighter` class. | ||
|
||
## 1. Describe a fighter | ||
## 2. Describe a Warrior | ||
|
||
Override the `toString()` method on the `Fighter` class to return a description of the fighter, formatted as `"Fighter is a <FIGHTER_TYPE>"`. | ||
Update the `Warrior` class so that its `toString()` method describes what kind of fighter they are. | ||
The method should return the string `"Fighter is a Warrior"`. | ||
|
||
```java | ||
Fighter warrior = new Warrior(); | ||
Warrior warrior = new Warrior(); | ||
warrior.toString(); | ||
// => "Fighter is a Warrior" | ||
``` | ||
|
||
## 2. Make fighters not vulnerable by default | ||
## 3. Make Warriors invulnerable | ||
|
||
Ensure that the `Fighter.isVulnerable()` method always returns `false`. | ||
Update the `Warrior` class so that its `isVulnerable()` method always returns `false`. | ||
|
||
```java | ||
Fighter warrior = new Warrior(); | ||
Warrior warrior = new Warrior(); | ||
warrior.isVulnerable(); | ||
// => false | ||
``` | ||
|
||
## 3. Allow Wizards to prepare a spell | ||
## 4. Calculate the damage points for a Warrior | ||
|
||
Implement the `Wizard.prepareSpell()` method to allow a Wizard to prepare a spell in advance. | ||
Update the `Warrior` class so that its `getDamagePoints(Fighter)` method calculates the damage dealt by a Warrior according to the rules above. | ||
|
||
```java | ||
Warrior warrior = new Warrior(); | ||
Wizard wizard = new Wizard(); | ||
wizard.prepareSpell(); | ||
|
||
warrior.getDamagePoints(wizard); | ||
// => 10 | ||
``` | ||
|
||
## 4. Make Wizards vulnerable when not having prepared a spell | ||
## 5. Create the Wizard class | ||
|
||
Create another new class called `Wizard`. | ||
This class should also inherit from the existing `Fighter` class. | ||
|
||
## 6. Describe a Wizard | ||
|
||
Ensure that the `isVulnerable()` method returns `true` if the wizard did not prepare a spell; otherwise, return `false`. | ||
Update the `Wizard` class so that its `toString()` method describes what kind of fighter they are. | ||
The method should return the string `"Fighter is a Wizard"`. | ||
|
||
```java | ||
Fighter wizard = new Wizard(); | ||
wizard.isVulnerable(); | ||
// => true | ||
Wizard wizard = new Wizard(); | ||
wizard.toString(); | ||
// => "Fighter is a Wizard" | ||
``` | ||
|
||
## 5. Calculate the damage points for a Wizard | ||
## 7. Allow Wizards to prepare a spell and make them vulnerable when not having prepared a spell | ||
|
||
Implement the `Wizard.damagePoints()` method to return the damage points dealt: 12 damage points when a spell has been prepared, 3 damage points when not. | ||
Update the `Wizard` class to add a method called `prepareSpell()`. | ||
The class should remember when this method is called, and make sure that its `isVulnerable()` method returns `false` only when a spell is prepared. | ||
|
||
```java | ||
Wizard wizard = new Wizard(); | ||
Warrior warrior = new Warrior(); | ||
|
||
wizard.prepareSpell(); | ||
wizard.damagePoints(warrior); | ||
// => 12 | ||
wizard.isVulnerable(); | ||
// => false | ||
``` | ||
|
||
## 6. Calculate the damage points for a Warrior | ||
## 8. Calculate the damage points for a Wizard | ||
|
||
Implement the `Warrior.damagePoints()` method to return the damage points dealt: 10 damage points when the target is vulnerable, 6 damage points when not. | ||
Update the `Wizard` class so that its `getDamagePoints(Fighter)` method calculates the damage dealt by a Wizard according to the rules above. | ||
|
||
```java | ||
Warrior warrior = new Warrior(); | ||
Wizard wizard = new Wizard(); | ||
Warrior warrior = new Warrior(); | ||
|
||
warrior.damagePoints(wizard); | ||
// => 10 | ||
wizard.prepareSpell(); | ||
wizard.getDamagePoints(warrior); | ||
// => 12 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.