{"id":339976,"date":"2022-10-19T21:00:09","date_gmt":"2022-10-19T21:00:09","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=339976"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=339976","title":{"rendered":"<span>\u041f\u043e\u0448\u0430\u0433\u043e\u0432\u0430\u044f \u0431\u043e\u0435\u0432\u0430\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 JS<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0432\u044b, \u043a\u0430\u043a \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442, \u043a\u043e\u0433\u0434\u0430-\u0442\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043e\u0432\u0430\u043b\u0438\u0441\u044c \u043f\u043e\u0448\u0430\u0433\u043e\u0432\u044b\u043c\u0438 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044f\u043c\u0438. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0440\u0435\u0448\u0438\u043b \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043e \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u043c \u0432\u0437\u0433\u043b\u044f\u0434\u0435 \u043d\u0430 \u044d\u0442\u0443 \u0442\u0435\u043c\u0443, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f JavaScript<br \/>\u041a\u0442\u043e \u0437\u0430\u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043e\u0432\u0430\u043d &#8212; \u0434\u043e\u0431\u0440\u043e \u043f\u043e\u0436\u0430\u043b\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0434 \u043a\u0430\u0442<\/p>\n<hr\/>\n<p>\u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442, \u044d\u0442\u043e stalker320, \u044f \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u043b \u043a\u0430\u043a\u043e\u0435-\u0442\u043e \u0432\u0440\u0435\u043c\u044f \u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u0435\u0440\u043d\u0443\u043b\u0441\u044f \u0438\u0437 \u0441\u043f\u044f\u0447\u043a\u0438.<\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u043c \u0437\u0430\u0434\u0430\u0447\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0442 \u0440\u0435\u0448\u0438\u0442\u044c \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c.<\/p>\n<ul>\n<li>\n<p>\u041a\u043b\u0430\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0438\u0433\u0440\u043e\u0432\u044b\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u044f. \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u043e\u043d \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f Game;<\/p>\n<\/li>\n<li>\n<p>\u041a\u043b\u0430\u0441\u0441, \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0437\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0438\u0433\u0440\u043e\u043a\u0430 \u0438 \u043c\u043e\u0431\u0430, \u043a\u043b\u0430\u0441\u0441 Entity;<\/p>\n<\/li>\n<li>\n<p>\u041a\u043b\u0430\u0441\u0441 \u0438\u043d\u0432\u0435\u043d\u0442\u0430\u0440\u044f;<\/p>\n<\/li>\n<li>\n<p>\u041a\u043b\u0430\u0441\u0441 \u043f\u0440\u0435\u0434\u043c\u0435\u0442\u0430;<\/p>\n<\/li>\n<li>\n<p>\u0418 \u043d\u0430\u043f\u043e\u0441\u043b\u0435\u0434\u043e\u043a \u043a\u043b\u0430\u0441\u0441 \u0434\u0435\u0439\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e \u044d\u0444\u0444\u0435\u043a\u0442\u0430.<\/p>\n<\/li>\n<\/ul>\n<h2>\u041a\u043b\u0430\u0441\u0441 Effect<\/h2>\n<p>\u041d\u0430\u0447\u0438\u043d\u0430\u0442\u044c \u043d\u0443\u0436\u043d\u043e \u0441 \u0442\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430\u0434\u0435\u0439\u0441\u0442\u0432\u0443\u0435\u0442 \u043d\u0430\u0438\u043c\u0435\u043d\u044c\u0448\u0435\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u043d\u0438\u0439 \u0434\u0440\u0443\u0433\u0438\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432. \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e \u043a\u043b\u0430\u0441\u0441 <code>Effect<\/code> \u0438 \u0443 \u043d\u0435\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u0434\u0432\u0430 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 <code>name<\/code> \u0438 <code>steps_left<\/code>.<\/p>\n<pre><code class=\"javascript\">class Effect {   constructor(name, steps_left) {     this.name = name;     this.steps_left = steps_left;   }   get_name() {     return this.name;   }   get_steps_left() {     return this.steps_left;   }   count() {     \/\/ \u043e\u0442\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442 1 \u0445\u043e\u0434.     this.steps_left -= 1;   } }<\/code><\/pre>\n<p>\u0414\u0430\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u043d\u0438\u0447\u0435\u0433\u043e \u0441\u0430\u043c \u043f\u043e \u0441\u0435\u0431\u0435 \u043d\u0435 \u0434\u0435\u043b\u0430\u0435\u0442, \u043d\u043e \u0437\u0430\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0435\u0442 \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b \u043d\u0430 \u0431\u0443\u0434\u0443\u0449\u0435\u0435.<br \/>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043c\u043e\u0436\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0432\u0430\u0440\u0438\u0430\u0446\u0438\u0438 \u044d\u0444\u0444\u0435\u043a\u0442\u043e\u0432:<\/p>\n<pre><code class=\"javascript\">\/\/ \u041a\u0440\u043e\u0432\u043e\u0442\u0435\u0447\u0435\u043d\u0438\u0435 class BleedingEffect extends Effect {   constructor(name, steps_left, damage) {     super(name, steps_left);     this.damage = damage;   }   get_damage() {     return this.damage;   } }  \/\/ \u0420\u0435\u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f class RegeneartionEffect extends Effect {   constructor(name, steps_left, heal) {     super(name, steps_left);     this.heal = heal;   }   get_heal_count() {     return this.heal;   } }  \/\/ \u041f\u0430\u0441\u0441\u0438\u0432\u043d\u0430\u044f \u0431\u0440\u043e\u043d\u044f \u043a\u0430\u0436\u0434\u044b\u0439 \u0445\u043e\u0434 class PassiveArmorEffect extends Effect {   constructor(name, steps_left, armor) {     super(name, steps_left);     this.armor = armor;   }   get_armor() {     return this.armor;   } }<\/code><\/pre>\n<p>\u0410 \u0435\u0449\u0451 \u0431\u043e\u043b\u0435\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u043c \u043c\u0435\u0442\u043e\u0434\u043e\u043c \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u044d\u0444\u0444\u0435\u043a\u0442\u043e\u0432 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043d\u0430 \u043c\u0435\u0441\u0442\u0435.<\/p>\n<pre><code class=\"javascript\">let berserk = new class BerserkEffect extends Effect {   constructor(name, steps_left) {     super(name, steps_left);   }   get_dmg_multiplier() {return 1.5;}   get_resistance() {return -0.5;} \/\/ \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0441\u043e\u043f\u0440\u043e\u0442\u0438\u0432\u043b\u0435\u043d\u0438\u0435 \u0443\u0440\u043e\u043d\u0443, \u0447\u0442\u043e \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c\u044b\u0439 \u0443\u0440\u043e\u043d \u043d\u0430 50% }();<\/code><\/pre>\n<h2>\u041a\u043b\u0430\u0441\u0441 Item<\/h2>\n<p>\u041f\u0440\u0435\u0434\u043c\u0435\u0442 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0448\u0430\u0431\u043b\u043e\u043d \u0434\u043b\u044f \u043c\u043d\u043e\u0433\u043e\u0433\u043e &#8212; \u043e\u0440\u0443\u0436\u0438\u0435, \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b, \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f.<\/p>\n<pre><code class=\"javascript\">class Item {   constructor(name) {     this.name = name;   }   get_name() {     return this.name;   } }<\/code><\/pre>\n<p>\u0421\u0430\u043c \u043a\u043b\u0430\u0441\u0441 <code>Item<\/code> \u043d\u0430\u043c \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0434\u0430\u0451\u0442, \u043d\u043e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u043e\u0439 \u0434\u043b\u044f \u0434\u0440\u0443\u0433\u0438\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u044f \u043f\u0440\u0438\u0432\u0435\u0434\u0443 \u0435\u0449\u0451 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043a\u043b\u0430\u0441\u0441\u043e\u0432, \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445\u0441\u044f \u043e\u0442 <code>Item<\/code>.<\/p>\n<pre><code class=\"javascript\">class Weapon extends Item {   constructor(name, damage, effect) {     super(name);     this.damage = damage;     this.effect = effect;   }   get_damage() {     return this.damage;   }   get_effect() {     return this.effect;   } }<\/code><\/pre>\n<p>\u041a\u043b\u0430\u0441\u0441 <code>Weapon<\/code> \u0438\u043c\u0435\u0435\u0442 \u0434\u0432\u0430 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0432 \u0434\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043a \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u043c <code>Item<\/code>. \u042d\u0442\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 damage \u0438 effect.<\/p>\n<pre><code class=\"javascript\">class Shield extends Item {   constructor(name, armor) {     super(name);     this.armor = armor;   }   get_shield() {     return this.armor;   } }<\/code><\/pre>\n<p>\u0429\u0438\u0442, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0443\u0440\u043e\u043d\u0430 \u043c\u0438\u043c\u043e \u043f\u043e\u043b\u043e\u0441\u044b \u0437\u0434\u043e\u0440\u043e\u0432\u044c\u044f<\/p>\n<pre><code class=\"javascript\">class Potion extends Item {   constructor(name, effect) {     super(name);     this.effect = effect;   }   get_effect() {     return this.effect;   } } \/\/ \u0417\u0435\u043b\u044c\u0435 \u043b\u0435\u0447\u0435\u043d\u0438\u044f \u0437\u0430 \u043e\u0434\u0438\u043d \u0445\u043e\u0434, \u043a\u0430\u043a \u043f\u0440\u0438\u043c\u0435\u0440 class HealPotion extends Potion {   constructor(name, heal_count) {     super(name, new RegenerationEffect(name, 1, heal_count));   } } class RegeneratonPotion extends Potion {   constructor(name, steps, heal_count) {     super(name, new RegenerationEffect(name, steps, heal_count));   } }<\/code><\/pre>\n<p>\u0410 \u0442\u0430\u043a\u0436\u0435 \u0442\u043e\u043d\u043d\u044b \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0432\u0438\u0434\u043e\u0432 \u0437\u0435\u043b\u0438\u0439, \u043d\u0430\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u044e\u0449\u0438\u0445 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u044b \u043d\u0430 \u043f\u0435\u0440\u0441\u043e\u043d\u0430\u0436\u0430 \u043f\u0440\u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0438.<\/p>\n<h2>\u041a\u043b\u0430\u0441\u0441 Inventory<\/h2>\n<p>\u041f\u0440\u043e\u0441\u0442\u043e\u0439 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0434\u043b\u044f \u043c\u0430\u0441\u0441\u0438\u0432\u0430, \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u044e\u0449\u0438\u0439 \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0439 \u0442\u0438\u043f \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0440\u0430\u0437\u043c\u0435\u0440.<\/p>\n<pre><code class=\"javascript\">class Inventory {   \/\/ \u0418\u043d\u0432\u0435\u043d\u0442\u0430\u0440\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043c\u0435\u0441\u0442\u043e, \u0433\u0434\u0435 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0432\u0441\u0435 \u043f\u0440\u0435\u0434\u043c\u0435\u0442\u044b   container;   container_size = 16;      constructor(container_size = 16) {     this.container_size = container_size;     this.container = Array();   }   set_item(idx, item) {     \/**      * idx - \u0447\u0438\u0441\u043b\u043e      * item - \u043e\u0431\u044a\u0435\u043a\u0442 \u043e\u0442 \u043a\u043b\u0430\u0441\u0441\u0430 Item     *\/     if ( !(item instanceof Item)) {       throw new Error(\"item isn't instance of Item\");     }     if (idx &lt; 0 || idx > this.container_size) {       throw new Error(\"idx out of bounds\");     }     this.container[idx] = item;   }   get_item(idx) {     \/**       * idx - \u0447\u0438\u0441\u043b\u043e     *\/     if (idx &lt; 0 || idx > this.container_size) {       throw new Error(\"idx out of bounds\");     }     return container[idx];   } }<\/code><\/pre>\n<h2>\u041a\u043b\u0430\u0441\u0441 Entity<\/h2>\n<p>\u042d\u0442\u043e\u0442 \u043a\u043b\u0430\u0441\u0441 \u043d\u0430\u0432\u0435\u0440\u043d\u043e\u0435 \u0432\u0442\u043e\u0440\u043e\u0439 \u043f\u043e \u0432\u0430\u0436\u043d\u043e\u0441\u0442\u0438 \u043a\u043b\u0430\u0441\u0441. \u041e\u043d \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u0432\u0441\u0435\u0445 \u043c\u043e\u0431\u043e\u0432 \u0438 \u0438\u0433\u0440\u043e\u043a\u0430, \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c.<br \/>\u0423 \u043d\u0435\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u043d\u0435 \u043e\u0441\u043e\u0431\u043e \u043c\u043d\u043e\u0433\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432, \u043d\u043e \u043e\u043d\u0438 \u0431\u0443\u0434\u0443\u0442 \u0443\u043c\u0435\u0441\u0442\u043d\u044b\u043c\u0438<\/p>\n<p>&#8212; \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0437\u0434\u043e\u0440\u043e\u0432\u044c\u0435 <code>max_health<\/code><br \/>&#8212; \u0442\u0435\u043a\u0443\u0449\u0435\u0435 \u0437\u0434\u043e\u0440\u043e\u0432\u044c\u0435 <code>health<\/code><br \/>&#8212; \u0429\u0438\u0442 <code>shield<\/code><br \/>&#8212; \u0438\u043d\u0432\u0435\u043d\u0442\u0430\u0440\u044c \u043e\u0442 <code>Inventory<\/code> <code>inventory<\/code><br \/>&#8212; \u044d\u0444\u0444\u0435\u043a\u0442\u044b <code>effects<\/code><br \/>&#8212; \u043e\u0447\u043a\u0438 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 <code>steps<\/code><br \/>&#8212; \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c \u043e\u0447\u043a\u043e\u0432 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 <code>max_steps<\/code><\/p>\n<pre><code class=\"javascript\">class Entity {   max_health;   health;   shield = 0;   inventory = new Inventory(16);   effects = Array();   steps;   max_steps;   weapon_idx = -1;   constructor(max_health = 100, max_steps = 3) {     this.max_health = max_health;     this.health = max_health;     this.steps = max_steps;     this.max_steps = max_steps;   }      gain_damage(damage, effect) {     if (effect !== null) {       this.effects.push(effect);     }     let dmg = damage;     \/\/ \u041e\u0411\u0420\u0410\u0411\u041e\u0422\u041a\u0410 \u0421\u041e\u041f\u0420\u041e\u0422\u0418\u0412\u041b\u0415\u041d\u0418\u0419     for (const effect in this.effects) {         if (effect.get_resistance !== null) {           dmg *= (1 - effect.get_resistance());         }       }     let dmg_left = dmg - this.shield;     if (dmg_left >= 0) {       this.health = health - dmg_left;       this.reset_shield();     }     else {       this.shield -= damage;     }      if (this.health &lt; 0) this.health = 0;   }   setup_shield(shield_count, effect) {     if (effect !== null) {       this.effects.push(effect);     }     let def = shield_count;      \/\/ \u041e\u0411\u0420\u0410\u0411\u041e\u0422\u041a\u0410 \u0418\u041d\u041a\u0420\u0415\u041c\u0415\u041d\u0422\u041e\u0412 \u0432 \u043f\u0435\u0440\u0432\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c     this.effects.forEach((effect) => {       if (effect.get_def_incrementation !== null) {         def += effect.get_def_incrementation();       }     });     \/\/ \u041e\u0411\u0420\u0410\u0411\u041e\u0422\u041a\u0410 \u041c\u041d\u041e\u0416\u0418\u0422\u0415\u041b\u0415\u0419 \u0434\u0430\u043b\u0435\u0435     this.effects.forEach((effect) => {       if (effect.get_def_multiplier !== null) {         def *= effect.get_def_multiplier();       }     })          this.shield += def;   }   reset_shield() {     this.shield = 0;   }   heal(heal_count, effect) {     if (effect !== null) {       this.effects.push(effect);     }     if (this.health &lt; this.max_health) {       this.health += heal_count;     }     if (this.health > this.max_health) this.health = this.max_health;        }      deal_damage(target, weapon) {     if (weapon instanceof Weapon) {       let dmg = weapon.get_damage();       \/\/ \u041e\u0411\u0420\u0410\u0411\u041e\u0422\u041a\u0410 \u0418\u041d\u041a\u0420\u0415\u041c\u0415\u041d\u0422\u041e\u0412 \u0432 \u043f\u0435\u0440\u0432\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c       this.effects.forEach((effect) => {         if (effect.get_dmg_incrementation !== null) {           dmg += effect.get_dmg_incrementation();         }       });       \/\/ \u041e\u0411\u0420\u0410\u0411\u041e\u0422\u041a\u0410 \u041c\u041d\u041e\u0416\u0418\u0422\u0415\u041b\u0415\u0419 \u0434\u0430\u043b\u0435\u0435       this.effects.forEach((effect) => {         if (effect.get_dmg_multiplier !== null) {           dmg *= effect.get_dmg_multiplier();         }       })       target.gain_damage(dmg, weapon.get_effect());     }   }   is_alive() {     return this.health > 0;   }   step() {     \/** \u0441\u0447\u0438\u0442\u0430\u0442\u044c \u043f\u043e\u0441\u043b\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u0430\u0442\u0430\u043a\u0438\/\u0437\u0430\u0449\u0438\u0442\u044b\/\u043b\u0435\u0447\u0435\u043d\u0438\u044f.       *     *\/     for (let i = 0; i &lt; this.effects.length; i++) {       const effect = this.effects[i];       if (effect.get_damage !== null) {         this.gain_damage(effect.get_damage(), null);       }       if (effect.get_heal_count !== null) {         this.heal(effect.get_heal_count(), null);       }       if (effect.get_armor !== null) {         this.heal(effect.get_armor(), null);       }       effect.count();       if (effect.get_steps_left() &lt;= 0) {         this.effects[i] = null;       }     }     this.effects = this.effects.filter((elem) => {return elem != null;});     \/\/ \u0417\u0434\u0435\u0441\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0430 \u0441\u0442\u0440\u0435\u043b\u043e\u0447\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438 \u043f\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c \u0431\u0435\u0437 null   }   get_weapon() {     if (this.weapon_idx >= 0) return this.inventory.get_item(this.weapon_idx);     else return null;   } }<\/code><\/pre>\n<p>\u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u0447\u0442\u043e \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438 \u0438\u0437\u043b\u0438\u0448\u043d\u0438, \u043d\u043e \u0435\u0441\u043b\u0438 \u043a\u0430\u043a\u0438\u0435-\u0442\u043e \u043c\u043e\u043c\u0435\u043d\u0442 \u043d\u0435 \u043f\u043e\u043d\u044f\u0442\u043d\u044b, \u043d\u0435 \u0441\u0442\u0435\u0441\u043d\u044f\u0439\u0442\u0435\u0441\u044c, \u0434\u043e\u0440\u043e\u0433\u0438\u0435 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u0438, \u0443\u0442\u043e\u0447\u043d\u044f\u0442\u044c \u043d\u0435\u043f\u043e\u043d\u044f\u0442\u043d\u044b\u0435 \u0438\u043b\u0438 \u043d\u0435\u0432\u0435\u0440\u043d\u044b\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445.<\/p>\n<h2>\u041a\u043b\u0430\u0441\u0441 Game<\/h2>\n<p>\u0421\u0430\u043c\u044b\u0439 \u0433\u043b\u0430\u0432\u043d\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435. \u041e\u043d \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u0438\u0433\u0440\u043e\u0432\u043e\u0439 \u0446\u0438\u043a\u043b, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e \u0441\u043e\u0431\u044b\u0442\u0438\u0439. \u0412\u043e\u0442 \u0447\u0442\u043e \u043e\u043d \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c:<\/p>\n<p>&#8212; \u041d\u043e\u043c\u0435\u0440 <code>Entity<\/code>, \u0441\u0435\u0439\u0447\u0430\u0441 \u0445\u043e\u0434\u044f\u0449\u0435\u0433\u043e, <code>step_idx<\/code><br \/>&#8212; \u043c\u0430\u0441\u0441\u0438\u0432 \u0438\u0437 <code>Entity<\/code>, <code>entities<\/code><br \/>&#8212; \u041d\u043e\u043c\u0435\u0440 \u0438\u0433\u0440\u043e\u043a\u0430 <code>player_idx<\/code><br \/>&#8212; \u0421\u043f\u0438\u0441\u043e\u043a \u0441\u043e\u044e\u0437\u043d\u0438\u043a\u043e\u0432 <code>ally_idxes<\/code><br \/>&#8212; \u0421\u043f\u0438\u0441\u043e\u043a \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u0438\u043a\u043e\u0432 <code>enemy_idxes<\/code><br \/>&#8212; \u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e <code>Entity<\/code>, <code>entities_count<\/code><\/p>\n<pre><code class=\"javascript\">class Game {   entities = Array();   step_idx = -1;   player_idx = -1;   entities_count = 0;   ally_idxes = Array();   enemy_idxes = Array();      constructor(allies_count, enemies_count) {     this.entities_count = allies_count + enemies_count;     this.step_idx = 0;     this.player_idx = 0;          for (let i = 0; i &lt; this.entities_count; i++) {       if (i &lt; allies_count) {         \/\/ \u0421\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u043f\u0438\u0441\u043a\u0438 \u0441\u043e\u044e\u0437\u043d\u0438\u043a\u043e\u0432         ally_idxes[ally_idxes.length] = i;       }       else if (i > allies_count &amp;&amp; i &lt; allies_count + enemies_count) {         \/\/ ... \u0438 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u0438\u043a\u043e\u0432         enemy_idxes[enemy_idxes.length] = i;       }     }   }   step(action) {     const entity = this.entities[step_idx];      if (action == 0) {       entity.dealDamage(target, entity.get_weapon());     }     else if (action == 1) {       entity.     }          entity.step();          this.step_count(entity);   }   step_count(entity) {     entity.steps -= 1;     if (entity.steps &lt;= 0) {       entity.steps = entity.max_steps;       this.step_idx += 1;       if (this.step_idx >= this.entities_count) this.step_idx = 0;     }   } }<\/code><\/pre>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>\u0421\u0435\u0433\u043e\u0434\u043d\u044f \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043b, \u0442\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0439 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a, \u0435\u0441\u043b\u0438 \u043d\u0435 \u0438\u0433\u0440\u043e\u0432\u043e\u0439 \u0434\u0432\u0438\u0436\u043e\u043a \u043d\u0430 JavaScript.<\/p>\n<h4>P. S.<\/h4>\n<p>\u041c\u043d\u0435 \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0441\u0438\u043b\u044c\u043d\u043e \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0432\u044b\u0441\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u0440\u0435\u0448\u0438\u043b \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u044d\u0442\u0443 \u0441\u0442\u0430\u0442\u044c\u044e.<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/694390\/\"> https:\/\/habr.com\/ru\/post\/694390\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0432\u044b, \u043a\u0430\u043a \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442, \u043a\u043e\u0433\u0434\u0430-\u0442\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043e\u0432\u0430\u043b\u0438\u0441\u044c \u043f\u043e\u0448\u0430\u0433\u043e\u0432\u044b\u043c\u0438 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044f\u043c\u0438. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0440\u0435\u0448\u0438\u043b \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043e \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u043c \u0432\u0437\u0433\u043b\u044f\u0434\u0435 \u043d\u0430 \u044d\u0442\u0443 \u0442\u0435\u043c\u0443, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f JavaScript<br \/>\u041a\u0442\u043e \u0437\u0430\u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043e\u0432\u0430\u043d &#8212; \u0434\u043e\u0431\u0440\u043e \u043f\u043e\u0436\u0430\u043b\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0434 \u043a\u0430\u0442<\/p>\n<hr\/>\n<p>\u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442, \u044d\u0442\u043e stalker320, \u044f \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u043b \u043a\u0430\u043a\u043e\u0435-\u0442\u043e \u0432\u0440\u0435\u043c\u044f \u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u0435\u0440\u043d\u0443\u043b\u0441\u044f \u0438\u0437 \u0441\u043f\u044f\u0447\u043a\u0438.<\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u043c \u0437\u0430\u0434\u0430\u0447\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0442 \u0440\u0435\u0448\u0438\u0442\u044c \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c.<\/p>\n<ul>\n<li>\n<p>\u041a\u043b\u0430\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0438\u0433\u0440\u043e\u0432\u044b\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u044f. \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u043e\u043d \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f Game;<\/p>\n<\/li>\n<li>\n<p>\u041a\u043b\u0430\u0441\u0441, \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0437\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0438\u0433\u0440\u043e\u043a\u0430 \u0438 \u043c\u043e\u0431\u0430, \u043a\u043b\u0430\u0441\u0441 Entity;<\/p>\n<\/li>\n<li>\n<p>\u041a\u043b\u0430\u0441\u0441 \u0438\u043d\u0432\u0435\u043d\u0442\u0430\u0440\u044f;<\/p>\n<\/li>\n<li>\n<p>\u041a\u043b\u0430\u0441\u0441 \u043f\u0440\u0435\u0434\u043c\u0435\u0442\u0430;<\/p>\n<\/li>\n<li>\n<p>\u0418 \u043d\u0430\u043f\u043e\u0441\u043b\u0435\u0434\u043e\u043a \u043a\u043b\u0430\u0441\u0441 \u0434\u0435\u0439\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e \u044d\u0444\u0444\u0435\u043a\u0442\u0430.<\/p>\n<\/li>\n<\/ul>\n<h2>\u041a\u043b\u0430\u0441\u0441 Effect<\/h2>\n<p>\u041d\u0430\u0447\u0438\u043d\u0430\u0442\u044c \u043d\u0443\u0436\u043d\u043e \u0441 \u0442\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430\u0434\u0435\u0439\u0441\u0442\u0432\u0443\u0435\u0442 \u043d\u0430\u0438\u043c\u0435\u043d\u044c\u0448\u0435\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u043d\u0438\u0439 \u0434\u0440\u0443\u0433\u0438\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432. \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e \u043a\u043b\u0430\u0441\u0441 <code>Effect<\/code> \u0438 \u0443 \u043d\u0435\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u0434\u0432\u0430 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 <code>name<\/code> \u0438 <code>steps_left<\/code>.<\/p>\n<pre><code class=\"javascript\">class Effect {   constructor(name, steps_left) {     this.name = name;     this.steps_left = steps_left;   }   get_name() {     return this.name;   }   get_steps_left() {     return this.steps_left;   }   count() {     \/\/ \u043e\u0442\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442 1 \u0445\u043e\u0434.     this.steps_left -= 1;   } }<\/code><\/pre>\n<p>\u0414\u0430\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u043d\u0438\u0447\u0435\u0433\u043e \u0441\u0430\u043c \u043f\u043e \u0441\u0435\u0431\u0435 \u043d\u0435 \u0434\u0435\u043b\u0430\u0435\u0442, \u043d\u043e \u0437\u0430\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0435\u0442 \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b \u043d\u0430 \u0431\u0443\u0434\u0443\u0449\u0435\u0435.<br \/>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043c\u043e\u0436\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0432\u0430\u0440\u0438\u0430\u0446\u0438\u0438 \u044d\u0444\u0444\u0435\u043a\u0442\u043e\u0432:<\/p>\n<pre><code class=\"javascript\">\/\/ \u041a\u0440\u043e\u0432\u043e\u0442\u0435\u0447\u0435\u043d\u0438\u0435 class BleedingEffect extends Effect {   constructor(name, steps_left, damage) {     super(name, steps_left);     this.damage = damage;   }   get_damage() {     return this.damage;   } }  \/\/ \u0420\u0435\u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f class RegeneartionEffect extends Effect {   constructor(name, steps_left, heal) {     super(name, steps_left);     this.heal = heal;   }   get_heal_count() {     return this.heal;   } }  \/\/ \u041f\u0430\u0441\u0441\u0438\u0432\u043d\u0430\u044f \u0431\u0440\u043e\u043d\u044f \u043a\u0430\u0436\u0434\u044b\u0439 \u0445\u043e\u0434 class PassiveArmorEffect extends Effect {   constructor(name, steps_left, armor) {     super(name, steps_left);     this.armor = armor;   }   get_armor() {     return this.armor;   } }<\/code><\/pre>\n<p>\u0410 \u0435\u0449\u0451 \u0431\u043e\u043b\u0435\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u043c \u043c\u0435\u0442\u043e\u0434\u043e\u043c \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u044d\u0444\u0444\u0435\u043a\u0442\u043e\u0432 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043d\u0430 \u043c\u0435\u0441\u0442\u0435.<\/p>\n<pre><code class=\"javascript\">let berserk = new class BerserkEffect extends Effect {   constructor(name, steps_left) {     super(name, steps_left);   }   get_dmg_multiplier() {return 1.5;}   get_resistance() {return -0.5;} \/\/ \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0441\u043e\u043f\u0440\u043e\u0442\u0438\u0432\u043b\u0435\u043d\u0438\u0435 \u0443\u0440\u043e\u043d\u0443, \u0447\u0442\u043e \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c\u044b\u0439 \u0443\u0440\u043e\u043d \u043d\u0430 50% }();<\/code><\/pre>\n<h2>\u041a\u043b\u0430\u0441\u0441 Item<\/h2>\n<p>\u041f\u0440\u0435\u0434\u043c\u0435\u0442 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0448\u0430\u0431\u043b\u043e\u043d \u0434\u043b\u044f \u043c\u043d\u043e\u0433\u043e\u0433\u043e &#8212; \u043e\u0440\u0443\u0436\u0438\u0435, \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b, \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f.<\/p>\n<pre><code class=\"javascript\">class Item {   constructor(name) {     this.name = name;   }   get_name() {     return this.name;   } }<\/code><\/pre>\n<p>\u0421\u0430\u043c \u043a\u043b\u0430\u0441\u0441 <code>Item<\/code> \u043d\u0430\u043c \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0434\u0430\u0451\u0442, \u043d\u043e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u043e\u0439 \u0434\u043b\u044f \u0434\u0440\u0443\u0433\u0438\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u044f \u043f\u0440\u0438\u0432\u0435\u0434\u0443 \u0435\u0449\u0451 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043a\u043b\u0430\u0441\u0441\u043e\u0432, \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445\u0441\u044f \u043e\u0442 <code>Item<\/code>.<\/p>\n<pre><code class=\"javascript\">class Weapon extends Item {   constructor(name, damage, effect) {     super(name);     this.damage = damage;     this.effect = effect;   }   get_damage() {     return this.damage;   }   get_effect() {     return this.effect;   } }<\/code><\/pre>\n<p>\u041a\u043b\u0430\u0441\u0441 <code>Weapon<\/code> \u0438\u043c\u0435\u0435\u0442 \u0434\u0432\u0430 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0432 \u0434\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043a \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u043c <code>Item<\/code>. \u042d\u0442\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 damage \u0438 effect.<\/p>\n<pre><code class=\"javascript\">class Shield extends Item {   constructor(name, armor) {     super(name);     this.armor = armor;   }   get_shield() {     return this.armor;   } }<\/code><\/pre>\n<p>\u0429\u0438\u0442, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0443\u0440\u043e\u043d\u0430 \u043c\u0438\u043c\u043e \u043f\u043e\u043b\u043e\u0441\u044b \u0437\u0434\u043e\u0440\u043e\u0432\u044c\u044f<\/p>\n<pre><code class=\"javascript\">class Potion extends Item {   constructor(name, effect) {     super(name);     this.effect = effect;   }   get_effect() {     return this.effect;   } } \/\/ \u0417\u0435\u043b\u044c\u0435 \u043b\u0435\u0447\u0435\u043d\u0438\u044f \u0437\u0430 \u043e\u0434\u0438\u043d \u0445\u043e\u0434, \u043a\u0430\u043a \u043f\u0440\u0438\u043c\u0435\u0440 class HealPotion extends Potion {   constructor(name, heal_count) {     super(name, new RegenerationEffect(name, 1, heal_count));   } } class RegeneratonPotion extends Potion {   constructor(name, steps, heal_count) {     super(name, new RegenerationEffect(name, steps, heal_count));   } }<\/code><\/pre>\n<p>\u0410 \u0442\u0430\u043a\u0436\u0435 \u0442\u043e\u043d\u043d\u044b \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0432\u0438\u0434\u043e\u0432 \u0437\u0435\u043b\u0438\u0439, \u043d\u0430\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u044e\u0449\u0438\u0445 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u044b \u043d\u0430 \u043f\u0435\u0440\u0441\u043e\u043d\u0430\u0436\u0430 \u043f\u0440\u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0438.<\/p>\n<h2>\u041a\u043b\u0430\u0441\u0441 Inventory<\/h2>\n<p>\u041f\u0440\u043e\u0441\u0442\u043e\u0439 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0434\u043b\u044f \u043c\u0430\u0441\u0441\u0438\u0432\u0430, \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u044e\u0449\u0438\u0439 \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0439 \u0442\u0438\u043f \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0440\u0430\u0437\u043c\u0435\u0440.<\/p>\n<pre><code class=\"javascript\">class Inventory {   \/\/ \u0418\u043d\u0432\u0435\u043d\u0442\u0430\u0440\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043c\u0435\u0441\u0442\u043e, \u0433\u0434\u0435 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0432\u0441\u0435 \u043f\u0440\u0435\u0434\u043c\u0435\u0442\u044b   container;   container_size = 16;      constructor(container_size = 16) {     this.container_size = container_size;     this.container = Array();   }   set_item(idx, item) {     \/**      * idx - \u0447\u0438\u0441\u043b\u043e      * item - \u043e\u0431\u044a\u0435\u043a\u0442 \u043e\u0442 \u043a\u043b\u0430\u0441\u0441\u0430 Item     *\/     if ( !(item instanceof Item)) {       throw new Error(\"item isn't instance of Item\");     }     if (idx &lt; 0 || idx > this.container_size) {       throw new Error(\"idx out of bounds\");     }     this.container[idx] = item;   }   get_item(idx) {     \/**       * idx - \u0447\u0438\u0441\u043b\u043e     *\/     if (idx &lt; 0 || idx > this.container_size) {       throw new Error(\"idx out of bounds\");     }     return container[idx];   } }<\/code><\/pre>\n<h2>\u041a\u043b\u0430\u0441\u0441 Entity<\/h2>\n<p>\u042d\u0442\u043e\u0442 \u043a\u043b\u0430\u0441\u0441 \u043d\u0430\u0432\u0435\u0440\u043d\u043e\u0435 \u0432\u0442\u043e\u0440\u043e\u0439 \u043f\u043e \u0432\u0430\u0436\u043d\u043e\u0441\u0442\u0438 \u043a\u043b\u0430\u0441\u0441. \u041e\u043d \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u0432\u0441\u0435\u0445 \u043c\u043e\u0431\u043e\u0432 \u0438 \u0438\u0433\u0440\u043e\u043a\u0430, \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c.<br \/>\u0423 \u043d\u0435\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u043d\u0435 \u043e\u0441\u043e\u0431\u043e \u043c\u043d\u043e\u0433\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432, \u043d\u043e \u043e\u043d\u0438 \u0431\u0443\u0434\u0443\u0442 \u0443\u043c\u0435\u0441\u0442\u043d\u044b\u043c\u0438<\/p>\n<p>&#8212; \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0437\u0434\u043e\u0440\u043e\u0432\u044c\u0435 <code>max_health<\/code><br \/>&#8212; \u0442\u0435\u043a\u0443\u0449\u0435\u0435 \u0437\u0434\u043e\u0440\u043e\u0432\u044c\u0435 <code>health<\/code><br \/>&#8212; \u0429\u0438\u0442 <code>shield<\/code><br \/>&#8212; \u0438\u043d\u0432\u0435\u043d\u0442\u0430\u0440\u044c \u043e\u0442 <code>Inventory<\/code> <code>inventory<\/code><br \/>&#8212; \u044d\u0444\u0444\u0435\u043a\u0442\u044b <code>effects<\/code><br \/>&#8212; \u043e\u0447\u043a\u0438 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 <code>steps<\/code><br \/>&#8212; \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c \u043e\u0447\u043a\u043e\u0432 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 <code>max_steps<\/code><\/p>\n<pre><code class=\"javascript\">class Entity {   max_health;   health;   shield = 0;   inventory = new Inventory(16);   effects = Array();   steps;   max_steps;   weapon_idx = -1;   constructor(max_health = 100, max_steps = 3) {     this.max_health = max_health;     this.health = max_health;     this.steps = max_steps;     this.max_steps = max_steps;   }      gain_damage(damage, effect) {     if (effect !== null) {       this.effects.push(effect);     }     let dmg = damage;     \/\/ \u041e\u0411\u0420\u0410\u0411\u041e\u0422\u041a\u0410 \u0421\u041e\u041f\u0420\u041e\u0422\u0418\u0412\u041b\u0415\u041d\u0418\u0419     for (const effect in this.effects) {         if (effect.get_resistance !== null) {           dmg *= (1 - effect.get_resistance());         }       }     let dmg_left = dmg - this.shield;     if (dmg_left >= 0) {       this.health = health - dmg_left;       this.reset_shield();     }     else {       this.shield -= damage;     }      if (this.health &lt; 0) this.health = 0;   }   setup_shield(shield_count, effect) {     if (effect !== null) {       this.effects.push(effect);     }     let def = shield_count;      \/\/ \u041e\u0411\u0420\u0410\u0411\u041e\u0422\u041a\u0410 \u0418\u041d\u041a\u0420\u0415\u041c\u0415\u041d\u0422\u041e\u0412 \u0432 \u043f\u0435\u0440\u0432\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c     this.effects.forEach((effect) => {       if (effect.get_def_incrementation !== null) {         def += effect.get_def_incrementation();       }     });     \/\/ \u041e\u0411\u0420\u0410\u0411\u041e\u0422\u041a\u0410 \u041c\u041d\u041e\u0416\u0418\u0422\u0415\u041b\u0415\u0419 \u0434\u0430\u043b\u0435\u0435     this.effects.forEach((effect) => {       if (effect.get_def_multiplier !== null) {         def *= effect.get_def_multiplier();       }     })          this.shield += def;   }   reset_shield() {     this.shield = 0;   }   heal(heal_count, effect) {     if (effect !== null) {       this.effects.push(effect);     }     if (this.health &lt; this.max_health) {       this.health += heal_count;     }     if (this.health > this.max_health) this.health = this.max_health;        }      deal_damage(target, weapon) {     if (weapon instanceof Weapon) {       let dmg = weapon.get_damage();       \/\/ \u041e\u0411\u0420\u0410\u0411\u041e\u0422\u041a\u0410 \u0418\u041d\u041a\u0420\u0415\u041c\u0415\u041d\u0422\u041e\u0412 \u0432 \u043f\u0435\u0440\u0432\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c       this.effects.forEach((effect) => {         if (effect.get_dmg_incrementation !== null) {           dmg += effect.get_dmg_incrementation();         }       });       \/\/ \u041e\u0411\u0420\u0410\u0411\u041e\u0422\u041a\u0410 \u041c\u041d\u041e\u0416\u0418\u0422\u0415\u041b\u0415\u0419 \u0434\u0430\u043b\u0435\u0435       this.effects.forEach((effect) => {         if (effect.get_dmg_multiplier !== null) {           dmg *= effect.get_dmg_multiplier();         }       })       target.gain_damage(dmg, weapon.get_effect());     }   }   is_alive() {     return this.health > 0;   }   step() {     \/** \u0441\u0447\u0438\u0442\u0430\u0442\u044c \u043f\u043e\u0441\u043b\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u0430\u0442\u0430\u043a\u0438\/\u0437\u0430\u0449\u0438\u0442\u044b\/\u043b\u0435\u0447\u0435\u043d\u0438\u044f.       *     *\/     for (let i = 0; i &lt; this.effects.length; i++) {       const effect = this.effects[i];       if (effect.get_damage !== null) {         this.gain_damage(effect.get_damage(), null);       }       if (effect.get_heal_count !== null) {         this.heal(effect.get_heal_count(), null);       }       if (effect.get_armor !== null) {         this.heal(effect.get_armor(), null);       }       effect.count();       if (effect.get_steps_left() &lt;= 0) {         this.effects[i] = null;       }     }     this.effects = this.effects.filter((elem) => {return elem != null;});     \/\/ \u0417\u0434\u0435\u0441\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0430 \u0441\u0442\u0440\u0435\u043b\u043e\u0447\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438 \u043f\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c \u0431\u0435\u0437 null   }   get_weapon() {     if (this.weapon_idx >= 0) return this.inventory.get_item(this.weapon_idx);     else return null;   } }<\/code><\/pre>\n<p>\u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u0447\u0442\u043e \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438 \u0438\u0437\u043b\u0438\u0448\u043d\u0438, \u043d\u043e \u0435\u0441\u043b\u0438 \u043a\u0430\u043a\u0438\u0435-\u0442\u043e \u043c\u043e\u043c\u0435\u043d\u0442 \u043d\u0435 \u043f\u043e\u043d\u044f\u0442\u043d\u044b, \u043d\u0435 \u0441\u0442\u0435\u0441\u043d\u044f\u0439\u0442\u0435\u0441\u044c, \u0434\u043e\u0440\u043e\u0433\u0438\u0435 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u0438, \u0443\u0442\u043e\u0447\u043d\u044f\u0442\u044c \u043d\u0435\u043f\u043e\u043d\u044f\u0442\u043d\u044b\u0435 \u0438\u043b\u0438 \u043d\u0435\u0432\u0435\u0440\u043d\u044b\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445.<\/p>\n<h2>\u041a\u043b\u0430\u0441\u0441 Game<\/h2>\n<p>\u0421\u0430\u043c\u044b\u0439 \u0433\u043b\u0430\u0432\u043d\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435. \u041e\u043d \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u0438\u0433\u0440\u043e\u0432\u043e\u0439 \u0446\u0438\u043a\u043b, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e \u0441\u043e\u0431\u044b\u0442\u0438\u0439. \u0412\u043e\u0442 \u0447\u0442\u043e \u043e\u043d \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c:<\/p>\n<p>&#8212; \u041d\u043e\u043c\u0435\u0440 <code>Entity<\/code>, \u0441\u0435\u0439\u0447\u0430\u0441 \u0445\u043e\u0434\u044f\u0449\u0435\u0433\u043e, <code>step_idx<\/code><br \/>&#8212; \u043c\u0430\u0441\u0441\u0438\u0432 \u0438\u0437 <code>Entity<\/code>, <code>entities<\/code><br \/>&#8212; \u041d\u043e\u043c\u0435\u0440 \u0438\u0433\u0440\u043e\u043a\u0430 <code>player_idx<\/code><br \/>&#8212; \u0421\u043f\u0438\u0441\u043e\u043a \u0441\u043e\u044e\u0437\u043d\u0438\u043a\u043e\u0432 <code>ally_idxes<\/code><br \/>&#8212; \u0421\u043f\u0438\u0441\u043e\u043a \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u0438\u043a\u043e\u0432 <code>enemy_idxes<\/code><br \/>&#8212; \u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e <code>Entity<\/code>, <code>entities_count<\/code><\/p>\n<pre><code class=\"javascript\">class Game {   entities = Array();   step_idx = -1;   player_idx = -1;   entities_count = 0;   ally_idxes = Array();   enemy_idxes = Array();      constructor(allies_count, enemies_count) {     this.entities_count = allies_count + enemies_count;     this.step_idx = 0;     this.player_idx = 0;          for (let i = 0; i &lt; this.entities_count; i++) {       if (i &lt; allies_count) {         \/\/ \u0421\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u043f\u0438\u0441\u043a\u0438 \u0441\u043e\u044e\u0437\u043d\u0438\u043a\u043e\u0432         ally_idxes[ally_idxes.length] = i;       }       else if (i > allies_count &amp;&amp; i &lt; allies_count + enemies_count) {         \/\/ ... \u0438 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u0438\u043a\u043e\u0432         enemy_idxes[enemy_idxes.length] = i;       }     }   }   step(action) {     const entity = this.entities[step_idx];      if (action == 0) {       entity.dealDamage(target, entity.get_weapon());     }     else if (action == 1) {       entity.     }          entity.step();          this.step_count(entity);   }   step_count(entity) {     entity.steps -= 1;     if (entity.steps &lt;= 0) {       entity.steps = entity.max_steps;       this.step_idx += 1;       if (this.step_idx >= this.entities_count) this.step_idx = 0;     }   } }<\/code><\/pre>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>\u0421\u0435\u0433\u043e\u0434\u043d\u044f \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043b, \u0442\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0439 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a, \u0435\u0441\u043b\u0438 \u043d\u0435 \u0438\u0433\u0440\u043e\u0432\u043e\u0439 \u0434\u0432\u0438\u0436\u043e\u043a \u043d\u0430 JavaScript.<\/p>\n<h4>P. S.<\/h4>\n<p>\u041c\u043d\u0435 \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0441\u0438\u043b\u044c\u043d\u043e \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0432\u044b\u0441\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u0440\u0435\u0448\u0438\u043b \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u044d\u0442\u0443 \u0441\u0442\u0430\u0442\u044c\u044e.<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/694390\/\"> https:\/\/habr.com\/ru\/post\/694390\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-339976","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/339976","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=339976"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/339976\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=339976"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=339976"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=339976"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}