CodeWars, Class assignment, Severe polymorphism and inheritance hierarchy, Calculating a person's age#21
CodeWars, Class assignment, Severe polymorphism and inheritance hierarchy, Calculating a person's age#21Victor2004 wants to merge 12 commits intoISUCT:Pyzhov_Viktorfrom
Conversation
rpgsaga Задание на классы 22 вариант. Фильм (метод - проиграть фильм)
Задание Суровый полиморфизм и иерархия наследования 22 вариант. Фильм
Задание Вычисление возраста человека
| /saga/.yarn | ||
| saga/yarn.lock |
There was a problem hiding this comment.
если yarn не используете - то просто удалите файлы
| /saga/.yarn | ||
| saga/yarn.lock | ||
| saga/.yarnrc.yml | ||
| saga/package.json |
There was a problem hiding this comment.
а вот этот файл должен быть в рапозитории
rpgsaga/saga/src/index.ts
Outdated
| @@ -1,16 +1,58 @@ | |||
| import { Phone } from './phone'; | |||
| // import { Art } from './art'; | |||
There was a problem hiding this comment.
все что не нужно - удаляйте - тут можете оставить в целом пример только вызова ваших классов
| @@ -0,0 +1,20 @@ | |||
| export abstract class Art { | |||
| title: string; | |||
| year1: number; | |||
There was a problem hiding this comment.
судя по всему год я могу сделать отрицательным - и почему он year1 ?
|
|
||
| constructor(title: string, year: number, director: string) { | ||
| this.title = title; | ||
| this.year1 = year; |
There was a problem hiding this comment.
вот тут как раз надо
| this.year1 = year; | |
| this.year = year; |
чтобы вызвался set
| } | ||
|
|
||
| set year(year: number) { | ||
| this.year1 = year; |
There was a problem hiding this comment.
добавьте проверку и бросайте exception если он не попадает в диапазон
| const now = new Date(); | ||
| const days = now.getDate() - this.dateBirth.getDate(); | ||
| const months = now.getMonth() - this.dateBirth.getMonth() + 1; | ||
| const years = now.getFullYear() - this.dateBirth.getFullYear(); | ||
| if (this.dateBirth.getDate() == now.getDate() && this.dateBirth.getMonth() == now.getMonth() && this.dateBirth.getFullYear() == now.getFullYear()) { | ||
| return "0 days, 0 months, 0 years"; | ||
| } | ||
| if (months < 0 || years < 0) { | ||
| return "Invalid date" | ||
| } | ||
| return `${days} days, ${months} months, ${years} years`; |
There was a problem hiding this comment.
не не - надо использовать timestamp и вычесть 1 дату из другой
| return `${this.title}, ${this.director}, ${this.year}`; | ||
| } | ||
|
|
||
| pages: number; |
There was a problem hiding this comment.
опчть же - если поле не приватное я могу сделать его отрицательным?
|
|
||
| constructor(title: string, year: number, director: string, pages: number) { | ||
| super(title, year, director); | ||
| this.pages = pages >= 1 ? pages : 1; |
There was a problem hiding this comment.
используйте set и вызовите его тут - если значение вас не устаривает - то бросайте exception
Основные отличия от ТЗ: - У всех классов есть атака ближнего боя; - Заклинание "Заворожение" маг может использовать только 3 раза.
Fix rpgsaga to comply with OOP, returned old files that I deleted for no reason, started writing unit tests
should simulate the first game scenarios
No description provided.