-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0ac214e
commit 75c060a
Showing
8 changed files
with
614 additions
and
533 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,169 +1,167 @@ | ||
import color from 'colorts'; | ||
|
||
import { MathHelper } from './mathHelper'; | ||
import { fireDamage, names } from './constants'; | ||
import color from 'colorts'; | ||
import { Logger } from './logger'; | ||
|
||
export class Character { | ||
className: string = ""; | ||
private _isBurn:boolean = false; | ||
get isBurn(): boolean { | ||
return this._isBurn; | ||
} | ||
|
||
protected isStunned: boolean = false; | ||
private _health: number; | ||
get health(): number { | ||
return this._health; | ||
} | ||
protected _minHealth: number = 5; | ||
protected _maxHealth: number = 10; | ||
|
||
private _strength: number; | ||
get strength(): number { | ||
return this._strength; | ||
} | ||
protected _minStrength: number = 5; | ||
protected _maxStrength: number = 10; | ||
|
||
private _characterName: string; | ||
get characterName(): string { | ||
return this._characterName; | ||
} | ||
|
||
private _dexterity: number; | ||
get dexterity(): number { | ||
return this._dexterity; | ||
} | ||
protected _minDexterity: number = 5; | ||
protected _maxDexterity: number = 10; | ||
|
||
protected _mana: number = 0; | ||
get mana(): number { | ||
return this._mana; | ||
} | ||
|
||
private _manaRegeneration: number; | ||
get manaRegeneration(): number { | ||
return this._manaRegeneration; | ||
} | ||
protected _minManaRegeneration: number = 8; | ||
protected _maxManaRegeneration: number = 10; | ||
|
||
private _classSkillCost: number = 0; | ||
get classSkillCost(): number { | ||
return this._classSkillCost; | ||
} | ||
protected _minClassSkillCost: number = 15; | ||
protected _maxClassSkillCost: number = 20; | ||
|
||
constructor() { | ||
this.Generate(); | ||
} | ||
|
||
public Stun() { | ||
this.isStunned = true; | ||
} | ||
|
||
private Generate() { | ||
this._health = MathHelper.genrateRandomNumber(this._minHealth, this._maxHealth); | ||
this._strength = MathHelper.genrateRandomNumber(this._minStrength, this._maxStrength); | ||
this._dexterity = MathHelper.genrateRandomNumber(this._minDexterity, this._maxDexterity); | ||
this._characterName = this.SelectColorName(names[MathHelper.genrateRandomNumber(0, names.length - 1)]); | ||
this._manaRegeneration = MathHelper.genrateRandomNumber(this._minManaRegeneration, this._maxManaRegeneration); | ||
this._classSkillCost = MathHelper.genrateRandomNumber(this._minClassSkillCost, this._maxClassSkillCost); | ||
} | ||
|
||
public checkInitiative() { | ||
return MathHelper.genrateRandomNumber(1, this._dexterity * 10); | ||
} | ||
|
||
public checkDexterity() { | ||
return MathHelper.genrateRandomNumber(1, this._dexterity * 10); | ||
} | ||
|
||
public checkHit() { | ||
return MathHelper.genrateRandomNumber(1, this.strength * 10); | ||
} | ||
|
||
public takeDamage(damage: number) { | ||
this._health -= damage; | ||
} | ||
|
||
private SelectColorName(name: string): string { | ||
let result: string = ""; | ||
switch (MathHelper.genrateRandomNumber(0, 6)) { | ||
case 0: | ||
result = color(name).red.toString(); | ||
break; | ||
case 1: | ||
result = color(name).green.toString(); | ||
break; | ||
case 2: | ||
result = color(name).yellow.toString(); | ||
break; | ||
case 3: | ||
result = color(name).blue.toString(); | ||
break; | ||
case 4: | ||
result = color(name).magenta.toString(); | ||
break; | ||
case 5: | ||
result = color(name).cyan.toString(); | ||
break; | ||
default: | ||
result = name; | ||
break; | ||
} | ||
return result; | ||
} | ||
|
||
startBurn(){ | ||
this._isBurn = true; | ||
} | ||
|
||
endBurn(){ | ||
this._isBurn = false; | ||
} | ||
|
||
characterTurn(enemy:Character){ | ||
this.attack(enemy); | ||
this.processEffects(); | ||
} | ||
|
||
protected attack(enemy: Character) { | ||
if (!this.isStunned) { | ||
Logger.startAttackMessage(this); | ||
|
||
let hitStrength = this.checkDexterity(); | ||
let dodgeStrength = enemy.checkDexterity(); | ||
|
||
if (hitStrength > dodgeStrength) { | ||
let damage = this.checkHit(); | ||
enemy.takeDamage(damage); | ||
Logger.successAttackMessage(this, hitStrength, enemy, dodgeStrength, damage) | ||
} | ||
else { | ||
Logger.failedAttackMessage(this, hitStrength, enemy, dodgeStrength) | ||
} | ||
} | ||
} | ||
|
||
hillHP(){ | ||
this._health += 100; | ||
} | ||
|
||
protected processEffects(){ | ||
if(this._isBurn) | ||
{ | ||
this._health -= fireDamage; | ||
Logger.CharacterBurn(this, fireDamage); | ||
} | ||
|
||
if(this.isStunned) | ||
{ | ||
this.isStunned = false; | ||
} | ||
|
||
this._mana += this._manaRegeneration; | ||
} | ||
} | ||
className = ''; | ||
private isBurn = false; | ||
get isBurnValue(): boolean { | ||
return this.isBurn; | ||
} | ||
|
||
protected isStunned = false; | ||
private health: number; | ||
get healthValue(): number { | ||
return this.health; | ||
} | ||
protected minHealth = 5; | ||
protected maxHealth = 10; | ||
|
||
private strength: number; | ||
get strengthValue(): number { | ||
return this.strength; | ||
} | ||
protected minStrength = 5; | ||
protected maxStrength = 10; | ||
|
||
private characterName: string; | ||
get characterNameValue(): string { | ||
return this.characterName; | ||
} | ||
|
||
private dexterity: number; | ||
get dexterityValue(): number { | ||
return this.dexterity; | ||
} | ||
protected minDexterity = 5; | ||
protected maxDexterity = 10; | ||
|
||
protected mana = 0; | ||
get manaValue(): number { | ||
return this.mana; | ||
} | ||
|
||
private manaRegeneration: number; | ||
get manaRegenerationValue(): number { | ||
return this.manaRegeneration; | ||
} | ||
protected minManaRegeneration = 8; | ||
protected maxManaRegeneration = 10; | ||
|
||
private classSkillCost = 0; | ||
get classSkillCostValue(): number { | ||
return this.classSkillCost; | ||
} | ||
protected minClassSkillCost = 15; | ||
protected maxClassSkillCost = 20; | ||
|
||
constructor() { | ||
this.generateStats(); | ||
} | ||
|
||
public stun() { | ||
this.isStunned = true; | ||
} | ||
|
||
private generateStats() { | ||
this.health = MathHelper.genrateRandomNumber(this.minHealth, this.maxHealth); | ||
this.strength = MathHelper.genrateRandomNumber(this.minStrength, this.maxStrength); | ||
this.dexterity = MathHelper.genrateRandomNumber(this.minDexterity, this.maxDexterity); | ||
this.characterName = this.selectColorName(names[MathHelper.genrateRandomNumber(0, names.length - 1)]); | ||
this.manaRegeneration = MathHelper.genrateRandomNumber(this.minManaRegeneration, this.maxManaRegeneration); | ||
this.classSkillCost = MathHelper.genrateRandomNumber(this.minClassSkillCost, this.maxClassSkillCost); | ||
} | ||
|
||
public checkInitiative() { | ||
return MathHelper.genrateRandomNumber(1, this.dexterity * 10); | ||
} | ||
|
||
public checkDexterity() { | ||
return MathHelper.genrateRandomNumber(1, this.dexterity * 10); | ||
} | ||
|
||
public checkHit() { | ||
return MathHelper.genrateRandomNumber(1, this.strengthValue * 10); | ||
} | ||
|
||
public takeDamage(damage: number) { | ||
this.health -= damage; | ||
} | ||
|
||
private selectColorName(name: string): string { | ||
let result = ''; | ||
switch (MathHelper.genrateRandomNumber(0, 6)) { | ||
case 0: | ||
result = color(name).red.toString(); | ||
break; | ||
case 1: | ||
result = color(name).green.toString(); | ||
break; | ||
case 2: | ||
result = color(name).yellow.toString(); | ||
break; | ||
case 3: | ||
result = color(name).blue.toString(); | ||
break; | ||
case 4: | ||
result = color(name).magenta.toString(); | ||
break; | ||
case 5: | ||
result = color(name).cyan.toString(); | ||
break; | ||
default: | ||
result = name; | ||
break; | ||
} | ||
return result; | ||
} | ||
|
||
startBurn() { | ||
this.isBurn = true; | ||
} | ||
|
||
endBurn() { | ||
this.isBurn = false; | ||
} | ||
|
||
characterTurn(enemy: Character) { | ||
this.attack(enemy); | ||
this.processEffects(); | ||
} | ||
|
||
protected attack(enemy: Character) { | ||
if (!this.isStunned) { | ||
Logger.startAttackMessage(this); | ||
|
||
const hitStrength = this.checkDexterity(); | ||
const dodgeStrength = enemy.checkDexterity(); | ||
|
||
if (hitStrength > dodgeStrength) { | ||
const damage = this.checkHit(); | ||
enemy.takeDamage(damage); | ||
Logger.successAttackMessage(this, hitStrength, enemy, dodgeStrength, damage); | ||
} else { | ||
Logger.failedAttackMessage(this, hitStrength, enemy, dodgeStrength); | ||
} | ||
} | ||
} | ||
|
||
hillHP() { | ||
this.health += 100; | ||
} | ||
|
||
protected processEffects() { | ||
if (this.isBurn) { | ||
this.health -= fireDamage; | ||
Logger.characterBurn(this, fireDamage); | ||
} | ||
|
||
if (this.isStunned) { | ||
this.isStunned = false; | ||
} | ||
|
||
this.mana += this.manaRegeneration; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,35 @@ | ||
import { Character } from "../character"; | ||
import { Logger } from "../logger"; | ||
import { Character } from '../character'; | ||
import { Logger } from '../logger'; | ||
|
||
export class Archer extends Character { | ||
|
||
_minHealth = 5; | ||
_maxHealth = 8; | ||
minHealth = 5; | ||
maxHealth = 8; | ||
|
||
_minStrength = 7; | ||
_maxStrength = 10; | ||
minStrength = 7; | ||
maxStrength = 10; | ||
|
||
_minDexterity = 7; | ||
_maxDexterity = 10; | ||
minDexterity = 7; | ||
maxDexterity = 10; | ||
|
||
_minManaRegeneration = 8; | ||
_maxManaRegeneration = 15; | ||
minManaRegeneration = 8; | ||
maxManaRegeneration = 15; | ||
|
||
_minClassSkillCost = 10; | ||
_maxClassSkillCost = 20; | ||
minClassSkillCost = 10; | ||
maxClassSkillCost = 20; | ||
|
||
className: string = "Лучник"; | ||
className = 'Лучник'; | ||
|
||
attack(enemy: Character): void { | ||
if (this.classSkillCost < this.mana && !enemy.isBurn) { | ||
Logger.UseArcherSkill(this, enemy); | ||
enemy.startBurn(); | ||
this._mana -= this.classSkillCost; | ||
} | ||
else { | ||
super.attack(enemy); | ||
} | ||
attack(enemy: Character): void { | ||
if (this.classSkillCostValue < this.manaValue && !enemy.isBurnValue) { | ||
Logger.useArcherSkill(this, enemy); | ||
enemy.startBurn(); | ||
this.mana -= this.classSkillCostValue; | ||
} else { | ||
super.attack(enemy); | ||
} | ||
} | ||
|
||
constructor() { | ||
super(); | ||
} | ||
} | ||
constructor() { | ||
super(); | ||
} | ||
} |
Oops, something went wrong.