From ecf8775dd0707172bfbcea4055601506702abd93 Mon Sep 17 00:00:00 2001 From: GitSwaggCat Date: Wed, 8 Nov 2023 08:35:52 +0300 Subject: [PATCH 1/5] commit --- rpgsaga/saga/src/index.ts | 20 +++----------- rpgsaga/saga/src/mouse.ts | 42 ++++++++++++++++++++++++++++++ rpgsaga/saga/src/polymorphism.ts | 5 ++++ rpgsaga/saga/tests/example.spec.ts | 7 ----- rpgsaga/saga/tests/mouse.spec.ts | 40 ++++++++++++++++++++++++++++ rpgsaga/saga/tests/phone.spec.ts | 4 +-- 6 files changed, 93 insertions(+), 25 deletions(-) create mode 100644 rpgsaga/saga/src/mouse.ts create mode 100644 rpgsaga/saga/src/polymorphism.ts delete mode 100644 rpgsaga/saga/tests/example.spec.ts create mode 100644 rpgsaga/saga/tests/mouse.spec.ts diff --git a/rpgsaga/saga/src/index.ts b/rpgsaga/saga/src/index.ts index 7805559..0418d60 100644 --- a/rpgsaga/saga/src/index.ts +++ b/rpgsaga/saga/src/index.ts @@ -1,16 +1,4 @@ -import { Phone } from './phone'; - -const first = new Phone('+7900-000 000 (123)', 1990, 'Телефон 1'); -first.year = 1998; - -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); +import { FILE } from "dns"; +import { Mouse } from "./mouse"; +const first = new Mouse(2,"Белый") +console.log(first.year) \ No newline at end of file diff --git a/rpgsaga/saga/src/mouse.ts b/rpgsaga/saga/src/mouse.ts new file mode 100644 index 0000000..c28b65c --- /dev/null +++ b/rpgsaga/saga/src/mouse.ts @@ -0,0 +1,42 @@ +export enum Mode{ + ALIVE = "Alive", + DIED = "Died" +} +export class Mouse { + _heathpool: number = 100; + private _age: number; + _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 + } + get year():number { + return this._age + } + hit(): string{ + this._heathpool-=10 + if (this._heathpool > 0) { + return `Вы ударили мышь, теперь у неё ${this._heathpool} здоровья` + }else{ + this._mode = Mode.DIED + return "Мышь сдохла" + } + } + heal():string{ + this._heathpool = 100 + return `Теперь здоровье мыши в норме и составляет 100 единиц` + } + paint(color): string{ + if (this._color == color) { + return `Зачем вы красите ${this._color} в ${color}` + }else{ + this._color = color + return `Теперь мышь имеет ${color} цвет` + } + } + +} diff --git a/rpgsaga/saga/src/polymorphism.ts b/rpgsaga/saga/src/polymorphism.ts new file mode 100644 index 0000000..0bfa3b4 --- /dev/null +++ b/rpgsaga/saga/src/polymorphism.ts @@ -0,0 +1,5 @@ +class Animal{ + _hp: number; + _age:number; + +} \ No newline at end of file diff --git a/rpgsaga/saga/tests/example.spec.ts b/rpgsaga/saga/tests/example.spec.ts deleted file mode 100644 index 8c44f23..0000000 --- a/rpgsaga/saga/tests/example.spec.ts +++ /dev/null @@ -1,7 +0,0 @@ -describe('Example', () => { - it('should return 5 as result of 2 and 3 sum', () => { - const a = 3; - const b = 2; - expect(a + b).toEqual(5); - }); -}); diff --git a/rpgsaga/saga/tests/mouse.spec.ts b/rpgsaga/saga/tests/mouse.spec.ts new file mode 100644 index 0000000..8ee3c3e --- /dev/null +++ b/rpgsaga/saga/tests/mouse.spec.ts @@ -0,0 +1,40 @@ +import { Mouse } from '../src/mouse'; +import { Mode } from "../src/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); +}); +}); + +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) +}); +it("Method color with same color and not", ()=>{ + const mouse = new Mouse(2,"Чёрный"); + expect(mouse.paint("Красный")).toEqual("Теперь мышь имеет Красный цвет"); + expect(mouse.paint("Красный")).toEqual("Зачем вы красите Красный в Красный"); +}) + }); + diff --git a/rpgsaga/saga/tests/phone.spec.ts b/rpgsaga/saga/tests/phone.spec.ts index 64c38b0..c193d39 100644 --- a/rpgsaga/saga/tests/phone.spec.ts +++ b/rpgsaga/saga/tests/phone.spec.ts @@ -1,6 +1,6 @@ import { Phone } from '../src/phone'; -describe('Testing phone constructor', () => { +xdescribe('Testing phone constructor', () => { it('Phone should be created', () => { const first = new Phone('+7900-000 000 (123)', 1990, 'Телефон 1'); expect(first.phoneNumber).toEqual('+7900-000 000 (123)'); @@ -27,7 +27,7 @@ describe('Testing phone constructor', () => { }); }); -describe('Testing phone methods', () => { +xdescribe('Testing phone methods', () => { it('Phone year set valid value', () => { const first = new Phone('+7900-000 000 (123)', 2000, 'Телефон 1'); first.year = 1991; From 1d9f89395b654c12a4b9216b3a92a085658cc65e Mon Sep 17 00:00:00 2001 From: GitSwaggCat Date: Thu, 9 Nov 2023 11:07:53 +0300 Subject: [PATCH 2/5] second --- rpgsaga/saga/src/{ => classTask}/mouse.ts | 34 +++++----- rpgsaga/saga/src/index.ts | 14 +++-- rpgsaga/saga/src/phone.ts | 28 --------- rpgsaga/saga/src/polymorphism.ts | 5 -- rpgsaga/saga/src/polymorphism/animal.ts | 16 +++++ rpgsaga/saga/src/polymorphism/chinchilla.ts | 23 +++++++ rpgsaga/saga/src/polymorphism/fox.ts | 34 ++++++++++ rpgsaga/saga/tests/mouse.spec.ts | 70 ++++++++++----------- rpgsaga/saga/tests/phone.spec.ts | 46 -------------- rpgsaga/saga/tests/polymorphism.spec.ts | 41 ++++++++++++ 10 files changed, 176 insertions(+), 135 deletions(-) rename rpgsaga/saga/src/{ => classTask}/mouse.ts (56%) delete mode 100644 rpgsaga/saga/src/phone.ts delete mode 100644 rpgsaga/saga/src/polymorphism.ts create mode 100644 rpgsaga/saga/src/polymorphism/animal.ts create mode 100644 rpgsaga/saga/src/polymorphism/chinchilla.ts create mode 100644 rpgsaga/saga/src/polymorphism/fox.ts delete mode 100644 rpgsaga/saga/tests/phone.spec.ts create mode 100644 rpgsaga/saga/tests/polymorphism.spec.ts diff --git a/rpgsaga/saga/src/mouse.ts b/rpgsaga/saga/src/classTask/mouse.ts similarity index 56% rename from rpgsaga/saga/src/mouse.ts rename to rpgsaga/saga/src/classTask/mouse.ts index c28b65c..05d8d82 100644 --- a/rpgsaga/saga/src/mouse.ts +++ b/rpgsaga/saga/src/classTask/mouse.ts @@ -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} цвет` } diff --git a/rpgsaga/saga/src/index.ts b/rpgsaga/saga/src/index.ts index 0418d60..6822669 100644 --- a/rpgsaga/saga/src/index.ts +++ b/rpgsaga/saga/src/index.ts @@ -1,4 +1,10 @@ -import { FILE } from "dns"; -import { Mouse } from "./mouse"; -const first = new Mouse(2,"Белый") -console.log(first.year) \ No newline at end of file +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()) \ No newline at end of file diff --git a/rpgsaga/saga/src/phone.ts b/rpgsaga/saga/src/phone.ts deleted file mode 100644 index d310d29..0000000 --- a/rpgsaga/saga/src/phone.ts +++ /dev/null @@ -1,28 +0,0 @@ -export class Phone { - private aYear: number; - phoneNumber: string; - - static phoneCount = 0; - - constructor(number: string, year: number, public name?: string) { - Phone.phoneCount += 1; - this.phoneNumber = number; - this.year = year; - this.name = name; - } - - call(number: string) { - console.log(`Making a call from ${this.phoneNumber} to ${number}`); - } - endCall() { - console.log('Ending call'); - } - - set year(year: number) { - this.aYear = year >= 1900 && year < 2023 ? year : this.aYear ?? 1900; - } - - get year(): number { - return this.aYear; - } -} \ No newline at end of file diff --git a/rpgsaga/saga/src/polymorphism.ts b/rpgsaga/saga/src/polymorphism.ts deleted file mode 100644 index 0bfa3b4..0000000 --- a/rpgsaga/saga/src/polymorphism.ts +++ /dev/null @@ -1,5 +0,0 @@ -class Animal{ - _hp: number; - _age:number; - -} \ No newline at end of file diff --git a/rpgsaga/saga/src/polymorphism/animal.ts b/rpgsaga/saga/src/polymorphism/animal.ts new file mode 100644 index 0000000..3c6ae85 --- /dev/null +++ b/rpgsaga/saga/src/polymorphism/animal.ts @@ -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 "Мы не можем понять, кто это" + } +}; + diff --git a/rpgsaga/saga/src/polymorphism/chinchilla.ts b/rpgsaga/saga/src/polymorphism/chinchilla.ts new file mode 100644 index 0000000..f1fe43d --- /dev/null +++ b/rpgsaga/saga/src/polymorphism/chinchilla.ts @@ -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 "Это Шиншила"; + }; +}; \ No newline at end of file diff --git a/rpgsaga/saga/src/polymorphism/fox.ts b/rpgsaga/saga/src/polymorphism/fox.ts new file mode 100644 index 0000000..a570eb3 --- /dev/null +++ b/rpgsaga/saga/src/polymorphism/fox.ts @@ -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 здоровья, однако боги исцелили её"; + }; + }; +}; \ No newline at end of file diff --git a/rpgsaga/saga/tests/mouse.spec.ts b/rpgsaga/saga/tests/mouse.spec.ts index 8ee3c3e..ba43b5c 100644 --- a/rpgsaga/saga/tests/mouse.spec.ts +++ b/rpgsaga/saga/tests/mouse.spec.ts @@ -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("Зачем вы красите Красный в Красный"); -}) - }); diff --git a/rpgsaga/saga/tests/phone.spec.ts b/rpgsaga/saga/tests/phone.spec.ts deleted file mode 100644 index c193d39..0000000 --- a/rpgsaga/saga/tests/phone.spec.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { Phone } from '../src/phone'; - -xdescribe('Testing phone constructor', () => { - it('Phone should be created', () => { - const first = new Phone('+7900-000 000 (123)', 1990, 'Телефон 1'); - expect(first.phoneNumber).toEqual('+7900-000 000 (123)'); - expect(first.year).toEqual(1990); - expect(first.name).toEqual('Телефон 1'); - }); - it('Phone with empty name', () => { - const first = new Phone('+7900-000 000 (123)', 1990); - expect(first.phoneNumber).toEqual('+7900-000 000 (123)'); - expect(first.year).toEqual(1990); - expect(first.name).toBeUndefined(); - }); - it('Phone year lower than bound', () => { - const first = new Phone('+7900-000 000 (123)', 1899); - expect(first.phoneNumber).toEqual('+7900-000 000 (123)'); - expect(first.year).toEqual(1900); - expect(first.name).toBeUndefined(); - }); - it('Phone year higher than bound', () => { - const first = new Phone('+7900-000 000 (123)', 2023); - expect(first.phoneNumber).toEqual('+7900-000 000 (123)'); - expect(first.year).toEqual(1900); - expect(first.name).toBeUndefined(); - }); -}); - -xdescribe('Testing phone methods', () => { - it('Phone year set valid value', () => { - const first = new Phone('+7900-000 000 (123)', 2000, 'Телефон 1'); - first.year = 1991; - expect(first.year).toEqual(1991); - }); - it('Phone year lower than valid value', () => { - const first = new Phone('+7900-000 000 (123)', 2000, 'Телефон 1'); - first.year = 1899; - expect(first.year).toEqual(2000); - }); - it('Phone year higher than valid value', () => { - const first = new Phone('+7900-000 000 (123)', 2000, 'Телефон 1'); - first.year = 2989; - expect(first.year).toEqual(2000); - }); -}); diff --git a/rpgsaga/saga/tests/polymorphism.spec.ts b/rpgsaga/saga/tests/polymorphism.spec.ts new file mode 100644 index 0000000..30975f7 --- /dev/null +++ b/rpgsaga/saga/tests/polymorphism.spec.ts @@ -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", () => { + }) +}); \ No newline at end of file From 7d1bd078a2e980a10e719fedc885e5ea6178e9dc Mon Sep 17 00:00:00 2001 From: GitSwaggCat Date: Tue, 28 Nov 2023 11:02:39 +0300 Subject: [PATCH 3/5] third --- rpgsaga/saga/RPG-Saga/Class/Archer/archer.ts | 5 +++++ rpgsaga/saga/RPG-Saga/Player/player.ts | 10 ++++++++++ rpgsaga/saga/src/index.ts | 9 +++++---- rpgsaga/saga/src/polymorphism/animal.ts | 2 +- rpgsaga/saga/tests/polymorphism.spec.ts | 3 --- 5 files changed, 21 insertions(+), 8 deletions(-) create mode 100644 rpgsaga/saga/RPG-Saga/Class/Archer/archer.ts create mode 100644 rpgsaga/saga/RPG-Saga/Player/player.ts diff --git a/rpgsaga/saga/RPG-Saga/Class/Archer/archer.ts b/rpgsaga/saga/RPG-Saga/Class/Archer/archer.ts new file mode 100644 index 0000000..212854b --- /dev/null +++ b/rpgsaga/saga/RPG-Saga/Class/Archer/archer.ts @@ -0,0 +1,5 @@ +import { Player } from "../../Player/player"; + +export class Archer extends Player{ + suppress_chance:number = 20; +} \ No newline at end of file diff --git a/rpgsaga/saga/RPG-Saga/Player/player.ts b/rpgsaga/saga/RPG-Saga/Player/player.ts new file mode 100644 index 0000000..4def72b --- /dev/null +++ b/rpgsaga/saga/RPG-Saga/Player/player.ts @@ -0,0 +1,10 @@ +export class Player{ + _name:string; + _attack:number; + _healthpool:number; + constructor(Playername:string, Playerattack:number,Playerhealthpool:number){ + this._name = Playername; + this._attack = Playerattack; + this._healthpool = Playerhealthpool; + } +} \ No newline at end of file diff --git a/rpgsaga/saga/src/index.ts b/rpgsaga/saga/src/index.ts index 6822669..ede7245 100644 --- a/rpgsaga/saga/src/index.ts +++ b/rpgsaga/saga/src/index.ts @@ -2,9 +2,10 @@ import { Animal } from "./polymorphism/animal"; import { Mode } from "./polymorphism/animal"; import { Fox } from "./polymorphism/fox"; import { chinchilla } from "./polymorphism/chinchilla"; -let animalArray:object[] = [] +let animalArray:Animal[] = [] const Karina = new Fox(200, "Белая"); const Evgenia = new chinchilla(19, "Чёрная") -animalArray.push(Karina,Evgenia) -console.log(Karina.sound()) -console.log(Evgenia.sound()) \ No newline at end of file +animalArray.push(Karina,Evgenia); +for (const item of animalArray) { + console.log(item.sound()); +} diff --git a/rpgsaga/saga/src/polymorphism/animal.ts b/rpgsaga/saga/src/polymorphism/animal.ts index 3c6ae85..60a08cb 100644 --- a/rpgsaga/saga/src/polymorphism/animal.ts +++ b/rpgsaga/saga/src/polymorphism/animal.ts @@ -2,7 +2,7 @@ export enum Mode { ALIVE = "Alive", DIED = "Died" }; -export class Animal { +export abstract class Animal { _mode: Mode = Mode.ALIVE; _color: string; _healthpool: number = 100; diff --git a/rpgsaga/saga/tests/polymorphism.spec.ts b/rpgsaga/saga/tests/polymorphism.spec.ts index 30975f7..cbbd36c 100644 --- a/rpgsaga/saga/tests/polymorphism.spec.ts +++ b/rpgsaga/saga/tests/polymorphism.spec.ts @@ -3,7 +3,6 @@ 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', () => { @@ -36,6 +35,4 @@ describe('Testing Animals methods', () => { expect(Karina.sound()).toEqual("Миу"); expect(Evgenia.sound()).toEqual("Фыр-фыр"); }); - it("Method color with same color and not", () => { - }) }); \ No newline at end of file From 51920df6993c0d650ae8185d0e0da620aa8cb256 Mon Sep 17 00:00:00 2001 From: GitSwaggCat Date: Tue, 9 Jan 2024 19:37:38 +0300 Subject: [PATCH 4/5] saga --- rpgsaga/saga/RPG-Saga/Class/Archer/archer.ts | 5 --- rpgsaga/saga/RPG-Saga/Player/player.ts | 10 ----- .../saga/src/SagaRPG/Classes/Archer/Archer.ts | 30 +++++++++++++ rpgsaga/saga/src/SagaRPG/Classes/Mage/Mage.ts | 30 +++++++++++++ .../src/SagaRPG/Classes/Warrior/Warrior.ts | 32 +++++++++++++ rpgsaga/saga/src/SagaRPG/Logger/logger.ts | 22 +++++++++ .../Player/Grid-generator/Grid-generator.ts | 19 ++++++++ .../Player_generator/Player_generator.ts | 28 ++++++++++++ rpgsaga/saga/src/SagaRPG/Player/player.ts | 32 +++++++++++++ rpgsaga/saga/src/SagaRPG/battle/battle.ts | 45 +++++++++++++++++++ rpgsaga/saga/src/SagaRPG/random/randomNum.ts | 3 ++ rpgsaga/saga/src/index.ts | 14 ++---- rpgsaga/saga/tsconfig.json | 3 +- 13 files changed, 246 insertions(+), 27 deletions(-) delete mode 100644 rpgsaga/saga/RPG-Saga/Class/Archer/archer.ts delete mode 100644 rpgsaga/saga/RPG-Saga/Player/player.ts create mode 100644 rpgsaga/saga/src/SagaRPG/Classes/Archer/Archer.ts create mode 100644 rpgsaga/saga/src/SagaRPG/Classes/Mage/Mage.ts create mode 100644 rpgsaga/saga/src/SagaRPG/Classes/Warrior/Warrior.ts create mode 100644 rpgsaga/saga/src/SagaRPG/Logger/logger.ts create mode 100644 rpgsaga/saga/src/SagaRPG/Player/Grid-generator/Grid-generator.ts create mode 100644 rpgsaga/saga/src/SagaRPG/Player/Player_generator/Player_generator.ts create mode 100644 rpgsaga/saga/src/SagaRPG/Player/player.ts create mode 100644 rpgsaga/saga/src/SagaRPG/battle/battle.ts create mode 100644 rpgsaga/saga/src/SagaRPG/random/randomNum.ts diff --git a/rpgsaga/saga/RPG-Saga/Class/Archer/archer.ts b/rpgsaga/saga/RPG-Saga/Class/Archer/archer.ts deleted file mode 100644 index 212854b..0000000 --- a/rpgsaga/saga/RPG-Saga/Class/Archer/archer.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { Player } from "../../Player/player"; - -export class Archer extends Player{ - suppress_chance:number = 20; -} \ No newline at end of file diff --git a/rpgsaga/saga/RPG-Saga/Player/player.ts b/rpgsaga/saga/RPG-Saga/Player/player.ts deleted file mode 100644 index 4def72b..0000000 --- a/rpgsaga/saga/RPG-Saga/Player/player.ts +++ /dev/null @@ -1,10 +0,0 @@ -export class Player{ - _name:string; - _attack:number; - _healthpool:number; - constructor(Playername:string, Playerattack:number,Playerhealthpool:number){ - this._name = Playername; - this._attack = Playerattack; - this._healthpool = Playerhealthpool; - } -} \ No newline at end of file diff --git a/rpgsaga/saga/src/SagaRPG/Classes/Archer/Archer.ts b/rpgsaga/saga/src/SagaRPG/Classes/Archer/Archer.ts new file mode 100644 index 0000000..e94ecc9 --- /dev/null +++ b/rpgsaga/saga/src/SagaRPG/Classes/Archer/Archer.ts @@ -0,0 +1,30 @@ +import { Player } from '../../Player/player'; + +export enum Archer_Shape { + Hunter = 'Hunter', + Raider = 'Raider', + Elemental_Mage = 'Elemental_Mage', +} + +export class Archer extends Player { + _healthpool: number; + _hp: number; + _power: number = 10; + //_hitchance: number = 85; + //_suppress: number = 25; + Shape: Archer_Shape; + constructor(Shape: Archer_Shape, name: string, hp: number) { + super(name); + this.Shape = Shape; + this._hp = hp; + this._healthpool = hp; + } + + attack() { + return this._power; + } + + public toString(): string { + return "(Archer) " + this._name; + } +} diff --git a/rpgsaga/saga/src/SagaRPG/Classes/Mage/Mage.ts b/rpgsaga/saga/src/SagaRPG/Classes/Mage/Mage.ts new file mode 100644 index 0000000..0fc6a9e --- /dev/null +++ b/rpgsaga/saga/src/SagaRPG/Classes/Mage/Mage.ts @@ -0,0 +1,30 @@ +import { Player } from '../../Player/player'; + +export enum Mage_Shape { + Inquisitor = 'Inquisitor', + Forbidden = 'Forbidden', + Occultist = 'Occultist', +} + +export class Mage extends Player { + _healthpool: number; + _hp: number; + _power: number = 12; + //_hitchance:number = 90; + //_evade:number = 10; + Shape: Mage_Shape; + constructor(Shape: Mage_Shape, name: string, hp: number) { + super(name); + this.Shape = Shape; + this._hp = hp; + this._healthpool = hp; + } + + attack() { + return this._power; + } + + public toString(): string { + return "(Mage) " + this._name; + } +} diff --git a/rpgsaga/saga/src/SagaRPG/Classes/Warrior/Warrior.ts b/rpgsaga/saga/src/SagaRPG/Classes/Warrior/Warrior.ts new file mode 100644 index 0000000..36bd624 --- /dev/null +++ b/rpgsaga/saga/src/SagaRPG/Classes/Warrior/Warrior.ts @@ -0,0 +1,32 @@ +import { Player } from '../../Player/player'; + +export enum Warrior_Shape { + Juggernaut = 'Juggernaut', + Marauder = 'Marauder', + Slayer = 'Slayer', +} + +export class Warrior extends Player { + _healthpool: number; + _hp: number; + _power: number = 8; + //_hitchance:number = 80; + //_block:number = 10; + Shape: Warrior_Shape; + constructor(Shape: Warrior_Shape, name: string, hp: number) { + super(name); + this.Shape = Shape; + this._hp = hp; + this._healthpool = hp; + } + + attack() { + return this._power; + } + + public toString(): string { + return "(Warrior) " + this._name; + } + +} + diff --git a/rpgsaga/saga/src/SagaRPG/Logger/logger.ts b/rpgsaga/saga/src/SagaRPG/Logger/logger.ts new file mode 100644 index 0000000..d64e563 --- /dev/null +++ b/rpgsaga/saga/src/SagaRPG/Logger/logger.ts @@ -0,0 +1,22 @@ +import { Player } from "../Player/player"; + +export class Logger{ + static WriteWinner(winner: Player){ + console.log() + console.log(`${winner} win this game`) + console.log() + } + static WritebattleNumber(number){ + console.log(`Battle № ${number}`) + } + static WritebattleMembers(battleMembers: Player[]){ + console.log(`${battleMembers[0]} VS ${battleMembers[1]}`); + } + + static WriteDeath(looser: Player): void { + console.log(`${looser} dead`); + } + static WriteAction(firstplayer, secondplayer, MoveAction){ + console.log((`${firstplayer} deal ${MoveAction} damage to enemy ${secondplayer}`)); + } +} \ No newline at end of file diff --git a/rpgsaga/saga/src/SagaRPG/Player/Grid-generator/Grid-generator.ts b/rpgsaga/saga/src/SagaRPG/Player/Grid-generator/Grid-generator.ts new file mode 100644 index 0000000..68e694a --- /dev/null +++ b/rpgsaga/saga/src/SagaRPG/Player/Grid-generator/Grid-generator.ts @@ -0,0 +1,19 @@ +import { Random } from "../../random/randomNum"; +import { generator} from "../Player_generator/Player_generator"; +import { Player } from "../player"; + +//classes +export enum classes { + Archer = 'Archer', + Warrior = 'Warrior', + Mage = 'Mage', + } +const classes_array: Array = [classes.Archer, classes.Warrior, classes.Mage]; + + export function Grid_generator(player_quantity):Player[]{ + let player_grid:Player[] = [] + for (let index = 0; index < player_quantity; index++) { + player_grid.push(generator(classes_array[Random(0,2)])) + } + return player_grid +} \ No newline at end of file diff --git a/rpgsaga/saga/src/SagaRPG/Player/Player_generator/Player_generator.ts b/rpgsaga/saga/src/SagaRPG/Player/Player_generator/Player_generator.ts new file mode 100644 index 0000000..f8e21e2 --- /dev/null +++ b/rpgsaga/saga/src/SagaRPG/Player/Player_generator/Player_generator.ts @@ -0,0 +1,28 @@ +import { Random } from '../../random/randomNum'; +import { Warrior, Warrior_Shape } from '../../Classes/Warrior/Warrior'; +import { Mage, Mage_Shape } from '../../Classes/Mage/Mage'; +import { Archer, Archer_Shape } from '../../Classes/Archer/Archer'; +import { Player } from '../player'; +import { classes } from '../Grid-generator/Grid-generator'; +//Shape +const A_Shape: Archer_Shape[] = [Archer_Shape.Hunter, Archer_Shape.Raider, Archer_Shape.Elemental_Mage]; +const M_Shape: Mage_Shape[] = [Mage_Shape.Forbidden, Mage_Shape.Inquisitor, Mage_Shape.Occultist]; +const W_Shape: Warrior_Shape[] = [Warrior_Shape.Juggernaut, Warrior_Shape.Marauder, Warrior_Shape.Slayer]; +//names +const names: string[] = ['Sergey', 'Danilla', 'Nikola', 'Artem', 'Denis', 'Karina', 'Evgenia', 'Elena', 'Egor']; + +export function generator(player_class: classes) { + let player: Player; + switch (player_class) { + case classes.Archer: + player = new Archer(A_Shape[Random(0, 2)], names[Random(0, 8)], Random(90, 110)); + break; + case classes.Warrior: + player = new Warrior(W_Shape[Random(0, 2)], names[Random(0, 8)], Random(110, 130)); + break; + default: + player = new Mage(M_Shape[Random(0, 2)], names[Random(0, 8)], Random(70, 90)); + break; + } + return player; +} diff --git a/rpgsaga/saga/src/SagaRPG/Player/player.ts b/rpgsaga/saga/src/SagaRPG/Player/player.ts new file mode 100644 index 0000000..a554acd --- /dev/null +++ b/rpgsaga/saga/src/SagaRPG/Player/player.ts @@ -0,0 +1,32 @@ +export class Player { + _hp: number; + _power: number; + _healthpool: number; + _name: string; + _abilityuses: number = 3; + _abilityused: number = 0; + //_hitchance: number; + constructor(name: string) { + this._name = name; + } + + ability() {} + attack() { + return this._power; + } + DeathOrAlive(): boolean { + if (this._hp <= 0) { + return true; + } else { + return false; + } + } + getDamage(damage: number) { + this._hp = this._hp - damage; + return this.DeathOrAlive(); + } + restore() { + this._hp = this._healthpool; + this._abilityused = 0; + } +} diff --git a/rpgsaga/saga/src/SagaRPG/battle/battle.ts b/rpgsaga/saga/src/SagaRPG/battle/battle.ts new file mode 100644 index 0000000..ce18666 --- /dev/null +++ b/rpgsaga/saga/src/SagaRPG/battle/battle.ts @@ -0,0 +1,45 @@ +import { Player } from '../Player/player'; +import { Grid_generator } from '../Player/Grid-generator/Grid-generator'; +import { Logger } from '../Logger/logger'; +import { Random } from '../random/randomNum'; +export class battle { + static Start(player_quantity): void { + let grid: Player[] = Grid_generator(player_quantity); + battle.Play(grid); + } + static Play(grid: Player[]): void { + let length = grid.length; + for (let index = 1; index < length; index++) { + Logger.WritebattleNumber(index); + battle.Playround(grid, length); + } + Logger.WriteWinner(grid[0]) + } + static Playround(grid: Player[], length): void { + let RoundMembers = [grid[0], grid[1]]; + Logger.WritebattleMembers(RoundMembers); + let winner = battle.Playbattle(RoundMembers); + grid.push(winner) + grid.splice(0,2) + } + static Playbattle(RoundMembers): Player { + for (let index = 0; true; index++) { + let PlayerMode = RoundMembers[index % 2].DeathOrAlive(); + if (PlayerMode) { + return RoundMembers[(index % 2) + 1]; + } + let MoveAction = battle.PlayerAction(RoundMembers[index % 2]); + PlayerMode = RoundMembers[(index + 1) % 2].getDamage(MoveAction); + Logger.WriteAction(RoundMembers[index % 2], RoundMembers[(index + 1) % 2], MoveAction); + if (PlayerMode) { + Logger.WriteDeath(RoundMembers[(index + 1) % 2]); + RoundMembers[index % 2].restore(); + return RoundMembers[index % 2]; + } + } + } + + static PlayerAction(player): void { + return player.attack(); + } +} diff --git a/rpgsaga/saga/src/SagaRPG/random/randomNum.ts b/rpgsaga/saga/src/SagaRPG/random/randomNum.ts new file mode 100644 index 0000000..d36436e --- /dev/null +++ b/rpgsaga/saga/src/SagaRPG/random/randomNum.ts @@ -0,0 +1,3 @@ +export function Random(min, max){ + return Math.round(Math.random() * (max - min) + min); + } \ No newline at end of file diff --git a/rpgsaga/saga/src/index.ts b/rpgsaga/saga/src/index.ts index ede7245..4747045 100644 --- a/rpgsaga/saga/src/index.ts +++ b/rpgsaga/saga/src/index.ts @@ -1,11 +1,3 @@ -import { Animal } from "./polymorphism/animal"; -import { Mode } from "./polymorphism/animal"; -import { Fox } from "./polymorphism/fox"; -import { chinchilla } from "./polymorphism/chinchilla"; -let animalArray:Animal[] = [] -const Karina = new Fox(200, "Белая"); -const Evgenia = new chinchilla(19, "Чёрная") -animalArray.push(Karina,Evgenia); -for (const item of animalArray) { - console.log(item.sound()); -} +import { Grid_generator } from "./SagaRPG/Player/Grid-generator/Grid-generator"; +import { battle } from "./SagaRPG/battle/battle"; +console.log(battle.Start(2)) \ No newline at end of file diff --git a/rpgsaga/saga/tsconfig.json b/rpgsaga/saga/tsconfig.json index 03a0e5a..46ca4e2 100644 --- a/rpgsaga/saga/tsconfig.json +++ b/rpgsaga/saga/tsconfig.json @@ -1,5 +1,6 @@ { "compilerOptions": { - "types": ["jest", "node"] + "types": ["jest", "node"], + "target":"ES6" } } \ No newline at end of file From 5a95cff3775f2b172fbcd823a8916c1a47903afe Mon Sep 17 00:00:00 2001 From: GitSwaggCat Date: Tue, 9 Jan 2024 23:53:04 +0300 Subject: [PATCH 5/5] saga with ability --- .../saga/src/SagaRPG/Classes/Archer/Archer.ts | 8 ++- rpgsaga/saga/src/SagaRPG/Classes/Mage/Mage.ts | 8 ++- .../src/SagaRPG/Classes/Warrior/Warrior.ts | 7 ++- rpgsaga/saga/src/SagaRPG/Logger/logger.ts | 9 ++- rpgsaga/saga/src/SagaRPG/Player/Ability.ts | 6 ++ rpgsaga/saga/src/SagaRPG/Player/player.ts | 28 +++++++--- rpgsaga/saga/src/SagaRPG/battle/battle.ts | 56 +++++++++++++------ rpgsaga/saga/src/SagaRPG/random/randomNum.ts | 2 +- 8 files changed, 91 insertions(+), 33 deletions(-) create mode 100644 rpgsaga/saga/src/SagaRPG/Player/Ability.ts diff --git a/rpgsaga/saga/src/SagaRPG/Classes/Archer/Archer.ts b/rpgsaga/saga/src/SagaRPG/Classes/Archer/Archer.ts index e94ecc9..23b94a8 100644 --- a/rpgsaga/saga/src/SagaRPG/Classes/Archer/Archer.ts +++ b/rpgsaga/saga/src/SagaRPG/Classes/Archer/Archer.ts @@ -1,5 +1,5 @@ import { Player } from '../../Player/player'; - +import { Status } from "../../Player/Ability"; export enum Archer_Shape { Hunter = 'Hunter', Raider = 'Raider', @@ -19,9 +19,11 @@ export class Archer extends Player { this._hp = hp; this._healthpool = hp; } - + ability(){ + return ['ability', 7, 3, Status.Ignite] + } attack() { - return this._power; + return ['damage',this._power]; } public toString(): string { diff --git a/rpgsaga/saga/src/SagaRPG/Classes/Mage/Mage.ts b/rpgsaga/saga/src/SagaRPG/Classes/Mage/Mage.ts index 0fc6a9e..4416a86 100644 --- a/rpgsaga/saga/src/SagaRPG/Classes/Mage/Mage.ts +++ b/rpgsaga/saga/src/SagaRPG/Classes/Mage/Mage.ts @@ -1,5 +1,5 @@ import { Player } from '../../Player/player'; - +import { Status } from "../../Player/Ability"; export enum Mage_Shape { Inquisitor = 'Inquisitor', Forbidden = 'Forbidden', @@ -20,8 +20,12 @@ export class Mage extends Player { this._healthpool = hp; } + ability(){ + return ['ability', 0, 2, Status.Freeze] + } + attack() { - return this._power; + return ['damage',this._power]; } public toString(): string { diff --git a/rpgsaga/saga/src/SagaRPG/Classes/Warrior/Warrior.ts b/rpgsaga/saga/src/SagaRPG/Classes/Warrior/Warrior.ts index 36bd624..67df29e 100644 --- a/rpgsaga/saga/src/SagaRPG/Classes/Warrior/Warrior.ts +++ b/rpgsaga/saga/src/SagaRPG/Classes/Warrior/Warrior.ts @@ -1,5 +1,5 @@ import { Player } from '../../Player/player'; - +import { Status } from "../../Player/Ability"; export enum Warrior_Shape { Juggernaut = 'Juggernaut', Marauder = 'Marauder', @@ -19,9 +19,12 @@ export class Warrior extends Player { this._hp = hp; this._healthpool = hp; } + ability(){ + return ['ability', 4, 6, Status.Bleed] + } attack() { - return this._power; + return ['damage',this._power]; } public toString(): string { diff --git a/rpgsaga/saga/src/SagaRPG/Logger/logger.ts b/rpgsaga/saga/src/SagaRPG/Logger/logger.ts index d64e563..312a1de 100644 --- a/rpgsaga/saga/src/SagaRPG/Logger/logger.ts +++ b/rpgsaga/saga/src/SagaRPG/Logger/logger.ts @@ -17,6 +17,13 @@ export class Logger{ console.log(`${looser} dead`); } static WriteAction(firstplayer, secondplayer, MoveAction){ - console.log((`${firstplayer} deal ${MoveAction} damage to enemy ${secondplayer}`)); + if (MoveAction[0] == 'damage') { + console.log((`${firstplayer} deal ${MoveAction[1]} damage to enemy ${secondplayer}`)); + }else{ + console.log((`${firstplayer} imposed ${MoveAction[3]} on ${secondplayer}`)); + } + } + static WriteDagameFromAbility(player){ + console.log(`${player} get ${player.CheckStatus()[2]} damage from enemy's ability`) } } \ No newline at end of file diff --git a/rpgsaga/saga/src/SagaRPG/Player/Ability.ts b/rpgsaga/saga/src/SagaRPG/Player/Ability.ts new file mode 100644 index 0000000..e8a8326 --- /dev/null +++ b/rpgsaga/saga/src/SagaRPG/Player/Ability.ts @@ -0,0 +1,6 @@ +export enum Status{ + Ignite = 'Ignite', + Freeze = 'Freeze', + Bleed = 'Bleed', + None = 'None' +} \ No newline at end of file diff --git a/rpgsaga/saga/src/SagaRPG/Player/player.ts b/rpgsaga/saga/src/SagaRPG/Player/player.ts index a554acd..02f7b7d 100644 --- a/rpgsaga/saga/src/SagaRPG/Player/player.ts +++ b/rpgsaga/saga/src/SagaRPG/Player/player.ts @@ -1,18 +1,21 @@ +import { stat } from "fs"; +import { Status } from "../Player/Ability"; export class Player { _hp: number; _power: number; _healthpool: number; _name: string; - _abilityuses: number = 3; - _abilityused: number = 0; + _status: [Status, number, number?] = [Status.None, 0, 0]; //_hitchance: number; constructor(name: string) { this._name = name; } - ability() {} + ability(){ + return ['ability', 6, 3, Status.Ignite] + } attack() { - return this._power; + return ['damage',this._power]; } DeathOrAlive(): boolean { if (this._hp <= 0) { @@ -21,12 +24,23 @@ export class Player { return false; } } - getDamage(damage: number) { + getDamage(damage: number): boolean { this._hp = this._hp - damage; return this.DeathOrAlive(); } - restore() { + restore():void { this._hp = this._healthpool; - this._abilityused = 0; + this._status = [Status.None, 0, 0] + } + + CheckStatus(){ + return this._status + } + getStatus(status){ + this._status = status + } + TakeDamageFromAbility(){ + this._healthpool -= this.CheckStatus[1] + this.CheckStatus[1] - 1 } } diff --git a/rpgsaga/saga/src/SagaRPG/battle/battle.ts b/rpgsaga/saga/src/SagaRPG/battle/battle.ts index ce18666..bd70192 100644 --- a/rpgsaga/saga/src/SagaRPG/battle/battle.ts +++ b/rpgsaga/saga/src/SagaRPG/battle/battle.ts @@ -2,6 +2,8 @@ import { Player } from '../Player/player'; import { Grid_generator } from '../Player/Grid-generator/Grid-generator'; import { Logger } from '../Logger/logger'; import { Random } from '../random/randomNum'; +import { Status } from '../Player/Ability'; +import { stat } from 'fs'; export class battle { static Start(player_quantity): void { let grid: Player[] = Grid_generator(player_quantity); @@ -10,36 +12,56 @@ export class battle { static Play(grid: Player[]): void { let length = grid.length; for (let index = 1; index < length; index++) { - Logger.WritebattleNumber(index); - battle.Playround(grid, length); + Logger.WritebattleNumber(index); + battle.Playround(grid, length); } - Logger.WriteWinner(grid[0]) + Logger.WriteWinner(grid[0]); } static Playround(grid: Player[], length): void { let RoundMembers = [grid[0], grid[1]]; Logger.WritebattleMembers(RoundMembers); let winner = battle.Playbattle(RoundMembers); - grid.push(winner) - grid.splice(0,2) + grid.push(winner); + grid.splice(0, 2); } static Playbattle(RoundMembers): Player { for (let index = 0; true; index++) { - let PlayerMode = RoundMembers[index % 2].DeathOrAlive(); - if (PlayerMode) { - return RoundMembers[(index % 2) + 1]; - } - let MoveAction = battle.PlayerAction(RoundMembers[index % 2]); - PlayerMode = RoundMembers[(index + 1) % 2].getDamage(MoveAction); - Logger.WriteAction(RoundMembers[index % 2], RoundMembers[(index + 1) % 2], MoveAction); - if (PlayerMode) { - Logger.WriteDeath(RoundMembers[(index + 1) % 2]); - RoundMembers[index % 2].restore(); - return RoundMembers[index % 2]; + if (RoundMembers[index % 2].CheckStatus()[0] == Status.Freeze && RoundMembers[index % 2].CheckStatus()[1] != 0) { + console.log(`${RoundMembers[index % 2]} skip move`); + RoundMembers[index % 2].CheckStatus()[1] -= 1; + }else { + if (RoundMembers[index % 2].CheckStatus()[0] == Status.Ignite || RoundMembers[index % 2].CheckStatus()[0] == Status.Bleed && RoundMembers[index % 2].CheckStatus()[1] < 0) { + + RoundMembers[index%2].TakeDamageFromAbility() + Logger.WriteDagameFromAbility(RoundMembers[index%2]) + } + let PlayerMode = RoundMembers[index % 2].DeathOrAlive(); + if (PlayerMode) { + return RoundMembers[(index + 1) % 2]; + } + let MoveAction = battle.PlayerAction(RoundMembers[index % 2]); + if (MoveAction[0] == 'damage') { + PlayerMode = RoundMembers[(index + 1) % 2].getDamage(MoveAction[1]); + Logger.WriteAction(RoundMembers[index % 2], RoundMembers[(index + 1) % 2], MoveAction); + } else { + RoundMembers[(index + 1) % 2].getStatus([MoveAction[3], MoveAction[2], MoveAction[1]]); + Logger.WriteAction(RoundMembers[index % 2], RoundMembers[(index + 1) % 2], MoveAction); + } + if (PlayerMode) { + Logger.WriteDeath(RoundMembers[(index + 1) % 2]); + RoundMembers[index % 2].restore(); + return RoundMembers[index % 2]; + } } } } static PlayerAction(player): void { - return player.attack(); + let chance = Random(0, 10); + if (chance <= 1) { + return player.ability(); + } else { + return player.attack(); + } } } diff --git a/rpgsaga/saga/src/SagaRPG/random/randomNum.ts b/rpgsaga/saga/src/SagaRPG/random/randomNum.ts index d36436e..c7ffb2f 100644 --- a/rpgsaga/saga/src/SagaRPG/random/randomNum.ts +++ b/rpgsaga/saga/src/SagaRPG/random/randomNum.ts @@ -1,3 +1,3 @@ -export function Random(min, max){ +export function Random(min: number, max: number): number{ return Math.round(Math.random() * (max - min) + min); } \ No newline at end of file