|
// -------------------------- |
|
// Base |
|
class PokeDex { |
|
constructor(name, hp, atk, gen, type){ |
|
this.name = name; |
|
this.hp = hp; |
|
this.atk = atk; |
|
this.gen = gen; |
|
this.type = type; |
|
this.rare = false; |
|
} |
|
printInfo(){ |
|
console.log('hello ' + this.name, this.hp, this.atk, this.gen + ' generation', this.type, ' rare?' + this.rare); |
|
} |
|
} |
|
|
|
// ----------------------------- |
|
// Child 1 |
|
class EvolvedPokemon extends PokeDex { |
|
constructor(name, hp, atk, gen, type){ |
|
super(name, hp, atk, gen, type); |
|
this.evolvedDate = new Date(); |
|
} |
|
happyBirthday(){ |
|
console.log('My birthday of evolution is ', this.evolvedDate); |
|
} |
|
} |
|
|
|
// ----------------------------- |
|
// Child 2 |
|
class LegendaryPokemon extends PokeDex { |
|
constructor(name, hp, atk, gen, type, capturedLocation){ |
|
super(name, hp, atk, gen, type); |
|
this.rare = true; |
|
this.capturedDate = new Date(); |
|
this.capturedLocation = capturedLocation; |
|
} |
|
} |
|
|
|
////---------------------------- |
|
// Misc Class - hold various information about the location |
|
class Location { |
|
constructor(lat, lng, city, state, country){ |
|
this.lat = lat; |
|
this.lng = lng; |
|
this.city = city; |
|
this.state = state; |
|
this.country = country; |
|
} |
|
printInfo(){ |
|
console.log('('+this.lat+','+this.lng+') - ' + this.city + ',' + this.state + ' ' + this.country); |
|
} |
|
} |
|
|
|
// Test ----------------------------------------- |
|
var pikachu = new PokeDex('Pikachu', 80, 20, 1, 'Electric'); |
|
pikachu.printInfo(); |
|
var squirtle = new PokeDex('Squirtle', 100, 15, 1, 'Water'); |
|
squirtle.printInfo(); |
|
var raichu = new EvolvedPokemon('Raichu', 120, 98, 1, 'Electric'); |
|
raichu.printInfo(); |
|
var newYorkGreenvale = new Location(40,-73,'Greenvale','NY','USA'); |
|
newYorkGreenvale.printInfo(); |
|
var articuno = new LegendaryPokemon('Articuno', 110, 90, 2, 'Ice', newYorkGreenvale); |
|
articuno.printInfo(); |
|
var entei = new LegendaryPokemon('Entei', 120, 100, 2, 'Fire', newYorkGreenvale); |
|
entei.printInfo(); |