diff --git a/assignments/lambda-classes.js b/assignments/lambda-classes.js index 71acfca0e..ac59f68cd 100644 --- a/assignments/lambda-classes.js +++ b/assignments/lambda-classes.js @@ -1 +1,142 @@ // CODE here for your Lambda Classes +class Person { + constructor(att) { + this.name = att.name; + this.age = att.age; + this.location = att.location; + this.gender = att.gender; + } + speak() { + return `Hello my name is ${this.name}, I am from ${this.location}`; + } +} + +class Instructor extends Person { + constructor(att) { + super(att); + this.specialty = att.specialty; + this.favLanguage = att.favLanguage; + this.catchPhrase = att.catchPhrase; + } + demo(subject) { + return `Today we are learning about ${subject}`; + } + grade(student, subject) { + return `${student.name} receives a perfect score on ${subject}`; + } + + modGrade(student){ + let points = Math.floor(Math.random() * 50); + let chance = Math.floor(Math.random() * 2); + if(chance === 0){ + student.grade -= points; + return `${this.name} removed ${points} points from ${student.grade}, \n + ${student.name} now has ${student.grade} ` + } else{ + student.grade += points; + return `${this.name} added ${points} points to ${student.grade}, \n + ${student.name} now has ${student.grade} ` + } + } +} + +class Student extends Person { + constructor(att) { + super(att); + this.previousBackground = att.previousBackground; + this.className = att.className; + this.favSubjects = att.favSubjects; + this.grade = att.grade; + } + listsSubjects() { + return `${this.favSubjects}`; + //.forEach(subject => console.log(`${subject}`)); + } + PRAssignment(subject) { + return `${this.name} has submitted a PR for ${subject}`; + } + sprintChallenge(subject) { + return `${this.name} has begun sprint challenge on ${subject}`; + } + graduate(){ + if(this.grade > (100*.7)){ + return `${this.name} is ready to Graduate with ${this.grade} !!!!! Congratz ${this.name}` + } else{ + return `Hit the books ${this.name} you have a long way to go -_-` + } + } +} + +class ProjectManager extends Instructor { + constructor(att) { + super(att); + this.gradClassName = att.gradClassName; + this.favInstructor = att.favInstructor; + } + standUp(channel) { + return `${this.name} announces to ${channel}, @channel standy times!​​​​​`; + } + debugsCode(student, subject) { + return `${this.name} debugs ${student.name}'s code on ${subject}`; + } +} +//------------------------------------------------------------------------------------------------------------------------------------------ +const fred = new Person({ + name: "Fred", + age: 35, + location: "BedRock", + gender: "Male" +}); + +const cam = new Instructor({ + name: "Cam", + age: 30, + location: "SanJose, CA", + gender: "Male", + specialty: "JavaScript", + favLanguage: ["HTML 5", "CSS 3", "JavaScript"], + catchPhrase: "Who needs a map" +}); + +const me = new Student({ + name: "Seun", + age: 25, + location: "Brockton", + gender: "Male", + previousBackground: "Systems Analyst", + className: "FSWPT4", + favSubjects: ["HTML 5", "CSS 3", "JavaScript", "React", "Sass"], + grade: 100 +}); + +const elvis = new ProjectManager({ + name: "Elvis", + age: 28, + location: "SanJose, CA", + gender: "Male", + specialty: "Judo Master", + favLanguage: ["JavaScipt", "TypeScript", "React"], + catchPhrase: "Is a leaf's only purpose to fall?", + gradClassName: "CS14", + favInstructor: "Dan" +}); + +console.log(fred.speak()); + +console.log(cam.speak()); +console.log(cam.demo("JavaScript-IV")); +console.log(cam.grade(me, "React")); + +console.log(me.speak()); +console.log(me.listsSubjects()); +console.log(me.PRAssignment("JavaScript-IV")); +console.log(me.sprintChallenge("PreProcessing-II")); + +console.log(elvis.speak()); +console.log(elvis.demo("React")); +console.log(elvis.grade(me, "React")); +console.log(elvis.standUp("Elvis-PT4")); +console.log(elvis.debugsCode(me, "Applied JavaScript")); +console.log(elvis.modGrade(me)) + +console.log(me.graduate()) \ No newline at end of file diff --git a/assignments/prototype-refactor.js b/assignments/prototype-refactor.js index 91424c9fa..5d2a74575 100644 --- a/assignments/prototype-refactor.js +++ b/assignments/prototype-refactor.js @@ -7,3 +7,213 @@ Prototype Refactor 2. Your goal is to refactor all of this code to use ES6 Classes. The console.log() statements should still return what is expected of them. */ + +/* + Object oriented design is commonly used in video games. For this part of the assignment you will be implementing several constructor functions with their correct inheritance hierarchy. + + In this file you will be creating three constructor functions: GameObject, CharacterStats, Humanoid. + + At the bottom of this file are 3 objects that all end up inheriting from Humanoid. Use the objects at the bottom of the page to test your constructor functions. + + Each constructor function has unique properties and methods that are defined in their block comments below: +*/ + +/* + === GameObject === + * createdAt + * dimensions (These represent the character's size in the video game) + * destroy() // prototype method -> returns the string: 'Object was removed from the game.' +*/ + +/* + === CharacterStats === + * healthPoints + * name + * takeDamage() // prototype method -> returns the string ' took damage.' + * should inherit destroy() from GameObject's prototype +*/ + +/* + === Humanoid (Having an appearance or character resembling that of a human.) === + * team + * weapons + * language + * greet() // prototype method -> returns the string ' offers a greeting in .' + * should inherit destroy() from GameObject through CharacterStats + * should inherit takeDamage() from CharacterStats +*/ + +/* + * Inheritance chain: GameObject -> CharacterStats -> Humanoid + * Instances of Humanoid should have all of the same properties as CharacterStats and GameObject. + * Instances of CharacterStats should have all of the same properties as GameObject. + */ + +// Test you work by un-commenting these 3 objects and the list of console logs below: + +class GameObject { + constructor(attributes) { + this.createdAt = attributes.createdAt; + this.dimensions = attributes.dimensions; + } + destroy() { + return `${this.name} was removed from the game.`; + } +} + +class CharacterStats extends GameObject { + constructor(attributes) { + super(attributes); + this.healthPoints = attributes.healthPoints; + this.name = attributes.name; + } + + takeDamage() { + return `${this.name} took damage.`; + } +} + +class Humanoid extends CharacterStats { + constructor(attributes) { + super(attributes); + this.team = attributes.team; + this.weapons = attributes.weapons; + this.language = attributes.language; + } + greet() { + return `${this.name} offers a greeting in ${this.language}`; + } + att(enemy){ + let damage = Math.floor(Math.random(100) * 50); + enemy.healthPoints -= damage; + if (enemy.healthPoints <= 0) { + return enemy.destroy(); + } else { + return `${enemy.name} took ${damage} points of damage`; + } + } + ult(enemy){ + let damage = Math.floor(Math.random() * (100 - 50) + 50); + enemy.healthPoints -= damage; + if (enemy.healthPoints <= 0) { + return `${this.name} uses ${this.ultimate} on ${ + enemy.name + } for ${damage} points! ${enemy.destroy()}`; + } else { + return `${this.name} uses ${this.ultimate} on ${ + enemy.name + }, and deals ${damage} points of damage`; + } + } +} + +class Villain extends Humanoid { + constructor(attributes) { + super(attributes); + this.ultimate = attributes.ultimate; + } +} + +class Hero extends Humanoid { + constructor(attributes) { + super(attributes); + this.ultimate = attributes.ultimate; + } +} + +const mage = new Humanoid({ + createdAt: new Date(), + dimensions: { + length: 2, + width: 1, + height: 1 + }, + healthPoints: 5, + name: "Bruce", + team: "Mage Guild", + weapons: ["Staff of Shamalama"], + language: "Common Tongue" +}); + +const swordsman = new Humanoid({ + createdAt: new Date(), + dimensions: { + length: 2, + width: 2, + height: 2 + }, + healthPoints: 15, + name: "Sir Mustachio", + team: "The Round Table", + weapons: ["Giant Sword", "Shield"], + language: "Common Tongue" +}); + +const archer = new Humanoid({ + createdAt: new Date(), + dimensions: { + length: 1, + width: 2, + height: 4 + }, + healthPoints: 10, + name: "Lilith", + team: "Forest Kingdom", + weapons: ["Bow", "Dagger"], + language: "Elvish" +}); + +console.log(mage.createdAt); // Today's date +console.log(archer.dimensions); // { length: 1, width: 2, height: 4 } +console.log(swordsman.healthPoints); // 15 +console.log(mage.name); // Bruce +console.log(swordsman.team); // The Round Table +console.log(mage.weapons); // Staff of Shamalama +console.log(archer.language); // Elvish +console.log(archer.greet()); // Lilith offers a greeting in Elvish. +console.log(mage.takeDamage()); //Bruce took damage. +console.log(swordsman.destroy()); // Sir Mustachio was removed from the game. + +// Stretch task: +// * Create Villain and Hero constructor functions that inherit from the Humanoid constructor function. +// * Give the Hero and Villains different methods that could be used to remove health points from objects which could result in destruction if health gets to 0 or drops below 0; +// * Create two new objects, one a villain and one a hero and fight it out with methods! + +const licht = new Villain({ + createdAt: new Date(), + dimensions: { + length: 2, + width: 3, + height: 6 + }, + healthPoints: 200, + name: "Licht", + team: "Eye of Midnight", + weapons: ["Light-Magic", "Spatial-Magic", "Fire"], + language: "Elvish", + ultimate: 'Light Blade', +}); + +const yami = new Hero({ + createdAt: new Date(), + dimensions: { + length: 2, + width: 3, + height: 6 + }, + healthPoints: 150, + name: "Yami", + team: "Black Bulls", + weapons: ["Katana", "Dark-Magic"], + language: "Common Tongue", + ultimate: 'Shadow Slash' +}); + + +console.log(yami.att(licht)); +console.log(licht.att(yami)); +console.log(yami.att(licht)); +console.log(licht.att(yami)); +console.log(yami.ult(licht)); +console.log(licht.ult(yami)); +console.log(yami.ult(licht));