-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclasses.ts
58 lines (49 loc) · 1.4 KB
/
classes.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
abstract class abistrata { //classe abistrata so pode ser estendida
nome: string;
constructor(nome: string) {
this.nome = nome;
}
}
class UserAccout {
public name: string;
protected age: number;
constructor(name: string, age: number){
this.name = name;
this.age = age;
}
logDetails(): void{
console.log(`the player ${this.name} is ${this.age} years old.`);
}
}
class CharAccount extends UserAccout {
private nickname: string;
readonly lavel: number;
level: number;
constructor(name: string, age: number, nickname: string, level: number, lavel: number){
super(name, age);
this.nickname = nickname;
this.level = level;
this.lavel = lavel
}
get getLevel(){
console.log("-----Get-----");
return this.level
}
set setLevel(level: number){
this.level = level;
}
logCharDetails(): void{
console.log(`thhe player ${this.name} is ${this.age} and has the char ${this.nickname} at level ${this.level}`);
}
}
const pessoa = new UserAccout("sarah", 30);
console.log(pessoa);
pessoa.logDetails();
const pessoa2 = new CharAccount("john", 45, "johmaster", 80, 9);
console.log(pessoa2.level);
pessoa2.logDetails();
// pessoa2.nickname = "jo"
pessoa2.logCharDetails();
pessoa2.setLevel = 499;
console.log(pessoa2.getLevel);
// const test = new abistrata("caio");