Repository navigation
Mohammad Tourjoman #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "liveServer.settings.port": 5501 | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,7 @@ | |
|
|
||
| Each constructor function has unique properties and methods that are defined in their block comments below: | ||
| */ | ||
|
|
||
| /* | ||
| === GameObject === | ||
| * createdAt | ||
|
|
@@ -32,79 +32,186 @@ | |
| * 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. | ||
| */ | ||
| * 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. | ||
| */ | ||
|
|
||
| function GameObject(attr) { | ||
| this.createdAt = attr.createdAt; | ||
| this.name = attr.name; | ||
| this.dimensions = attr.dimensions; | ||
| } | ||
|
|
||
| GameObject.prototype.destroy = function() { | ||
| return `${this.name} was removed from the game`; | ||
| }; | ||
|
|
||
| function CharacterStats(attr) { | ||
| GameObject.call(this, attr); | ||
| this.healthPoints = attr.healthPoints; | ||
| } | ||
|
|
||
| CharacterStats.prototype = Object.create(GameObject.prototype); | ||
|
|
||
| /* updated for stretch */ | ||
| CharacterStats.prototype.takeDamage = function(damage) { | ||
| this.healthPoints -= damage; | ||
| if(this.healthPoints <= 0) { | ||
| return `Critical damage! ` + this.destroy(); | ||
| } else | ||
| return `${this.name} took damage. Health remaining: ${this.healthPoints}`; | ||
| }; | ||
|
|
||
| function Humanoid(attr) { | ||
| CharacterStats.call(this, attr); | ||
| this.team = attr.team; | ||
| this.weapons = attr.weapons; | ||
| this.language = attr.language; | ||
| } | ||
|
|
||
| Humanoid.prototype = Object.create(CharacterStats.prototype); | ||
| Humanoid.prototype.greet = function() { | ||
| return `${this.name} offers a greeting in ${this.language}`; | ||
| }; | ||
|
|
||
| // 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. | ||
| 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(5)); // 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! | ||
|
|
||
| /**************** | ||
| * The takeDamage() method has been updated above for optimal implementation of this stretch | ||
| * | ||
| */ | ||
|
|
||
| // 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! | ||
| function Villain(attr) { | ||
| Humanoid.call(this, attr); | ||
| //this.super(); | ||
|
|
||
| this.spitPotionAt = function (target){ | ||
| console.log(`${this.name} spit potion at ${target.name}!`); | ||
| return target.takeDamage(5); | ||
| } | ||
| this.castSpellOn = function(target){ | ||
| console.log(`${this.name} cast a spell on ${target.name}!`); | ||
| //regenerates health when this attack is used | ||
| this.healthPoints += 1; | ||
| return target.takeDamage(3); | ||
| } | ||
| } | ||
|
|
||
| Villain.prototype = Object.create(Humanoid.prototype); | ||
|
|
||
| function Hero(attr) { | ||
| Humanoid.call(this, attr); | ||
| //this.super(); | ||
|
|
||
| this.swordStab = function (target){ | ||
| console.log(`${this.name} stabbed ${target.name} with a sword!`); | ||
| return target.takeDamage(6); | ||
| } | ||
| this.airstrike = function (target) { | ||
| console.log(`${this.name} launched an airstrike on ${target.name}!`); | ||
| this.healthPoints += 2; | ||
| return target.takeDamage(2); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. only 2 damage for an airstrike?
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the AI that fires the missiles is inaccurate 🤷♂ |
||
| } | ||
| } | ||
|
|
||
| Hero.prototype = Object.create(Humanoid.prototype); | ||
|
|
||
| const houdini = new Villain({ | ||
| createdAt: new Date(), | ||
| dimensions: { | ||
| length: 2, | ||
| width: 1, | ||
| height: 1 | ||
| }, | ||
| healthPoints: 15, | ||
| name: "Houdini", | ||
| team: "Leeches", | ||
| weapons: ["Annoying words"], | ||
| language: "Basic Tongue" | ||
| }); | ||
|
|
||
| const momoney = new Hero({ | ||
| createdAt: new Date(), | ||
| dimensions: { | ||
| length: 2, | ||
| width: 1, | ||
| height: 2 | ||
| }, | ||
| healthPoints: 18, | ||
| name: "Mo Money", | ||
| team: "Seeds", | ||
| weapons: ["JavaScript code"], | ||
| language: "Full-Stack Tongue" | ||
| }); | ||
|
|
||
| console.log(houdini.spitPotionAt(momoney)); | ||
| console.log(momoney.airstrike(houdini)); | ||
| console.log(houdini.castSpellOn(momoney)); | ||
| console.log(momoney.swordStab(houdini)); | ||
| console.log(houdini.castSpellOn(momoney)); | ||
| console.log(momoney.swordStab(houdini)); | ||
| console.log(houdini.spitPotionAt(momoney)); | ||
| console.log(momoney.airstrike(houdini)); | ||
| console.log(houdini.castSpellOn(momoney)); | ||
| console.log(momoney.airstrike(houdini)); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,26 +1,61 @@ | ||
| /* The for principles of "this"; | ||
| * in your own words. explain the four principle for the "this" keyword below. | ||
| * | ||
| * 1. | ||
| * 2. | ||
| * 3. | ||
| * 4. | ||
| * 1. Window binding means that the 'this' keyword binds to the window object (also | ||
| known as default binding) | ||
| * 2. Implicit binding means that the 'this' keyword binds implicitly (automatically) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Implicit binding refers to the dot notaton. the object on the left of the dot is implicated as THIS.
|
||
| to its variable object. | ||
| * 3. Explicit binding is when the 'this' keyword is explicitly assigned to an object | ||
| of the programmer's choice | ||
| * 4. New binding happens when a new object is created, and the 'this' keyword gets | ||
| assigned to that empty object before it is initialized. | ||
| * | ||
| * write out a code example of each explanation above | ||
| */ | ||
|
|
||
| // Principle 1 | ||
|
|
||
| // code example for Window Binding | ||
| console.log(this); | ||
|
|
||
| // Principle 2 | ||
|
|
||
| // code example for Implicit Binding | ||
| function test (){ | ||
| console.log(this.name); | ||
| } | ||
|
|
||
| const objTest = { | ||
| name: "Mo Money", | ||
| test: test | ||
| }; | ||
|
|
||
| objTest.test(); | ||
| // Principle 3 | ||
|
|
||
| // code example for New Binding | ||
| function testFunc (){ | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. by convention, Constructor functions are named with CapitalCase. this does not affect the way the code functions, but it provides a helpful visual cue to keep your code standardized and thereby easier for you to read.
|
||
| this.name = "Mo"; | ||
| this.speak = function (){ | ||
| return "My name is " + this.name; | ||
| }; | ||
| } | ||
|
|
||
| console.log(testFunc.name); | ||
| var testFuncTest = new testFunc (); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you should only be using CONST and LET to declare variables. VAR is a relic and does not have the same helpful scoping rules that CONST and LET provide. |
||
| console.log(testFuncTest.name); | ||
|
|
||
| testFunc(); | ||
|
|
||
| // Principle 4 | ||
|
|
||
| // code example for Explicit Binding | ||
| // code example for Explicit Binding | ||
| function hello (){ | ||
| console.log(this.text); | ||
| } | ||
|
|
||
| let explicitExample = { | ||
| text: "Test Text" | ||
| } | ||
|
|
||
| hello.call(explicitExample); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great job with the damage logic.