Created
June 14, 2024 11:17
-
-
Save Caballerog/8159dc049880d4af0d52cd4e6ddaf1ee to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Clonable } from "./clonable"; | |
export class VirtualPet implements Clonable { | |
name: string; | |
color: string; | |
abilities: string[]; | |
energyLevel: number = 0; | |
constructor(name: string, color: string, abilities: string[], energyLevel: number = 100) { | |
this.name = name; | |
this.color = color; | |
this.abilities = abilities; | |
this.calculateEnergy(3000); | |
} | |
private calculateEnergy(milliseconds: number) { | |
const start = new Date().getTime(); | |
let end = start; | |
console.log(`Initializing ${this.name}...`); | |
while (end < start + milliseconds) { | |
end = new Date().getTime(); | |
} | |
this.energyLevel = 100; | |
} | |
displayInfo() { | |
console.log(`Name: ${this.name}, Color: ${this.color}, Abilities: ${this.abilities.join(', ')}, Energy Level: ${this.energyLevel}`); | |
} | |
clone(): this { | |
console.log(`\nCloning ${this.name}...`) | |
const clone = Object.create(this); | |
clone.abilities = [...this.abilities]; // Clone the abilities array | |
return clone; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment