Code style refactors [minor]
This commit is contained in:
parent
ad3a648765
commit
6e617b970e
4
Tank.ts
4
Tank.ts
@ -1,9 +1,9 @@
|
|||||||
export interface ITank {
|
export interface ITank {
|
||||||
name: string;
|
name: string;
|
||||||
health: number;
|
health: number;
|
||||||
|
|
||||||
attackDelay: number;
|
attackDelay: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
type BuildTank = (name: string) => ITank;
|
type BuildTank = (name: string) => ITank;
|
||||||
export const buildTank: BuildTank = (name) => ({
|
export const buildTank: BuildTank = (name) => ({
|
||||||
name,
|
name,
|
||||||
@ -11,7 +11,6 @@ export const buildTank: BuildTank = (name) => ({
|
|||||||
attackDelay: 0,
|
attackDelay: 0,
|
||||||
} as ITank);
|
} as ITank);
|
||||||
|
|
||||||
|
|
||||||
type CritMultiplier = (health: number) => number;
|
type CritMultiplier = (health: number) => number;
|
||||||
const critMultiplier: CritMultiplier = (health) =>
|
const critMultiplier: CritMultiplier = (health) =>
|
||||||
Math.floor(Math.random() * 10) >= 10 - health / 10 ? 1 : 2;
|
Math.floor(Math.random() * 10) >= 10 - health / 10 ? 1 : 2;
|
||||||
@ -24,6 +23,7 @@ const setStats: SetStats = (tank) => ({
|
|||||||
|
|
||||||
type Attack = (_: ITank[], tank: ITank, tIndex: number, tanks: ITank[]) => ITank[];
|
type Attack = (_: ITank[], tank: ITank, tIndex: number, tanks: ITank[]) => ITank[];
|
||||||
const attack: Attack = (_acc, tank, _iTank, tanks) => {
|
const attack: Attack = (_acc, tank, _iTank, tanks) => {
|
||||||
|
// Must refactor this imperative block
|
||||||
if (tank.attackDelay === 0) {
|
if (tank.attackDelay === 0) {
|
||||||
const target = tanks[Math.floor(Math.random() * tanks.length)];
|
const target = tanks[Math.floor(Math.random() * tanks.length)];
|
||||||
const attackDamage = critMultiplier(tank.health) * tank.health / 100;
|
const attackDamage = critMultiplier(tank.health) * tank.health / 100;
|
||||||
|
Loading…
Reference in New Issue
Block a user