/
mrrobot
/
js-final
Обзор
Документация
Войти
/
mrrobot
/
js-final
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/Game.js
47 строк
1 KB
Ivan Popov
game
22 май 2026, 19:42
22 май 2026, 19:42
1125ae5
Код
Авторство
О чём код?
'use strict'; const MAX_TURNS = 1000; function getAlive(players) { return players.filter((p) => !p.isDead()); } function play(players) { console.log('=== Начало битвы ==='); for (const p of players) { console.log(`${p.name} (${p.description}): жизнь=${p.life}, позиция=${p.position}, оружие=${p.weapon.name}.`); } let turnCount = 0; while (getAlive(players).length > 1 && turnCount < MAX_TURNS) { turnCount += 1; console.log(`\n--- Ход ${turnCount} ---`); const turnOrder = getAlive(players); for (const player of turnOrder) { if (player.isDead()) { continue; } const currentAlive = getAlive(players); if (currentAlive.length <= 1) { break; } player.turn(currentAlive); } } const survivors = getAlive(players); if (survivors.length === 1) { const winner = survivors[0]; console.log(`\n=== Победитель: ${winner.name} (${winner.description}) с жизнью ${winner.life.toFixed(2)} ===`); return winner; } if (survivors.length > 1) { const leader = survivors.reduce((max, p) => (p.life > max.life ? p : max), survivors[0]); console.log(`\n=== Битва не закончилась за ${MAX_TURNS} ходов. Лидер: ${leader.name} (жизнь ${leader.life.toFixed(2)}) ===`); return leader; } console.log('\n=== Все погибли ==='); return null; } module.exports = { play, MAX_TURNS };