Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 29 additions & 32 deletions src/TaskQueue.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,33 @@
const TaskQueue = function() {
function TaskQueue() {
function runNextTask(taskQueue) {
if (taskQueue.running || taskQueue.tasks.length === 0) {
return;
}
taskQueue.running = true;
const task = taskQueue.tasks.shift();

if (task.runAndContinue) {
setTimeout(() => {
task.runAndContinue(() => {
task.dispose && task.dispose();
taskQueue.running = false;

setTimeout(() => {
runNextTask(taskQueue);
});
});
}, 0);
}
else {
runNextTask(taskQueue);
}
}

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 {
Expand All @@ -21,35 +44,9 @@ const TaskQueue = function() {
runNextTask(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();

if (task.runAndContinue) {
setTimeout(() => {
task.runAndContinue(() => {
task.dispose && task.dispose();
taskQueue.running = false;

setTimeout(() => {
runNextTask(taskQueue);
});
});
}, 0);
}
else {
runNextTask(taskQueue);
}
}

return TaskQueue;
}();
}

export default TaskQueue;
92 changes: 74 additions & 18 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,72 @@ import Game from './Game.js';
import TaskQueue from './TaskQueue.js';
import SpeedRate from './SpeedRate.js';

class Creature extends Card{
getDescriptions(){
let str1 = super.getDescriptions();
let str2 = getCreatureDescription(this);
return[str1, str2];
}

}

class Duck extends Creature{
constructor(name = "Мирная утка", maxPower = 2){
super(name, maxPower)
}
quacks() { console.log('quack') };
swims() { console.log('float: both;') };
}

class BigDuck extends Duck{
constructor(name = "Большая утка", maxPower = 4){
super(name, maxPower)
}
}

class Dog extends Creature{
constructor(name = "Пес-бандит", maxPower = 3){
super(name, maxPower)
}
}

class Trasher extends Dog{
constructor(name = "Громила", maxPower = 4){
super(name, maxPower)
}
modifyDealedDamageToCreature (value, toCard, gameContext, continuation) {
this.view.signalAbility(() => {continuation(value - 1)});
};
getDescriptions() {
return ['Входящий урон уменьшен на 1',
super.getDescription(),

];
};
}

class Gatling extends Creature{
constructor(name = "Гатлинг", maxPower = 6){
super(name, maxPower)
}
attack(gameContext, continuation) {
const taskQueue = new TaskQueue();

const {currentPlayer, oppositePlayer, position, updateView} = gameContext;
for(let i = 0; i<oppositePlayer.table.length; i++){
const element = oppositePlayer[i];
taskQueue.push(onDone => this.view.showAttack(onDone));
taskQueue.push(onDone => {

if (element) {
this.dealDamageToCreature(2, element, gameContext, onDone);
}
});
}
taskQueue.continueWith(continuation);
};
}

// Отвечает является ли карта уткой.
function isDuck(card) {
return card && card.quacks && card.swims;
Expand All @@ -27,30 +93,20 @@ function getCreatureDescription(card) {
return 'Существо';
}



// Основа для утки.
function Duck() {
this.quacks = function () { console.log('quack') };
this.swims = function () { console.log('float: both;') };
}


// Основа для собаки.
function Dog() {
}


// Колода Шерифа, нижнего игрока.
const seriffStartDeck = [
new Card('Мирный житель', 2),
new Card('Мирный житель', 2),
new Card('Мирный житель', 2),
new Duck(),
new Duck(),
new Gatling(),
new BigDuck(),
];

// Колода Бандита, верхнего игрока.
const banditStartDeck = [
new Card('Бандит', 3),
new Trasher(),
new Dog(),
new Dog(),
new Dog(),
];


Expand Down