Coder Social home page Coder Social logo

apprentice-oop-exercise's Introduction

Overview โš”๏ธ ๐Ÿ‰

Today we're creating characters for a game. Each Character has two properties and two methods.

Properties

  • name (string) - The Character's name
  • health (number) - A number between 0 and 50 representing the Character's current health

Methods

  • talk (function) - When spoken to, the character will greet you with their name
  • attack (function) - When attacked, the character can:
    • take damage, decreasing their health
    • counter-attack by returning a number representing damage points against the attacker

The Challenge

Given a base Character class, implement an inherited class for one or more of the character types below. Your character should have the same interface (properties and method) as described above. Your character can have additional properties or methods if necessary, as long as it also implements the above interface.

Your solution should utilize the following:

  • extends to allow your character to inherit from the base Character class
  • super to call and override methods from the base Character class when necessary

Character Types

Wizard

A wizard behaves as follows:

talk

  • When spoken to, a wizard loudly greets you and proclaims their name in all UPPER CASE.

attack

  • When first attacked, a wizard casts a protection spell.
  • While the protection spell is active, the wizard receives no damage and counter-attacks are twice as powerful.
  • The spell lasts for 3 attacks
  • After the spell, the wizard recieves 10 points damage on every attack, and counter-attacks return to the default value.

Rogue

A rogue behaves as follows:

talk

  • When spoken to, a rogue quietly greets you and whispers their name in all lower case.

attack

  • A rogue is difficult to attack. By default they will evade an attack, receive no damage, and return a 5 point counter-attack.
  • On every 5th attack, a rogue lets their guard down and receives 5 points damage. In their weakened state, they return the default counter-attack value.

Getting Started

This repo contains source code in the src repo to get you started, as well as Jest tests to validate your solution. To get started:

  1. Clone this repo
  2. cd into the directory and run npm install
  3. Run the tests with npm test:watch
  4. Locate the characters in the src directory and choose a character to implement.
    • Note: src/character is the base class that the others will inherit from, so don't choose that one.
  5. Locate the character's set of tests in index.test.js
  6. Pending tests are marked with xit. Unpend a test by changing xit to it, watch it fail, and write the code necessary to make the test pass.
  7. Repeat the last step for the rest of the tests in the suite.

Bonus

How would you implement a solution without using the class keyword? For example, using a factory function and object composition?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.