Skip to content
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

Open
wants to merge 5 commits into
base: Novoselov_Nikolaj_Vitalevich
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions rpgsaga/saga/src/SagaRPG/Classes/Archer/Archer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Player } from '../../Player/player';
import { Status } from "../../Player/Ability";
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;
}
ability(){
return ['ability', 7, 3, Status.Ignite]
}
attack() {
return ['damage',this._power];
}

public toString(): string {
return "(Archer) " + this._name;
}
}
34 changes: 34 additions & 0 deletions rpgsaga/saga/src/SagaRPG/Classes/Mage/Mage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Player } from '../../Player/player';
import { Status } from "../../Player/Ability";
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;
}

ability(){
return ['ability', 0, 2, Status.Freeze]
}

attack() {
return ['damage',this._power];
}

public toString(): string {
return "(Mage) " + this._name;
}
}
35 changes: 35 additions & 0 deletions rpgsaga/saga/src/SagaRPG/Classes/Warrior/Warrior.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Player } from '../../Player/player';
import { Status } from "../../Player/Ability";
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;
}
ability(){
return ['ability', 4, 6, Status.Bleed]
}

attack() {
return ['damage',this._power];
}

public toString(): string {
return "(Warrior) " + this._name;
}

}

29 changes: 29 additions & 0 deletions rpgsaga/saga/src/SagaRPG/Logger/logger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
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){
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`)
}
}
6 changes: 6 additions & 0 deletions rpgsaga/saga/src/SagaRPG/Player/Ability.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export enum Status{
Ignite = 'Ignite',
Freeze = 'Freeze',
Bleed = 'Bleed',
None = 'None'
}
19 changes: 19 additions & 0 deletions rpgsaga/saga/src/SagaRPG/Player/Grid-generator/Grid-generator.ts
Original file line number Diff line number Diff line change
@@ -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> = [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
}
Original file line number Diff line number Diff line change
@@ -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;
}
46 changes: 46 additions & 0 deletions rpgsaga/saga/src/SagaRPG/Player/player.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { stat } from "fs";
import { Status } from "../Player/Ability";
export class Player {
_hp: number;
_power: number;
_healthpool: number;
_name: string;
_status: [Status, number, number?] = [Status.None, 0, 0];
//_hitchance: number;
constructor(name: string) {
this._name = name;
}

ability(){
return ['ability', 6, 3, Status.Ignite]
}
attack() {
return ['damage',this._power];
}
DeathOrAlive(): boolean {
if (this._hp <= 0) {
return true;
} else {
return false;
}
}
getDamage(damage: number): boolean {
this._hp = this._hp - damage;
return this.DeathOrAlive();
}
restore():void {
this._hp = this._healthpool;
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
}
}
67 changes: 67 additions & 0 deletions rpgsaga/saga/src/SagaRPG/battle/battle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
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);
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++) {
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 {
let chance = Random(0, 10);
if (chance <= 1) {
return player.ability();
} else {
return player.attack();
}
}
}
3 changes: 3 additions & 0 deletions rpgsaga/saga/src/SagaRPG/random/randomNum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function Random(min: number, max: number): number{
return Math.round(Math.random() * (max - min) + min);
}
42 changes: 42 additions & 0 deletions rpgsaga/saga/src/classTask/mouse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
export enum Mode {
ALIVE = "Alive",
DIED = "Died"
}
export class Mouse {
_healthpool: number = 100;
private _age: number;
_color: string;
_mode: Mode = Mode.ALIVE;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

и извне могу ее убить - поле то публичное

constructor(year: number, color: string) {
this.year = year;
this._color = color;
};
set year(year: number) {
this._age = year > 0 && year < 4 ? year : 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

при неправильном значении бросайте exception

}
get year(): number {
return this._age
}
hit(): string {
this._healthpool -= 10
if (this._healthpool > 0) {
return `Вы ударили мышь, теперь у неё ${this._healthpool} здоровья`
} else {
this._mode = Mode.DIED
return "Мышь сдохла"
}
}
heal(): string {
this._healthpool = 100
return `Теперь здоровье мыши в норме и составляет 100 единиц`
}
paint(color): string {
if (this._color == color) {
return `Зачем вы красите ${this._color} в ${color}`
} else {
this._color = color
return `Теперь мышь имеет ${color} цвет`
}
}

}
19 changes: 3 additions & 16 deletions rpgsaga/saga/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
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 { Grid_generator } from "./SagaRPG/Player/Grid-generator/Grid-generator";
import { battle } from "./SagaRPG/battle/battle";
console.log(battle.Start(2))
Loading