Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'reward' property to Unit class #67

Merged
merged 1 commit into from
May 10, 2018
Merged

Add 'reward' property to Unit class #67

merged 1 commit into from
May 10, 2018

Conversation

RascalTwo
Copy link
Contributor

@RascalTwo RascalTwo commented May 10, 2018

This allows Units to reward a set amount of points when killed instead of their max health.


Along with the new test, I tested it in an actual level in which I give a unit a reward, and it works as expected.

Copy link
Owner

@olistic olistic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Except for a couple of comments/suggestions, changes look good.

@@ -157,7 +159,7 @@ class Unit {
damage(receiver, amount) {
receiver.takeDamage(amount);
if (!receiver.isAlive()) {
this.earnPoints(receiver.maxHealth);
this.earnPoints(receiver.reward || receiver.maxHealth);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RascalTwo I prefer we make this check in the constructor, and here just award receiver.reward. Also, there could be scenarios where we want the reward to be 0, which evaluates to false, so we may need to make this check more explicit (like reward === null ? maxHealth : reward).

this.name = name;
this.character = character;
this.maxHealth = maxHealth;
this.reward = reward;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RascalTwo Let's check for null here instead.

*/
constructor(name, character, maxHealth, captive = false) {
constructor(name, character, maxHealth, captive = false, reward = null) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RascalTwo If you put the reward parameter before captive it could make the tests easier because you won't have to worry about passing a value for captive, see comment in the test.

unit.earnPoints = jest.fn();
unit.damage(receiver, 5);
expect(unit.earnPoints).toHaveBeenCalledWith(5);
});

test('earns points equal to reward when killing unit with reward', () => {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RascalTwo Assigning the reward to max health in the constructor makes this test obsolete. Instead, we should pass a reward when instantiating the unit for tests, and add a test to check that reward is assigned to max health when omitted.

@RascalTwo
Copy link
Contributor Author

Thanks for the comments!


So I made the changes you requested, believe I got everything as you intended.

@olistic
Copy link
Owner

olistic commented May 10, 2018

@RascalTwo Thanks for your contribution, and congratulations for being the first contributor in this new stage of the project! It makes me very happy 😄

Would you mind pushing your changes again? I just realized I had the option to build forks disabled in CircleCI.

This allows Units to reward a set amount of points when
killed instead of their max health.
@codecov-io
Copy link

Codecov Report

Merging #67 into master will increase coverage by 0.01%.
The diff coverage is 80%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #67      +/-   ##
==========================================
+ Coverage   86.02%   86.03%   +0.01%     
==========================================
  Files          80       80              
  Lines        1016     1017       +1     
  Branches      153      154       +1     
==========================================
+ Hits          874      875       +1     
  Misses        127      127              
  Partials       15       15
Impacted Files Coverage Δ
packages/warriorjs-core/src/LevelLoader.js 0% <0%> (ø) ⬆️
packages/warriorjs-core/src/Warrior.js 100% <100%> (ø) ⬆️
packages/warriorjs-core/src/Unit.js 91.75% <100%> (+0.08%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 91ba5fd...a102ef8. Read the comment docs.

@RascalTwo
Copy link
Contributor Author

You're welcome, and thank you for taking to time to make those comments, I'm just happy to contribute.

It's quite a fun game, lots of potential.

@olistic olistic merged commit f281141 into olistic:master May 10, 2018
@RascalTwo RascalTwo deleted the feature-unit-rewards branch May 10, 2018 17:21
@olistic
Copy link
Owner

olistic commented May 10, 2018

Just for the record, I'm open to ideas on how to make the game better or more fun 😄. Most of it I think comes from the available levels, abilities, units, etc., so being able to make new ones as plugins for the game is a big plus. I'm writing the docs for Tower makers now.

This PR you just contributed with gives more freedom to makers, which is great!

@olistic olistic changed the title Add 'reward' property to Unit class (#60) Add 'reward' property to Unit class May 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants