From 6e617b970e211c1baf8d4fdb1d2ac90a52801db8 Mon Sep 17 00:00:00 2001 From: texhno Date: Tue, 5 Dec 2023 20:22:01 +0100 Subject: [PATCH] Code style refactors [minor] --- Tank.ts | 4 ++-- index.ts | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Tank.ts b/Tank.ts index 268aefd..fa02acd 100644 --- a/Tank.ts +++ b/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; diff --git a/index.ts b/index.ts index bfc9745..05fb31d 100644 --- a/index.ts +++ b/index.ts @@ -20,4 +20,6 @@ const tankPrototypes = [ ]; const initialTanks = tankPrototypes.map(buildTank); -console.log(battleItOut(initialTanks).name); +const winner = battleItOut(initialTanks); + +console.log(winner);