mirror of
https://github.com/Chouchen/motsmeles.git
synced 2018-06-07 06:04:38 +02:00
merge avec branche précédente
This commit is contained in:
commit
f932a372d7
@ -1,5 +1,4 @@
|
||||
var SIZE = 30;
|
||||
var NUMCASE = 10;
|
||||
var GRID = [
|
||||
['S','S','S','A','U','B','A','G','N','E'],
|
||||
['E','P','A','A','M','V','E','N','C','E'],
|
||||
@ -12,7 +11,4 @@ var GRID = [
|
||||
['C','A','S','S','U','J','E','R','F','L'],
|
||||
['E','B','E','L','S','I','S','S','A','C']
|
||||
];
|
||||
|
||||
var words = ['AIX','APT','ARLES','AUBAGNE','AUPS','AVIGNON','BANDOL','CANNES','CASSIS','DIGNE','FREJUS','HYERES','LUNEL','MIRAMAS','NICE','ORANGE','SALON','SORGUES','TOULON','VENCE'];
|
||||
|
||||
var reponse = 'BA';
|
@ -1,4 +1,4 @@
|
||||
(function(fabric, document, SIZE, NUMCASE, GRID, reponse, words){
|
||||
(function(fabric, SIZE, GRID, words){
|
||||
var canvas = new fabric.Canvas('c', { selection: false });
|
||||
var i;
|
||||
var j;
|
||||
@ -8,7 +8,7 @@
|
||||
var end = [];
|
||||
var isDragging = false;
|
||||
var drawingLine;
|
||||
canvas.setDimensions({width: SIZE*NUMCASE + NUMCASE, height: SIZE*NUMCASE + NUMCASE});
|
||||
|
||||
var LabeledRect = fabric.util.createClass(fabric.Rect, {
|
||||
type: 'labeledRect',
|
||||
initialize: function(options) {
|
||||
@ -76,12 +76,37 @@
|
||||
}
|
||||
};
|
||||
|
||||
var validateGrid = function validateGrid() {
|
||||
var i = 1;
|
||||
var l = GRID.length;
|
||||
var supposed;
|
||||
if(l !== 0 && GRID[0]) {
|
||||
supposed = GRID[0].length;
|
||||
for(;i<l;i++) {
|
||||
if(GRID[i].length !== supposed){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
// init grid
|
||||
for (i = 0; i < NUMCASE; i++) {
|
||||
for (j = 0; j < NUMCASE; j++) {
|
||||
var init = function init() {
|
||||
if(validateGrid()) {
|
||||
var numHeight = GRID.length;
|
||||
var numWidth = GRID[0].length;
|
||||
var ulContent = document.createDocumentFragment();
|
||||
var tmpLi;
|
||||
|
||||
canvas.setDimensions({width: SIZE*numWidth + numWidth, height: SIZE*numHeight + numHeight});
|
||||
|
||||
for (i = 0; i < numWidth; i++) {
|
||||
for (j = 0; j < numHeight; j++) {
|
||||
var rect = new LabeledRect({
|
||||
left: i*SIZE,
|
||||
top: j*SIZE,
|
||||
left: i * SIZE,
|
||||
top: j * SIZE,
|
||||
fill: 'white',
|
||||
stroke: 'black',
|
||||
width: SIZE,
|
||||
@ -92,13 +117,22 @@
|
||||
canvas.add(rect);
|
||||
}
|
||||
}
|
||||
// init words
|
||||
// TODO eurk
|
||||
for(var uno = 0; uno < words.length; uno++) {
|
||||
var tmpLi = document.createElement('li');
|
||||
tmpLi.innerHTML = words[uno].toUpperCase();
|
||||
document.getElementById('words').appendChild(tmpLi);
|
||||
|
||||
words.forEach(
|
||||
function(value, index){
|
||||
tmpLi = document.createElement('li');
|
||||
tmpLi.innerHTML = value.toUpperCase();
|
||||
ulContent.appendChild(tmpLi);
|
||||
}
|
||||
);
|
||||
|
||||
document.getElementById('words').appendChild(ulContent);
|
||||
|
||||
} else {
|
||||
throw new Error('invalid grid');
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
canvas.on('mouse:down', function(options) {
|
||||
isDragging = true;
|
||||
@ -158,4 +192,8 @@
|
||||
var nextStep = function nextStep() {
|
||||
// TODO calling callback
|
||||
};
|
||||
})(fabric, document, SIZE, NUMCASE, GRID, reponse, words);
|
||||
|
||||
// let's call our game
|
||||
init();
|
||||
|
||||
})(fabric, SIZE, GRID, words);
|
||||
|
Loading…
Reference in New Issue
Block a user