diff --git a/rpgsaga/saga/src/index.ts b/rpgsaga/saga/src/index.ts index 7805559..97ead3b 100644 --- a/rpgsaga/saga/src/index.ts +++ b/rpgsaga/saga/src/index.ts @@ -1,16 +1,9 @@ -import { Phone } from './phone'; +import { Rabbit } from './rabbit'; -const first = new Phone('+7900-000 000 (123)', 1990, 'Телефон 1'); -first.year = 1998; +const myRabbit = new Rabbit(5, 'black', 'Dutch dwarf'); +myRabbit.age = 10; +console.log(myRabbit.age); +myRabbit.name = 'Malebu'; +console.log(myRabbit.name); -first.year = -1998; -first.call('12345'); -first.endCall(); - -const second = new Phone('+799900000', -5); -// second.name = 'Телефон 2'; -console.log(second.year); -second.call('12345'); -second.endCall(); - -console.log(first, second, Phone.phoneCount); +console.log(myRabbit); diff --git a/rpgsaga/saga/src/rabbit.ts b/rpgsaga/saga/src/rabbit.ts new file mode 100644 index 0000000..1cb411e --- /dev/null +++ b/rpgsaga/saga/src/rabbit.ts @@ -0,0 +1,32 @@ +export class Rabbit { + private _age: number; + private breed: string; + private color: string; + private _name: string; + + constructor(rabAge: number, rabBreed: string, rabColor: string) { + this.age = rabAge; + this.breed = rabBreed; + this.color = rabColor; + } + + get age(): number { + return this._age; + } + + set age(n: number) { + if (n < 0 || n > 12) { + console.log('Недопустимый возраст!'); + } else { + this._age = n; + } + } + + get name(): string { + return this._name; + } + + public set name(str: string) { + this._name = str; + } + } \ No newline at end of file diff --git a/rpgsaga/saga/tests/rabbit.spec.ts b/rpgsaga/saga/tests/rabbit.spec.ts new file mode 100644 index 0000000..303ea04 --- /dev/null +++ b/rpgsaga/saga/tests/rabbit.spec.ts @@ -0,0 +1 @@ +import { Rabbit } from '../src/rabbit'; \ No newline at end of file