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 {
|
||||
name: string;
|
||||
health: number;
|
||||
|
||||
attackDelay: number;
|
||||
}
|
||||
|
||||
type BuildTank = (name: string) => ITank;
|
||||
export const buildTank: BuildTank = (name) => ({
|
||||
name,
|
||||
@ -11,7 +11,6 @@ export const buildTank: BuildTank = (name) => ({
|
||||
attackDelay: 0,
|
||||
} as ITank);
|
||||
|
||||
|
||||
type CritMultiplier = (health: number) => number;
|
||||
const critMultiplier: CritMultiplier = (health) =>
|
||||
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[];
|
||||
const attack: Attack = (_acc, tank, _iTank, tanks) => {
|
||||
// Must refactor this imperative block
|
||||
if (tank.attackDelay === 0) {
|
||||
const target = tanks[Math.floor(Math.random() * tanks.length)];
|
||||
const attackDamage = critMultiplier(tank.health) * tank.health / 100;
|
||||
|
Loading…
Reference in New Issue
Block a user