Skip to content

Commit

Permalink
second
Browse files Browse the repository at this point in the history
  • Loading branch information
GitSwaggCat committed Nov 9, 2023
1 parent ecf8775 commit 1d9f893
Show file tree
Hide file tree
Showing 10 changed files with 176 additions and 135 deletions.
34 changes: 17 additions & 17 deletions rpgsaga/saga/src/mouse.ts → rpgsaga/saga/src/classTask/mouse.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
export enum Mode{
export enum Mode {
ALIVE = "Alive",
DIED = "Died"
}
export class Mouse {
_heathpool: number = 100;
_healthpool: number = 100;
private _age: number;
_color: string;
_mode: Mode = Mode.ALIVE;
_color: string;
_mode: Mode = Mode.ALIVE;
constructor(year: number, color: string) {
this.year = year;
this._color = color;
};
set year(year:number ){
this._age = year > 0 && year < 4 ? year:0
set year(year: number) {
this._age = year > 0 && year < 4 ? year : 0
}
get year():number {
get year(): number {
return this._age
}
hit(): string{
this._heathpool-=10
if (this._heathpool > 0) {
return `Вы ударили мышь, теперь у неё ${this._heathpool} здоровья`
}else{
hit(): string {
this._healthpool -= 10
if (this._healthpool > 0) {
return `Вы ударили мышь, теперь у неё ${this._healthpool} здоровья`
} else {
this._mode = Mode.DIED
return "Мышь сдохла"
}
}
heal():string{
this._heathpool = 100
heal(): string {
this._healthpool = 100
return `Теперь здоровье мыши в норме и составляет 100 единиц`
}
paint(color): string{
paint(color): string {
if (this._color == color) {
return `Зачем вы красите ${this._color} в ${color}`
}else{
return `Зачем вы красите ${this._color} в ${color}`
} else {
this._color = color
return `Теперь мышь имеет ${color} цвет`
}
Expand Down
14 changes: 10 additions & 4 deletions rpgsaga/saga/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { FILE } from "dns";
import { Mouse } from "./mouse";
const first = new Mouse(2,"Белый")
console.log(first.year)
import { Animal } from "./polymorphism/animal";
import { Mode } from "./polymorphism/animal";
import { Fox } from "./polymorphism/fox";
import { chinchilla } from "./polymorphism/chinchilla";
let animalArray:object[] = []
const Karina = new Fox(200, "Белая");
const Evgenia = new chinchilla(19, "Чёрная")
animalArray.push(Karina,Evgenia)
console.log(Karina.sound())
console.log(Evgenia.sound())
28 changes: 0 additions & 28 deletions rpgsaga/saga/src/phone.ts

This file was deleted.

5 changes: 0 additions & 5 deletions rpgsaga/saga/src/polymorphism.ts

This file was deleted.

16 changes: 16 additions & 0 deletions rpgsaga/saga/src/polymorphism/animal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export enum Mode {
ALIVE = "Alive",
DIED = "Died"
};
export class Animal {
_mode: Mode = Mode.ALIVE;
_color: string;
_healthpool: number = 100;
constructor(color: string) {
this._color = color;
};
sound(): string {
return "Мы не можем понять, кто это"
}
};

23 changes: 23 additions & 0 deletions rpgsaga/saga/src/polymorphism/chinchilla.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Animal } from "./animal";
import { Mode } from "./animal";
export class chinchilla extends Animal {
private _age: number;
constructor(year: number, color: string) {
super(color);
this.year = year;
};
set year(year: number) {
this._age = year > 0 && year < 20 ? year : 0;
};

get year(): number {
return this._age;
}

sound(): string {
return `Фыр-фыр`;
};
toString(): string {
return "Это Шиншила";
};
};
34 changes: 34 additions & 0 deletions rpgsaga/saga/src/polymorphism/fox.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Animal } from "./animal";
import { Mode } from "./animal";
export class Fox extends Animal {
private _age: number;
constructor(year: number, color: string) {
super(color);
this.year = year;
};
set year(year: number) {
this._age = year > 0 && year < 25 ? year : 0;
};

get year(): number {
return this._age;
};

sound(): string {
return `Миу`;
};

toString(): string {
return "Это Лиса";
};

hit(): string {
this._healthpool -= 10;
if (this._healthpool > 0) {
return `Вы ударили лису, теперь у неё ${this._healthpool} здоровья`
} else {
this._healthpool = 100;
return "У лисы осталось 0 здоровья, однако боги исцелили её";
};
};
};
70 changes: 35 additions & 35 deletions rpgsaga/saga/tests/mouse.spec.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
import { Mouse } from '../src/mouse';
import { Mode } from "../src/mouse";
import { Mouse } from '../src/classTask/mouse';
import { Mode } from "../src/classTask/mouse";

describe('Testing Mouse constructor', () =>{
it('Mouse should be created with incorrect age', () =>{
const mouse = new Mouse(6, "Красный");
expect(mouse.year).toEqual(0);
expect(mouse._heathpool).toEqual(100);
expect(mouse._color).toEqual("Красный");
expect(mouse._mode).toEqual(Mode.ALIVE);
});
it("Mouse should be created", () =>{
const mouse = new Mouse(2,"Чёрный");
expect(mouse.year).toEqual(2);
expect(mouse._heathpool).toEqual(100);
expect(mouse._color).toEqual("Чёрный");
expect(mouse._mode).toEqual(Mode.ALIVE);
});
xdescribe('Testing Mouse constructor', () => {
it('Mouse should be created with incorrect age', () => {
const mouse = new Mouse(6, "Красный");
expect(mouse.year).toEqual(0);
expect(mouse._healthpool).toEqual(100);
expect(mouse._color).toEqual("Красный");
expect(mouse._mode).toEqual(Mode.ALIVE);
});
it("Mouse should be created", () => {
const mouse = new Mouse(2, "Чёрный");
expect(mouse.year).toEqual(2);
expect(mouse._healthpool).toEqual(100);
expect(mouse._color).toEqual("Чёрный");
expect(mouse._mode).toEqual(Mode.ALIVE);
});
});

describe('Testing Mouse methods', () => {
it("Method hit", () => {
const mouse = new Mouse(2,"Чёрный");
for (let index = 1; index < 10; index++) {
mouse.hit()
expect(mouse._heathpool).toEqual(100 -index*10)
};
});
it("Method heal",()=>{
const mouse = new Mouse(2,"Чёрный");
mouse.heal();
expect(mouse._heathpool).toEqual(100)
xdescribe('Testing Mouse methods', () => {
it("Method hit", () => {
const mouse = new Mouse(2, "Чёрный");
for (let index = 1; index < 10; index++) {
mouse.hit()
expect(mouse._healthpool).toEqual(100 - index * 10)
};
});
it("Method heal", () => {
const mouse = new Mouse(2, "Чёрный");
mouse.heal();
expect(mouse._healthpool).toEqual(100)
});
it("Method color with same color and not", () => {
const mouse = new Mouse(2, "Чёрный");
expect(mouse.paint("Красный")).toEqual("Теперь мышь имеет Красный цвет");
expect(mouse.paint("Красный")).toEqual("Зачем вы красите Красный в Красный");
})
});
it("Method color with same color and not", ()=>{
const mouse = new Mouse(2,"Чёрный");
expect(mouse.paint("Красный")).toEqual("Теперь мышь имеет Красный цвет");
expect(mouse.paint("Красный")).toEqual("Зачем вы красите Красный в Красный");
})
});

46 changes: 0 additions & 46 deletions rpgsaga/saga/tests/phone.spec.ts

This file was deleted.

41 changes: 41 additions & 0 deletions rpgsaga/saga/tests/polymorphism.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

import { Animal } from "../src/polymorphism/animal";
import { Mode } from "../src/polymorphism/animal";
import { Fox } from "../src/polymorphism/fox";
import { chinchilla } from "../src/polymorphism/chinchilla";
import { generateKeyPair } from "crypto";

describe('Testing Animals constructor', () => {
it('Animals should be created with incorrect age', () => {
const Evgenia = new chinchilla(200, "Белая");
const Karina = new Fox(200, "Чёрная");
expect(Evgenia.year).toEqual(0)
expect(Karina.year).toEqual(0)
expect(Evgenia._color).toEqual("Белая")
expect(Karina._color).toEqual("Чёрная")
});

it("Animals should be created", () => {
const Evgenia = new chinchilla(19, "Белая");
const Karina = new Fox(19, "Чёрная");
expect(Evgenia.year).toEqual(19)
expect(Karina.year).toEqual(19)
});
});

describe('Testing Animals methods', () => {
it("Method toString", () => {
const Evgenia = new chinchilla(19, "Белая");
const Karina = new Fox(19, "Чёрная");
expect(`${Evgenia}`).toEqual("Это Шиншила");
expect(`${Karina}`).toEqual("Это Лиса");
});
it("Method sound", () => {
const Evgenia = new chinchilla(19, "Белая");
const Karina = new Fox(19, "Чёрная");
expect(Karina.sound()).toEqual("Миу");
expect(Evgenia.sound()).toEqual("Фыр-фыр");
});
it("Method color with same color and not", () => {
})
});

0 comments on commit 1d9f893

Please sign in to comment.