Skip to content

Commit 36ea5c1

Browse files
committed
Updates to JS-III
- Readme - new this.js assignment - new prototypes assignment - added gitignore
0 parents  commit 36ea5c1

4 files changed

Lines changed: 156 additions & 0 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.DS_Store

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# JavaScript - III
2+
This challenge focuses on using the `this` keyword as well as getting comfortable with prototypes by building out a fantasy themed video game.
3+
4+
## Assignment Description
5+
6+
* Fork/Clone this repository.
7+
* Complete all the exercises as described inside each assignment file.
8+
* Use `console.log()` statements to check to see if your code does what it is supposed to do.
9+
* To test your `console` statements you can run `node /assignments/<fileName>` and see what prints in your terminal. You can also use an online tool like `JSBin`, `REPL.it`, `JSFiddle`, or even your `Chrome developer console`.
10+
* Once you finish the exercises in each file, commit your code, and push it to your fork.
11+
12+
### The `this` keyword
13+
Having a solid understanding of how `this` works will give you a huge advantage when you start building with more advanced frameworks. Use the [this.js](assignments/this.js) file to traverse through a few `this` problems.
14+
15+
### Prototype
16+
The prototype challenge will focus on building prototypes for a fantasy themed game that includes mages, swordsmen, and archers. Follow the [prototypes.js](assignments/this.js) instructions closely to create the beginnings of what could be an awesome JavaScript game.
17+
18+
* Read the instructions found within the file carefully to finish the challenges.
19+
* Remember to uncomment the objects and console logs to test your work at the bottom of the page.

assignments/prototypes.js

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/*
2+
Object oriented design is commonly used in video games. For this part of the assignment
3+
you will be implementing several classes with their correct inheritance heirarchy.
4+
5+
In this file you will be creating three classes: GameObject, NPC, Humanoid.
6+
At the bottom of this file are 3 objects that all inherit from Humanoid. Use the objects at the bottom of the page to test your classes.
7+
8+
Each class has unique properites and methods that are defined in their block comments below:
9+
*/
10+
11+
/*
12+
=== GameObject ===
13+
* createdAt
14+
* dimensions
15+
* destroy() // prototype method -> returns the string 'Object was removed from the game.'
16+
*/
17+
18+
/*
19+
=== NPC ===
20+
* hp
21+
* name
22+
* takeDamage() // prototype method -> returns the string '<object name> took damage.'
23+
* should inherit destroy() from GameObject's prototype
24+
*/
25+
26+
/*
27+
=== Humanoid ===
28+
* faction
29+
* weapons
30+
* language
31+
* greet() // prototype method -> returns the string '<object name> offers a greeting in <object language>.'
32+
* should inherit destroy() from GameObject through NPC
33+
* should inherit takeDamage() from NPC
34+
*/
35+
36+
/*
37+
* Inheritance chain: Humanoid -> NPC -> GameObject
38+
* Instances of Humanoid should have all of the same properties as NPC and GameObject.
39+
* Instances of NPC should have all of the same properties as GameObject.
40+
*/
41+
42+
//Test you work by uncommenting these 3 objects and the list of console logs below:
43+
44+
/*
45+
const mage = new Humanoid({
46+
createdAt: new Date(),
47+
dimensions: {
48+
length: 2,
49+
width: 1,
50+
height: 1,
51+
},
52+
hp: 5,
53+
name: 'Bruce',
54+
faction: 'Mage Guild',
55+
weapons: [
56+
'Staff of Shamalama',
57+
],
58+
language: 'Common Toungue',
59+
});
60+
61+
const swordsman = new Humanoid({
62+
createdAt: new Date(),
63+
dimensions: {
64+
length: 2,
65+
width: 2,
66+
height: 2,
67+
},
68+
hp: 15,
69+
name: 'Sir Mustachio',
70+
faction: 'The Round Table',
71+
weapons: [
72+
'Giant Sword',
73+
'Shield',
74+
],
75+
language: 'Common Toungue',
76+
});
77+
78+
const archer = new Humanoid({
79+
createdAt: new Date(),
80+
dimensions: {
81+
length: 1,
82+
width: 2,
83+
height: 4,
84+
},
85+
hp: 10,
86+
name: 'Lilith',
87+
faction: 'Forest Kingdom',
88+
weapons: [
89+
'Bow',
90+
'Dagger',
91+
],
92+
language: 'Elvish',
93+
});
94+
95+
console.log(mage.createdAt); // Today's date
96+
console.log(archer.dimensions); // { length: 1, width: 2, height: 4 }
97+
console.log(swordsman.hp); // 15
98+
console.log(mage.name); // Bruce
99+
console.log(swordsman.faction); // The Round Table
100+
console.log(mage.weapons); // Staff of Shamalama
101+
console.log(archer.language); // Elvish
102+
console.log(archer.greet()); // Lilith offers a greeting in Elvish.
103+
console.log(mage.takeDamage()); // Bruce took damage.
104+
console.log(swordsman.destroy()); // Sir Mustachio was removed from the game.
105+
*/
106+
107+
// Stretch task:
108+
// * Create Villian and Hero classes that inherit from the Humanoid class.
109+
// * Give the Hero and Villians 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;
110+
// * Create two new objects, one a villian and one a hero and fight it out with methods!

assignments/this.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/* The for principles of "this";
2+
* in your own words. explain the four principle for the "this" keyword below.
3+
*
4+
* 1.
5+
* 2.
6+
* 3.
7+
* 4.
8+
*
9+
* write out a code example of each explanation above
10+
*/
11+
12+
// Principle 1
13+
14+
// code example for Window Binding
15+
16+
// Principle 2
17+
18+
// code example for Implicit Binding
19+
20+
// Principle 3
21+
22+
// code example for New Binding
23+
24+
// Principle 4
25+
26+
// code example for Explicit Binding

0 commit comments

Comments
 (0)