Skip to content
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

mvp #767

Closed
Closed

mvp #767

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 102 additions & 5 deletions assignments/prototypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,37 @@

Each constructor function has unique properties and methods that are defined in their block comments below:
*/

function GameObject(attributes){
this.createdAt = attributes.createdAt;
this.name = attributes.name;
this.dimensions = attributes.dimensions;

}
GameObject.prototype.destroy = function(){
return `${this.name} was removed from the game.`;
}


function CharacterStats(attributes){
this.healthPoints = attributes.healthPoints;
GameObject.call(this, attributes);
}
CharacterStats.prototype = Object.create(GameObject.prototype)
CharacterStats.prototype.takeDamage = function (){
return `${this.name} took damage.`;
}


function Humanoid(attributes){
this.team = attributes.team;
this.weapons = attributes.weapons;
this.language = attributes.language;
CharacterStats.call(this, attributes);
}
Humanoid.prototype = Object.create(CharacterStats.prototype);
Humanoid.prototype.greet = function(){
return `${this.name} offers a greeting in ${this.language}`;
}
/*
=== GameObject ===
* createdAt
Expand Down Expand Up @@ -41,7 +71,7 @@

// Test you work by un-commenting these 3 objects and the list of console logs below:

/*

const mage = new Humanoid({
createdAt: new Date(),
dimensions: {
Expand Down Expand Up @@ -97,14 +127,81 @@
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(mage.weapons[0]); // 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!
// * Create two new objects, one a villain and one a hero and fight it out with methods!




function Hero(attributes){
Humanoid.call(this, attributes);
}
Hero.prototype.removeHP = function(){
this.healthPoints--;
console.log(`${this.name} took 1 dmg, new HP is ${this.healthPoints}`);
if (this.healthPoints === 0){
return console.log(`you've been removed from the game`);
}
}

function Villain(attributes){
Humanoid.call(this, attributes);
}

Villain.prototype.removeHP = function(){
this.healthPoints--;
console.log(`${this.name} took 1 dmg, new HP is ${this.healthPoints}`);
if (this.healthPoints === 0){
return console.log(`you've been removed from the game`);
}
}

const superMan = new Hero({
createdAt: new Date(),
dimensions: {
length: 2,
width: 1,
height: 1,
},
healthPoints: 3,
name: 'Bruce',
team: 'Mage Guild',
weapons: [
'Staff of Shamalama',
],
language: 'Common Tongue',
});

const Venom = new Villain ({
createdAt: new Date(),
dimensions: {
length: 2,
width: 1,
height: 1,
},
healthPoints: 3,
name: 'alexis',
team: 'Mage Guild',
weapons: [
'Staff of Shamalama',
],
language: 'Common Tongue',
});
superMan.removeHP();
superMan.removeHP();
superMan.removeHP();

Venom.removeHP();
Venom.removeHP();
Venom.removeHP();


59 changes: 54 additions & 5 deletions assignments/this.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
/* The for principles of "this";
* in your own words. explain the four principle for the "this" keyword below.
*
* 1.
* 2.
* 3.
* 4.
* 1. WINDOW/GLOBAL OBJECT BINDING: when using "this" in global scope you will return the ENTIRITY of global objects.

* 2. IMPLICIT BINDING: "this" points to the object before the dot notation.

* 3. NEW BINDING: Basically using a constructor function to return an object, you have to use the "new" keyword to create a new object.

* 4. EXPLICIT BINDING: whenever this is defined, you can override the constructor by using keywords - bind, call, apply.
*
* write out a code example of each explanation above
*/
Expand All @@ -13,14 +16,60 @@

// code example for Window Binding



function global(name){
console.log(this)
return name;
}

// global("josh");



// Principle 2

// code example for Implicit Binding



object = {
greeting: "hello",
sayHello: function(name){
console.log(`${this.greeting} my name is ${name}`)
console.log(this)
}
}
object.sayHello("josh!!!!")

// Principle 3

// code example for New Binding




function Object(greeter) {

this.greeting = "hello";
this.greeter = greeter;
this.sayHello = function(name){
console.log(`${this.greeting} my name is ${this.greeter}`);
console.log(this);
}
}
const joshh = new Object("josh")
const tata = new Object ("tataaaaaaa")
joshh.sayHello();
tata.sayHello();


// Principle 4

// code example for Explicit Binding


// code example for Explicit Binding



joshh.sayHello.call(tata);