-
Notifications
You must be signed in to change notification settings - Fork 34
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
Create PR #25
base: Novoselov_Nikolaj_Vitalevich
Are you sure you want to change the base?
Create PR #25
Conversation
rpgsaga/saga/src/mouse.ts
Outdated
DIED = "Died" | ||
} | ||
export class Mouse { | ||
_heathpool: number = 100; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
проверим настройки линтера
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
а _heathpool не должен быть приватным или protected
rpgsaga/saga/src/mouse.ts
Outdated
@@ -0,0 +1,42 @@ | |||
export enum Mode{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
enum можно вынести в отдельный файл
rpgsaga/saga/src/mouse.ts
Outdated
this._heathpool-=10 | ||
if (this._heathpool > 0) { | ||
return `Вы ударили мышь, теперь у неё ${this._heathpool} здоровья` | ||
}else{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
не используйте else
rpgsaga/saga/src/mouse.ts
Outdated
return `Вы ударили мышь, теперь у неё ${this._heathpool} здоровья` | ||
}else{ | ||
this._mode = Mode.DIED | ||
return "Мышь сдохла" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
линтер точно не заработал - нужна ; в конце строки
_healthpool: number = 100; | ||
private _age: number; | ||
_color: string; | ||
_mode: Mode = Mode.ALIVE; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
и извне могу ее убить - поле то публичное
this._color = color; | ||
}; | ||
set year(year: number) { | ||
this._age = year > 0 && year < 4 ? year : 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
при неправильном значении бросайте exception
constructor(color: string) { | ||
this._color = color; | ||
}; | ||
sound(): string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
тогда сделайте его абстрактным
export class Animal { | ||
_mode: Mode = Mode.ALIVE; | ||
_color: string; | ||
_healthpool: number = 100; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
и вот это поле публичное
} | ||
|
||
sound(): string { | ||
return `Фыр-фыр`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
set year(year: number) { | ||
this._age = year > 0 && year < 20 ? year : 0; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
а вот тут интересно - у вас у всех есть возраст - но нет в базовом классе -> я могу создать животьное у которого не будет этого года - что может привести к неожиданному поведению
this.year = year; | ||
}; | ||
set year(year: number) { | ||
this._age = year > 0 && year < 25 ? year : 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
при неправильном годе - бросайте exception
кроме того вы можете определить базовое поведение и хранить сколько лет живет то или иное животное - и исходя из этого сделать этот метод вообще в базовом классе
No description provided.