-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcombat.js
More file actions
46 lines (39 loc) · 962 Bytes
/
combat.js
File metadata and controls
46 lines (39 loc) · 962 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { getRandom, $arenas, $formFight, createElement } from './utils.js';
const HIT = {
head: 30,
body: 25,
foot: 20,
}
const ATTACK = ['head', 'body', 'foot'];
export function isWinner(player) {
const $winTitle = createElement('div', 'loseTitle');
if (player) {
$winTitle.innerText = player.name + ' win';
} else {
$winTitle.innerText = 'draw';
}
$arenas.appendChild($winTitle);
}
export function enemyAttack() {
const hit = ATTACK[getRandom(3) - 1];
const defence = ATTACK[getRandom(3) - 1];
return {
value: getRandom(HIT[hit]),
hit,
defence
}
}
export function playerAttack() {
const attack = {};
for (let item of $formFight) {
if (item.checked && item.name === 'hit') {
attack.value = getRandom(HIT[item.value]);
attack.hit = item.value;
}
if (item.checked && item.name === 'defence') {
attack.defence = item.value;
}
item.checked = false;
}
return attack;
}