const $ = require('jquery');
const Board = require('./board');
const Panel = require('./panel');

class Stage {
	constructor($stage, config) {
		this.$stage = $stage;
		this.config = config;
		this.caseIndex = 0;
		this.board = new Board(this);
		this.panel = new Panel(this);

		this.$selectedBlock = this.$stage.find('.panel .block[selected]').first();

		this.$stage.find('.board .block').click((event) => {
			const $block = $(event.target);
			const type = this.$selectedBlock.data('type');
			$block.attr('data-type', type);
			this.panel.takeAndPlace($block.data('x'), $block.data('y'), type);
		});

		this.$stage.find('.execute').click((event) => {
			this.executeCase();
		});

		this.$stage.find('.inputs').empty().append(config.input.map((input) => $('<div/>', {
			'class': 'input',
			text: input,
		})));

		this.$stage.find('.user-outputs').empty().append(config.output.map(() => $('<div/>', {
			'class': 'output',
		})));

		this.$stage.find('.correct-outputs').empty().append(config.output.map((output) => $('<div/>', {
			'class': 'output',
			text: output,
		})));
	}

	executeCase() {
		this.board.input(this.config.input[this.caseIndex]);
	}

	output(value) {
		this.$stage.find('.user-outputs .output').eq(this.caseIndex).text(value);
	}
}

module.exports = Stage;

@@ -651,16 +651,93 @@
 t) =%3E %7B%0A
+%09%09%09this.caseIndex = 0;%0A%09%09%09this.$stage.find('.user-outputs .output').empty();%0A
 %09%09%09this.
@@ -1328,16 +1328,215 @@
 (value);
+%0A%0A%09%09if (this.config.output%5Bthis.caseIndex%5D === value) %7B%0A%09%09%09if (this.config.output.length === this.caseIndex + 1) %7B%0A%09%09%09%09// %E7%B5%82%E4%BA%86%E5%87%A6%E7%90%86%E3%82%92%E3%81%93%E3%81%93%E3%81%AB%E6%9B%B8%E3%81%8F%0A%09%09%09%7D else %7B%0A%09%09%09%09this.caseIndex++;%0A%09%09%09%09this.executeCase();%0A%09%09%09%7D%0A%09%09%7D
 %0A%09%7D%0A%7D%0A%0Am

Make comparison of result and next tick