Skip to content

Instantly share code, notes, and snippets.

@bastienapp
Last active October 6, 2020 12:38
Show Gist options
  • Select an option

  • Save bastienapp/b7f66c30aae4fa01ee3edce898e27987 to your computer and use it in GitHub Desktop.

Select an option

Save bastienapp/b7f66c30aae4fa01ee3edce898e27987 to your computer and use it in GitHub Desktop.
Fire Emblem Heroes

Fire Emblem Heroes

Part 1 : Hero

The Hero class allows you to create objects on this model :

{
    name: string,
    power: number,
    life: number,
    hit: function,
    alive: function
}

The hit method has a damage parameter and should reduce the number of life points of the Hero by as damage received.

The alive method should return true if the number of life points of the hero is greater than zero and false otherwise.

Create two instances of Hero and check that the hit and alive methods work.

Part 2 : Weapons

Add the weapon attribute (of string type) to the Hero class without modifying the constructor (so weapon is not initialized).

Modify the hit method to add a second parameter, weapon.

Create three classes HeroAxe, HeroSword and HeroSpear which inherit from Hero.

These three classes call the constructor of their parent and initialize weapon with the values axe, sword or spear as appropriate.

In the HeroAxe, HeroSword and HeroSpear classes, override the hit method to take into account the following cases:

  • HeroAxe: if the weapon parameter is equal to word, multiply damage by 2
  • HeroSword: if the weapon parameter is equal to spear, multiply damage by 2
  • HeroSpear: if the weapon parameter is equal to axis, multiply damage by 2

Create instances of the three classes HeroAxe, HeroSword and HeroSpear and check that the hit methods work correctly.

Part 3 : Battle

Create a loop that makes two instances of Hero subclasses fight each other (they attack at the same time).

When at least one of them is dead, log {heroName} wins. If both of them are dead, log It's a draw.

Fire Emblem Heroes

Partie 1 : Héros

La classe Hero permet de créer des objets sur ce modèle :

{
    name : string,
    power : number,
    life : number,
    hit : function,
    alive : function
}

La méthode hit a un paramètre damage et devrait réduire le nombre de points de vie (life) du Hero d'autant de dégats (damage) reçus.

La méthode alive devrait retourner true si le nombre de points de vie du héros est supérieur à zéro et false sinon.

Crée deux instances de Hero et vérifie que les méthodes hit et alive fonctionnent.

Partie 2 : Armes

Ajoute l'attribut weapon (de type string) à la classe Hero sans modifier le constructeur (ainsi weapon n'est pas initialisé).

Modifie la méthode hit pour ajouter un second paramètre, weapon.

Crée trois classes HeroAxe, HeroSword et HeroSpear qui héritent de Hero.

Ces trois classes appellent le constructeur de leur parent et initialisent weapon avec les valeurs axe, sword ou spear selon le cas.

Dans les classes HeroAxe, HeroSword et HeroSpear, redéfinisse la méthode hit pour prendre en compte les cas suivants :

  • HeroAxe : si le paramètre weapon est égal à sword, multiplier damage par deux
  • HeroSword : si le paramètre weapon est égal à spear, multiplier damage par deux
  • HeroSpear : si le paramètre weapon est égal à axe, multiplier damage par deux

Crée des instances des trois classes HeroAxe, HeroSword et HeroSpear et vérifie que leurs méthodes hit fonctionnent correctement.

Partie 3 : Bataille

Crée une boucle qui fait que deux instances de sous-classes Hero s'affrontent (elles attaquent en même temps).

Quand au moins l'une d'entre elles est morte, afficher {heroName} wins. Si les deux sont morts, afficher It's a draw.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment