Lab Activity: Objects & Orcs Character Interaction and NPC Generation
Objective:
In this lab activity, you will build upon the Objects and Orcs character classes from the lesson. You will create new classes that extend the Character
class, create methods for instances of these classes to interact with other objects, and write a function that generates non-player characters (NPCs) with random properties.
Instructions:
- Create new classes that extend the
Character
class. Use your creativity to build unique derived classes based on Objects and Orcs characters. Some examples could beWarrior
,Mage
, orRogue
. - Add methods to your classes that allow instances of the classes to interact with other objects, such as attacking or casting spells on other characters. For example, you could create a method called
attack(target)
that decreases the target's health based on the attacker's strength. - Create a function called
generateNPCs(n, characterClass)
that takes an integern
and acharacterClass
as arguments. This function should generaten
number of NPCs with random properties and attributes for the givencharacterClass
. For instance, if thecharacterClass
isWarrior
, the function should generaten
warriors with random strengths, health, etc.
Example:
class Warrior extends Character {
// ...
attack(target) {
// ...
}
}
class Mage extends Character {
// ...
castSpell(target) {
// ...
}
}
function generateNPCs(n, characterClass) {
// ...
}
const npcWarriors = generateNPCs(5, Warrior);
Requirements:
- Create at least three unique derived classes that extend the Character class.
- Implement methods for instances of these classes to interact with other objects.
- Write a function that generates n number of NPCs with random properties and attributes.