diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..b58b603
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,5 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
diff --git a/.idea/4-west.iml b/.idea/4-west.iml
new file mode 100644
index 0000000..0c8867d
--- /dev/null
+++ b/.idea/4-west.iml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..6b35bfd
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..94a25f7
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/TaskQueue.js b/src/TaskQueue.js
index f3a9c6a..090cca1 100644
--- a/src/TaskQueue.js
+++ b/src/TaskQueue.js
@@ -1,10 +1,9 @@
-const TaskQueue = function() {
- function TaskQueue() {
+export default class TaskQueue {
+ constructor() {
this.tasks = [];
- this.running = false;
}
- TaskQueue.prototype.push = function(run, dispose, duration) {
+ push(run, dispose, duration) {
if (duration === undefined || duration === null) {
this.tasks.push({runAndContinue: run, dispose});
} else {
@@ -18,38 +17,36 @@ const TaskQueue = function() {
dispose
});
}
- runNextTask(this);
+ nextTask(this);
};
- TaskQueue.prototype.continueWith = function(action) {
+ continueWith(action) {
this.push(action, null, 0);
};
+};
- function runNextTask(taskQueue) {
- if (taskQueue.running || taskQueue.tasks.length === 0) {
- return;
- }
- taskQueue.running = true;
- const task = taskQueue.tasks.shift();
+function nextTask(taskQueue) {
+ if (taskQueue.running || taskQueue.tasks.length === 0) {
+ return;
+ }
+ taskQueue.running = true;
+ const currentTask = taskQueue.tasks.shift();
- if (task.runAndContinue) {
- setTimeout(() => {
- task.runAndContinue(() => {
- task.dispose && task.dispose();
- taskQueue.running = false;
+ if (currentTask.runAndContinue) {
+ setTimeout(() => {
+ currentTask.runAndContinue(() => {
+ currentTask.dispose && currentTask.dispose();
+ taskQueue.running = false;
- setTimeout(() => {
- runNextTask(taskQueue);
- });
+ setTimeout(() => {
+ nextTask(taskQueue);
});
- }, 0);
- }
- else {
- runNextTask(taskQueue);
- }
+ });
+ }, 0);
}
+ else {
+ nextTask(taskQueue);
+ }
+}
- return TaskQueue;
-}();
-
-export default TaskQueue;
+nextTask(new TaskQueue());
\ No newline at end of file
diff --git a/src/index.js b/src/index.js
index a01f912..0ef59a4 100644
--- a/src/index.js
+++ b/src/index.js
@@ -1,18 +1,16 @@
import Card from './Card.js';
import Game from './Game.js';
-import TaskQueue from './TaskQueue.js';
+//import TaskQueue from './TaskQueue.js';
import SpeedRate from './SpeedRate.js';
// Отвечает является ли карта уткой.
function isDuck(card) {
return card && card.quacks && card.swims;
}
-
// Отвечает является ли карта собакой.
function isDog(card) {
return card instanceof Dog;
}
-
// Дает описание существа по схожести с утками и собаками
function getCreatureDescription(card) {
if (isDuck(card) && isDog(card)) {
@@ -27,40 +25,202 @@ function getCreatureDescription(card) {
return 'Существо';
}
+class Creature extends Card {
+ constructor(name, maxPower) {
+ super(name, maxPower);
+ }
+
+ // setCurrentPower(value) {
+ // this.currentPower = Math.min(this.maxPower, this.currentPower + value);
+ // }
+
+ getDescriptions() {
+ return [getCreatureDescription(this), ...super.getDescriptions()]
+ }
+}
+
+class Duck extends Creature {
+ constructor(name, power) {
+ super(name ?? "Мирная утка", power ?? 2);
+ }
+
+ quacks() {
+ console.log('quack')
+ };
+
+ swims() {
+ console.log('float: both;')
+ };
+}
+
+class Dog extends Creature {
+ constructor(name, power) {
+ super(name ?? "Пес-бандит", power ?? 3);
+ }
+}
+
+class Trasher extends Dog {
+ constructor(name, power) {
+ super(name ?? "Громила", power ?? 5);
+ }
+
+ modifyTakenDamage(value, fromCard, gameContext, continuation) {
+ this.view.signalAbility(() => continuation(value - 1));
+ }
+
+ getDescriptions() {
+ let descriptions = [];
+ if (Trasher.prototype.hasOwnProperty('modifyTakenDamage')) {
+ descriptions = ["Урон меньше на 1"];
+ }
+ return descriptions.concat([...super.getDescriptions()]);
+ }
+}
+
+class Gatling extends Creature {
+ constructor(name, power) {
+ super(name ?? "Гатлинг", power ?? 6);
+ }
+
+ // attack(gameContext, continuation) {
+ // let taskQueue = new TaskQueue();
+ // let oppositePlayer = gameContext.oppositePlayer;
+ // for (let card of oppositePlayer.table) {
+ // taskQueue.push((attack) => this.view.showAttack(attack));
+ // taskQueue.push((onDone) => this.dealDamageToCreature(2, card, gameContext, onDone));
+ // }
+ // taskQueue.continueWith(continuation);
+ // game.updateView();
+ // };
+}
+
+class Lad extends Dog {
+ constructor(name, power) {
+ super(name ?? "Браток", power ?? 2);
+ }
+
+ static getInGameCount() {
+ return this.inGameCount || 0;
+ }
+
+ // static setInGameCount(value) {
+ // this.inGameCount = value;
+ // }
+
+ static getBonus() {
+ return this.getInGameCount() * (this.getInGameCount() + 1) / 2;
+ }
+
+ // doAfterComingIntoPlay(gameContext, continuation) {
+ // Lad.setInGameCount(Lad.getInGameCount() + 1);
+ // continuation();
+ // }
+ //
+ // doBeforeRemoving(continuation) {
+ // Lad.setInGameCount(Lad.getInGameCount() - 1);
+ // continuation();
+ // };
+
+ modifyTakenDamage(value, fromCard, gameContext, continuation) {
+ this.view.signalAbility(() => continuation(value - Lad.getBonus()));
+ }
+
+ modifyDealedDamageToCreature(value, toCard, gameContext, continuation) {
+ continuation(value + Lad.getBonus());
+ }
+
+ getDescriptions() {
+ let descriptions = super.getDescriptions();
+ if (Lad.prototype.hasOwnProperty("modifyDealedDamageToCreature") && Lad.prototype.hasOwnProperty("modifyTakenDamage")) {
+ descriptions.push("Чем их больше, тем они сильнее");
+ }
+ return descriptions;
+ }
+}
+
+class Rogue extends Creature {
+ constructor(name, power) {
+ super(name ?? "Изгой", power ?? 2);
+ }
+ static stealer = ["modifyDealedDamageToCreature", "modifyDealedDamageToPlayer", "modifyTakenDamage"];
+
+ modifyTakenDamage(value, fromCard, gameContext, continuation) {
+ const prototype = Object.getPrototypeOf(fromCard);
+ for (const property of Rogue.stealer) {
+ if (prototype.hasOwnProperty(property)) {
+ this[property] = prototype[property];
+ delete prototype[property];
+ }
+ }
+
+ gameContext.updateView();
+ super.modifyTakenDamage(value, fromCard, gameContext, continuation);
+ }
-// Основа для утки.
-function Duck() {
- this.quacks = function () { console.log('quack') };
- this.swims = function () { console.log('float: both;') };
+ getDescriptions() {
+ let descriptions = ["Ворует способности врагов"];
+ return descriptions.concat([...super.getDescriptions()]);
+ }
}
+class Brewer extends Duck {
+ constructor(name, power) {
+ super(name ?? "Пивовар", power ?? 2);
+ }
-// Основа для собаки.
-function Dog() {
+ // doBeforeAttack(gameContext, continuation) {
+ // let taskQueue = new TaskQueue();
+ // let {currentPlayer, oppositePlayer} = gameContext;
+ // let cards = currentPlayer.table.concat(oppositePlayer.table);
+ // for (let card of cards) {
+ // if (isDuck(card)) {
+ // card.maxPower += 1;
+ // card.setCurrentPower(2);
+ // taskQueue.push(onDone => card.view.signalHeal(onDone));
+ // card.updateView();
+ // }
+ // }
+ // taskQueue.continueWith(continuation);
+ // }
}
+class PseudoDuck extends Dog {
+ constructor(name, power) {
+ super(name ?? "Псевдоутка", power ?? 3);
+ }
-// Колода Шерифа, нижнего игрока.
-const seriffStartDeck = [
- new Card('Мирный житель', 2),
- new Card('Мирный житель', 2),
- new Card('Мирный житель', 2),
-];
+ quacks() {console.log('quack')};
+ swims() {console.log('float: both;')};
+}
-// Колода Бандита, верхнего игрока.
-const banditStartDeck = [
- new Card('Бандит', 3),
-];
+class Nemo extends Creature {
+ constructor(name, power) {
+ super(name ?? "Немо", power ?? 4);
+ }
+ // doBeforeAttack(gameContext, continuation) {
+ // let taskQueue = new TaskQueue();
+ // let {oppositePlayer, position} = gameContext;
+ // let oppositeCard = oppositePlayer.table[position];
+ //
+ // if (oppositeCard) {
+ // Object.setPrototypeOf(this, Object.getPrototypeOf(oppositeCard));
+ // gameContext.updateView();
+ // }
+ // taskQueue.continueWith(continuation);
+ // }
+}
// Создание игры.
+const seriffStartDeck = [new Duck(), new Duck(), new Gatling(), new Nemo()];
+const banditStartDeck = [new Trasher(), new Brewer(), new Lad(), new PseudoDuck()];
const game = new Game(seriffStartDeck, banditStartDeck);
// Глобальный объект, позволяющий управлять скоростью всех анимаций.
-SpeedRate.set(1);
+SpeedRate.set(2);
// Запуск игры.
game.play(false, (winner) => {
alert('Победил ' + winner.name);
-});
+});
\ No newline at end of file