From 4c3363c2e6f2d11f2a3050ef23c9a7da94e5d0e3 Mon Sep 17 00:00:00 2001 From: Jashele T Date: Thu, 30 May 2019 17:42:49 -0700 Subject: [PATCH 1/7] refactored game object: protype refactor.js --- assignments/prototype-refactor.js | 193 ++++++++++++++++++++++++++++++ 1 file changed, 193 insertions(+) diff --git a/assignments/prototype-refactor.js b/assignments/prototype-refactor.js index 91424c9fa..fba91d26d 100644 --- a/assignments/prototype-refactor.js +++ b/assignments/prototype-refactor.js @@ -7,3 +7,196 @@ 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: +*/ + + +// Notes: +// GameObject -> CharacterStats -> Humanoid + + + + +// === GameObject === + // function GameObject(GameObj) { + // this.createdAt = GameObj.createdAt; + // this.name = GameObj.name; + // this.dimensions = GameObj.dimensions; // (These represent the character's size in the video game) + // }; + + + // Object Refactored: + + class GameObject { + constructor(GameObj){ + this.createdAt = GameObj.createdAt; + this.name = GameObj.name; + this.dimensions = GameObj.dimensions; + } + +// GameObject.prototype.destroy = function() { +// return `${this.name} was removed from the game.`; // prototype method that returns: `${this.name} was removed from the game.` +// } + + // Prototype Refactored: + destroy() { + return `${this.name} was removed from the game.`; + } +} + + + + + + + // === CharacterStats === + + + function CharacterStats(charAttrs) { + GameObject.call(this, charAttrs); + this.healthPoints = charAttrs.healthPoints; + }; + + CharacterStats.prototype = Object.create(GameObject.prototype); + + CharacterStats.prototype.takeDamage = function () { + return `${this.name} took damage`; + } + + // function CharacterStats(CharStats) { + // CharacterStats.prototype = Object.create(GameObject.prototype); + // this.healthPoints = CharStats.healthPoints; + + + + // // should inherit destroy() from GameObject's prototype + // }; + + // CharacterStats.prototype.takeDamage = function() { + // return `${this.name} took damage.`; // prototype method -> returns the string ' took damage.' + // } + + + + + + + // === Humanoid (Having an appearance or character resembling that of a human.) === + + function Humanoid(HumanoidAttr) { + CharacterStats.call(this, HumanoidAttr); + this.team = HumanoidAttr.team; + + this.weapons = HumanoidAttr.weapons; + + this.language = HumanoidAttr.language; + + }; + + + + Humanoid.prototype = Object.create(CharacterStats.prototype); + // should inherit takeDamage() from CharacterStats + + + + Humanoid.prototype.greet = function() { + return `${this.name} offers a greeting in ${this.language}.` + // prototype method -> returns the string ' offers a greeting in .' + + + } + + + + + + + + + /* + * 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: + + + 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! \ No newline at end of file From 43d2fb9bc2a9bc996bd65e99d8271cfd127d3c9f Mon Sep 17 00:00:00 2001 From: Jashele T Date: Thu, 30 May 2019 17:46:34 -0700 Subject: [PATCH 2/7] refactored character stats --- assignments/prototype-refactor.js | 50 +++++++++++++++---------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/assignments/prototype-refactor.js b/assignments/prototype-refactor.js index fba91d26d..35c9803c2 100644 --- a/assignments/prototype-refactor.js +++ b/assignments/prototype-refactor.js @@ -36,7 +36,7 @@ Prototype Refactor // }; - // Object Refactored: + // GameObject Object Refactored: class GameObject { constructor(GameObj){ @@ -56,36 +56,36 @@ Prototype Refactor } - - - - // === CharacterStats === +// function CharacterStats(charAttrs) { +// GameObject.call(this, charAttrs); +// this.healthPoints = charAttrs.healthPoints; +// }; + + + // CharacterStats Refactored: + + class CharacterStats extends GameObject { + constructor(charAttrs){ + super(GameObj); + this.healthPoints = charAttrs.healthPoints; + } - function CharacterStats(charAttrs) { - GameObject.call(this, charAttrs); - this.healthPoints = charAttrs.healthPoints; - }; - - CharacterStats.prototype = Object.create(GameObject.prototype); +// CharacterStats.prototype = Object.create(GameObject.prototype); - CharacterStats.prototype.takeDamage = function () { +// CharacterStats.prototype.takeDamage = function () { +// return `${this.name} took damage`; +// } + + + +// CharacterStats Prototype Refactored: + + takeDamage(){ return `${this.name} took damage`; } - - // function CharacterStats(CharStats) { - // CharacterStats.prototype = Object.create(GameObject.prototype); - // this.healthPoints = CharStats.healthPoints; - - - - // // should inherit destroy() from GameObject's prototype - // }; - - // CharacterStats.prototype.takeDamage = function() { - // return `${this.name} took damage.`; // prototype method -> returns the string ' took damage.' - // } +} From f4cd074c39dc65151d030a0fd0d2e59f19c1d318 Mon Sep 17 00:00:00 2001 From: Jashele T Date: Thu, 30 May 2019 17:53:41 -0700 Subject: [PATCH 3/7] humanoid refactors: object & prototype --- assignments/prototype-refactor.js | 56 ++++++++++++++++++------------- 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/assignments/prototype-refactor.js b/assignments/prototype-refactor.js index 35c9803c2..278912678 100644 --- a/assignments/prototype-refactor.js +++ b/assignments/prototype-refactor.js @@ -94,36 +94,46 @@ Prototype Refactor // === Humanoid (Having an appearance or character resembling that of a human.) === - function Humanoid(HumanoidAttr) { - CharacterStats.call(this, HumanoidAttr); - this.team = HumanoidAttr.team; + // function Humanoid(HumanoidAttr) { + // CharacterStats.call(this, HumanoidAttr); + // this.team = HumanoidAttr.team; - this.weapons = HumanoidAttr.weapons; + // this.weapons = HumanoidAttr.weapons; - this.language = HumanoidAttr.language; + // this.language = HumanoidAttr.language; - }; - - - - Humanoid.prototype = Object.create(CharacterStats.prototype); - // should inherit takeDamage() from CharacterStats - - - - Humanoid.prototype.greet = function() { - return `${this.name} offers a greeting in ${this.language}.` - // prototype method -> returns the string ' offers a greeting in .' + // }; + + + + // Humanoid Refactored: + + class Humanoid extends GameObj { + constructor(HumanoidAttr) { + super(GameObj); + this.team = HumanoidAttr.team; + this.weapons = HumanoidAttr.weapons; + this.language = HumanoidAttr.language; + } + // Humanoid.prototype = Object.create(CharacterStats.prototype); + // // should inherit takeDamage() from CharacterStats + + + // Humanoid.prototype.greet = function() { + // return `${this.name} offers a greeting in ${this.language}.` + // // prototype method -> returns the string ' offers a greeting in .' + // } + + // Humanoid Prototype Refactor: + + greet(){ + return `${this.name} offers a greeting in ${this.language}.` } +} - - - - - - + /* * Inheritance chain: GameObject -> CharacterStats -> Humanoid From 8ee12e1889ee2197bc517a06b1440a360bf57e11 Mon Sep 17 00:00:00 2001 From: Jashele T Date: Thu, 30 May 2019 18:31:49 -0700 Subject: [PATCH 4/7] refactored prototype-refactor .js --- assignments/lambda-classes.js | 6 +++ assignments/prototype-refactor.js | 87 ++++++++++++++----------------- 2 files changed, 45 insertions(+), 48 deletions(-) diff --git a/assignments/lambda-classes.js b/assignments/lambda-classes.js index 71acfca0e..26a5bb4a2 100644 --- a/assignments/lambda-classes.js +++ b/assignments/lambda-classes.js @@ -1 +1,7 @@ // CODE here for your Lambda Classes + +class Person { + constructor(attributes) { + + } +} diff --git a/assignments/prototype-refactor.js b/assignments/prototype-refactor.js index 278912678..b329039d8 100644 --- a/assignments/prototype-refactor.js +++ b/assignments/prototype-refactor.js @@ -29,6 +29,7 @@ Prototype Refactor // === GameObject === + // function GameObject(GameObj) { // this.createdAt = GameObj.createdAt; // this.name = GameObj.name; @@ -45,32 +46,41 @@ Prototype Refactor this.dimensions = GameObj.dimensions; } + + // GameObject.prototype.destroy = function() { // return `${this.name} was removed from the game.`; // prototype method that returns: `${this.name} was removed from the game.` // } + + // Prototype Refactored: destroy() { return `${this.name} was removed from the game.`; } } + + // === CharacterStats === + // function CharacterStats(charAttrs) { -// GameObject.call(this, charAttrs); -// this.healthPoints = charAttrs.healthPoints; +// GameObject.call(this, charAttrs); +// this.healthPoints = charAttrs.healthPoints; // }; + // CharacterStats Refactored: class CharacterStats extends GameObject { constructor(charAttrs){ - super(GameObj); + super(charAttrs); this.healthPoints = charAttrs.healthPoints; } + // CharacterStats.prototype = Object.create(GameObject.prototype); @@ -91,26 +101,22 @@ Prototype Refactor - // === Humanoid (Having an appearance or character resembling that of a human.) === // function Humanoid(HumanoidAttr) { - // CharacterStats.call(this, HumanoidAttr); - // this.team = HumanoidAttr.team; - - // this.weapons = HumanoidAttr.weapons; - - // this.language = HumanoidAttr.language; - + // CharacterStats.call(this, HumanoidAttr); + // this.team = HumanoidAttr.team; + // this.weapons = HumanoidAttr.weapons; + // this.language = HumanoidAttr.language; // }; // Humanoid Refactored: - class Humanoid extends GameObj { + class Humanoid extends CharacterStats { constructor(HumanoidAttr) { - super(GameObj); + super(HumanoidAttr); this.team = HumanoidAttr.team; this.weapons = HumanoidAttr.weapons; this.language = HumanoidAttr.language; @@ -118,7 +124,7 @@ Prototype Refactor // Humanoid.prototype = Object.create(CharacterStats.prototype); - // // should inherit takeDamage() from CharacterStats + // should inherit takeDamage() from CharacterStats // Humanoid.prototype.greet = function() { @@ -143,56 +149,41 @@ Prototype Refactor // Test you work by un-commenting these 3 objects and the list of console logs below: - + + 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', - }); + 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, - }, + dimensions: {length: 2, width: 2, height: 2, }, healthPoints: 15, name: 'Sir Mustachio', team: 'The Round Table', - weapons: [ - 'Giant Sword', - 'Shield', - ], + weapons: ['Giant Sword', 'Shield',], language: 'Common Tongue', - }); + }) + const archer = new Humanoid({ createdAt: new Date(), - dimensions: { - length: 1, - width: 2, - height: 4, - }, + dimensions: {length: 1, width: 2, height: 4, }, healthPoints: 10, name: 'Lilith', team: 'Forest Kingdom', - weapons: [ - 'Bow', - 'Dagger', - ], + weapons: ['Bow', 'Dagger', ], language: 'Elvish', }); + console.log(mage.createdAt); // Today's date console.log(archer.dimensions); // { length: 1, width: 2, height: 4 } From 525a9b0260773dbd70c7f57c335782995a54b9b6 Mon Sep 17 00:00:00 2001 From: Jashele T Date: Thu, 30 May 2019 18:55:27 -0700 Subject: [PATCH 5/7] added person class, instructor class --- assignments/lambda-classes.js | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/assignments/lambda-classes.js b/assignments/lambda-classes.js index 26a5bb4a2..4c9116bb5 100644 --- a/assignments/lambda-classes.js +++ b/assignments/lambda-classes.js @@ -2,6 +2,31 @@ class Person { constructor(attributes) { - + name = attributes.name; + age = attributes.age; + location = attributes.location; + } + + speak() { + return `Hello, my name is ${this.name}, I am from ${this.location}.` + } +} + +class Instructor extends Person { + constructor(attributes) { + super(attributes); + this.specialty = attributes.specialty; + this.favLanguage = attributes.favLanguage; + this.catchPhrase = attributes.catchPhrase; + } + + demo() { + const subject = 'JavaScript'; + return `Today we are learning about ${this.subject}.` + } + + grade() { + const studentname = 'Jashele Tillman'; + return `${this.studentname} receives a perfect score on ${this.subject}.` } } From d8b93c142ef3653e7a59ddc3a39e705b01a603ed Mon Sep 17 00:00:00 2001 From: Jashele T Date: Thu, 30 May 2019 19:23:17 -0700 Subject: [PATCH 6/7] added student child and student methods --- assignments/lambda-classes.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/assignments/lambda-classes.js b/assignments/lambda-classes.js index 4c9116bb5..e9e944c97 100644 --- a/assignments/lambda-classes.js +++ b/assignments/lambda-classes.js @@ -30,3 +30,26 @@ class Instructor extends Person { return `${this.studentname} receives a perfect score on ${this.subject}.` } } + + +class Student extends Person { + constructor(attributes) { + super(attributes); + this.previousbackground = attributes.previousbackground; + this.className = attributes.className; + this.favSubjects = attributes.favSubjects; + } + + listsSubjects() { + return `${this.favSubjects}` + } + + PRAssignments() { + return `${this.studentname} has submitted a PR for ${this.subject}.` + } + + sprintChallenge() { + return `${this.studentname} has begun sprint challenge on ${this.subject}.` + } + +} From 12c22071161706de8dabd65c25dd45c67cd612c5 Mon Sep 17 00:00:00 2001 From: Jashele T Date: Thu, 30 May 2019 20:04:45 -0700 Subject: [PATCH 7/7] added a new student --- assignments/lambda-classes.js | 35 +++++++++++++++++++++++++++---- assignments/prototype-refactor.js | 6 +++--- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/assignments/lambda-classes.js b/assignments/lambda-classes.js index e9e944c97..7fec96684 100644 --- a/assignments/lambda-classes.js +++ b/assignments/lambda-classes.js @@ -2,9 +2,9 @@ class Person { constructor(attributes) { - name = attributes.name; - age = attributes.age; - location = attributes.location; + this.name = attributes.name; + this.age = attributes.age; + this.location = attributes.location; } speak() { @@ -41,7 +41,7 @@ class Student extends Person { } listsSubjects() { - return `${this.favSubjects}` + return `${this.favSubjects}`; } PRAssignments() { @@ -53,3 +53,30 @@ class Student extends Person { } } + +class ProjectManager extends Person { + constructor(attributes) { + super(attributes); + this.gradClassName = attributes.gradClassName; + this.favInstructor = attributes.favInstructor; + } + + standUp(channel) { + return `${this.name} announces to ${channel}, @channel standby times!`; + } + debugsCode() { + return `${this.name} debugs ${this.studentname} code on ${this.subject}.`; + } +} + +const Jashele = new Student ({ + name: 'Jashele', + age: 100, + location: 'Earth', + previousbackground: 'Panda', + className: 'Web PT 7', + favSubjects: ['User Interface'] +}) + +console.log(Jashele); + diff --git a/assignments/prototype-refactor.js b/assignments/prototype-refactor.js index b329039d8..9d37c69d6 100644 --- a/assignments/prototype-refactor.js +++ b/assignments/prototype-refactor.js @@ -159,7 +159,7 @@ Prototype Refactor team: 'Mage Guild', weapons: ['Staff of Shamalama',], language: 'Common Tongue', - }) + }); @@ -171,7 +171,7 @@ Prototype Refactor team: 'The Round Table', weapons: ['Giant Sword', 'Shield',], language: 'Common Tongue', - }) + }); const archer = new Humanoid({ @@ -183,7 +183,7 @@ Prototype Refactor weapons: ['Bow', 'Dagger', ], language: 'Elvish', }); - + console.log(mage.createdAt); // Today's date console.log(archer.dimensions); // { length: 1, width: 2, height: 4 }