1
0
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:
Shikiryu 2015-01-29 00:25:36 +01:00
commit f932a372d7
3 changed files with 65 additions and 31 deletions

View File

@ -1,5 +1,4 @@
var SIZE = 30; var SIZE = 30;
var NUMCASE = 10;
var GRID = [ var GRID = [
['S','S','S','A','U','B','A','G','N','E'], ['S','S','S','A','U','B','A','G','N','E'],
['E','P','A','A','M','V','E','N','C','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'], ['C','A','S','S','U','J','E','R','F','L'],
['E','B','E','L','S','I','S','S','A','C'] ['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 words = ['AIX','APT','ARLES','AUBAGNE','AUPS','AVIGNON','BANDOL','CANNES','CASSIS','DIGNE','FREJUS','HYERES','LUNEL','MIRAMAS','NICE','ORANGE','SALON','SORGUES','TOULON','VENCE'];
var reponse = 'BA';

View File

@ -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 canvas = new fabric.Canvas('c', { selection: false });
var i; var i;
var j; var j;
@ -8,7 +8,7 @@
var end = []; var end = [];
var isDragging = false; var isDragging = false;
var drawingLine; var drawingLine;
canvas.setDimensions({width: SIZE*NUMCASE + NUMCASE, height: SIZE*NUMCASE + NUMCASE});
var LabeledRect = fabric.util.createClass(fabric.Rect, { var LabeledRect = fabric.util.createClass(fabric.Rect, {
type: 'labeledRect', type: 'labeledRect',
initialize: function(options) { 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 // init grid
for (i = 0; i < NUMCASE; i++) { var init = function init() {
for (j = 0; j < NUMCASE; j++) { 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({ var rect = new LabeledRect({
left: i*SIZE, left: i * SIZE,
top: j*SIZE, top: j * SIZE,
fill: 'white', fill: 'white',
stroke: 'black', stroke: 'black',
width: SIZE, width: SIZE,
@ -92,13 +117,22 @@
canvas.add(rect); canvas.add(rect);
} }
} }
// init words
// TODO eurk words.forEach(
for(var uno = 0; uno < words.length; uno++) { function(value, index){
var tmpLi = document.createElement('li'); tmpLi = document.createElement('li');
tmpLi.innerHTML = words[uno].toUpperCase(); tmpLi.innerHTML = value.toUpperCase();
document.getElementById('words').appendChild(tmpLi); ulContent.appendChild(tmpLi);
} }
);
document.getElementById('words').appendChild(ulContent);
} else {
throw new Error('invalid grid');
}
};
canvas.on('mouse:down', function(options) { canvas.on('mouse:down', function(options) {
isDragging = true; isDragging = true;
@ -158,4 +192,8 @@
var nextStep = function nextStep() { var nextStep = function nextStep() {
// TODO calling callback // TODO calling callback
}; };
})(fabric, document, SIZE, NUMCASE, GRID, reponse, words);
// let's call our game
init();
})(fabric, SIZE, GRID, words);