JSFiddle - React, Tailwind, and code Playground
by Konstantin Cryman
HTML
<div id="game"></div>
JavaScript
var Level = {};
Level.Model = function(x, y) {
var w = x ? x : 1,
h = y ? y : (x ? x : 1);
return new function() {
this.width = w;
this.height = h;
this.data = [];
this.places = [];
this.dim = 18,
this.cellMin = 2,
this.cellMax = 5;
// reset function
this.reset = function(w, v) {
this.width = w ? w : 1,
this.height = v ? v : (w ? w : 1);
this.data = [];
for (var i = 0; i < this.height; i++) {
var arr = [];
for (var n = 0; n < this.width; n++) {
arr[n] = {
content: 0,
object: {}
};
}
this.data[i] = arr;
}
return this;
};
// Call function
this.call = function(func) {
return func(this);
};
// В конце, чтоб всё сработало как надо.
this.reset(this.width, this.height);
// chain
return this;
};
};
Level.View = function(model) {
return new function() {
this.model = model;
this.width = this.model.width;
this.height = this.model.height;
this.data = [];
this.dim = this.model.dim;
// Element params
this.display = $('#game');
this.el = $('<div class="table"></div>');
// reset function
this.reset = function(w, v) {
this.data = [];
for (var i = 0; i < this.height; i++) {
var arr = [];
for (var n = 0; n < this.width; n++) {
arr[n] = '';
}
this.data[i] = arr;
}
return this;
};
// Рендерер
this.render = function() {
this.el.empty();
for (var i = 0; i < this.height; i++) {
//var tr =...