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
2
dist/js/motsmeles.min.js
vendored
2
dist/js/motsmeles.min.js
vendored
@ -1,2 +1,2 @@
|
|||||||
/*! motsmeles 2015-01-29 */
|
/*! motsmeles 2015-01-29 */
|
||||||
var SIZE=30,NUMCASE=10,GRID=[["S","S","S","A","U","B","A","G","N","E"],["E","P","A","A","M","V","E","N","C","E"],["L","U","L","M","I","R","A","M","A","S"],["R","A","O","G","E","X","A","C","O","E"],["A","L","N","E","G","N","A","R","O","R"],["T","O","U","L","O","N","G","L","R","E"],["N","D","S","T","N","U","E","I","E","Y"],["I","N","P","E","E","N","I","L","D","H"],["C","A","S","S","U","J","E","R","F","L"],["E","B","E","L","S","I","S","S","A","C"]],words=["AIX","APT","ARLES","AUBAGNE","AUPS","AVIGNON","BANDOL","CANNES","CASSIS","DIGNE","FREJUS","HYERES","LUNEL","MIRAMAS","NICE","ORANGE","SALON","SORGUES","TOULON","VENCE"],reponse="BA";!function(a,b,c,d,e,f,g){var h,i,j,k,l=new a.Canvas("c",{selection:!1}),m=[],n=[],o=!1;l.setDimensions({width:c*d+d,height:c*d+d});var p=a.util.createClass(a.Rect,{type:"labeledRect",initialize:function(a){a=a||{},this.callSuper("initialize",a),this.set("label",a.label||"")},toObject:function(){return a.util.object.extend(this.callSuper("toObject"),{label:this.get("label")})},_render:function(a){this.callSuper("_render",a),a.font="20px Helvetica",a.fillStyle="#333",a.fillText(this.label,-this.width/2+5,-this.height/2+20)}}),q=function(){var a,b,c,d=-1,f=m[0]===n[0],h=m[1]===n[1],i=Math.abs(m[0]-n[0])===Math.abs(m[1]-n[1]),j="";if(f){for(b=Math.min(m[1],n[1]),c=Math.max(m[1],n[1]),a=b;c>=a;a++)j+=e[m[0]][a];return Math.max(g.indexOf(j),g.indexOf(j.split("").reverse().join("")))}if(h){for(b=Math.min(m[0],n[0]),c=Math.max(m[0],n[0]),a=b;c>=a;a++)j+=e[a][m[1]];return Math.max(g.indexOf(j),g.indexOf(j.split("").reverse().join("")))}if(i){for(var k=m[0]-n[0]<0,l=m[1]-n[1]<0,o=0,p=Math.abs(m[0]-n[0]);p>=o;o++)j+=e[k?m[0]+o:m[0]-o][l?m[1]+o:m[1]-o];return Math.max(g.indexOf(j),g.indexOf(j.split("").reverse().join("")))}return d},r=function(a){var c=b.getElementById("words").getElementsByTagName("li"),d=c.length;for(j=0;d>j;j++)if(c[j].textContent===a){c[j].className="validate";break}};for(h=0;d>h;h++)for(i=0;d>i;i++){var s=new p({left:h*c,top:i*c,fill:"white",stroke:"black",width:c,height:c,label:e[i][h],selectable:!1});l.add(s)}for(var t=0;t<g.length;t++){var u=b.createElement("li");u.innerHTML=g[t].toUpperCase(),b.getElementById("words").appendChild(u)}l.on("mouse:down",function(b){o=!0;var d=l.getPointer(b.e),e=[d.x,d.y,d.x,d.y];m=[Math.floor(e[1]/c),Math.floor(e[0]/c)],k=new a.Line(e,{stroke:"black",strokeLineCap:"round",strokeWidth:c/6,strokeDashArray:[c/6,c/6],originX:"center",originY:"center"}),l.add(k)}),l.on("mouse:move",function(a){if(o){var b=l.getPointer(a.e);k.set({x2:b.x,y2:b.y}),l.renderAll()}}),l.on("mouse:up",function(b){o=!1;var d=l.getPointer(b.e),e=[d.x,d.y];if(n=[Math.floor(e[1]/c),Math.floor(e[0]/c)],l.remove(k),m[0]!==n[0]||m[1]!==n[1]){var f=q();if(-1!==f){var h=g[f];h=m.reverse().join("").concat(n.reverse().join("")).split(""),h=h.map(function(a){return a*c+c/2});var i=new a.Line(h,{stroke:"black",strokeLineCap:"round",strokeWidth:c/6,originX:"center",originY:"center",selectable:!1});r(g[f]),g.splice(f,1),l.add(i),0===g.length&&v()}}m=[],n=[]});var v=function(){}}(fabric,document,SIZE,NUMCASE,GRID,reponse,words);
|
var SIZE=30,NUMCASE=10,GRID=[["S","S","S","A","U","B","A","G","N","E"],["E","P","A","A","M","V","E","N","C","E"],["L","U","L","M","I","R","A","M","A","S"],["R","A","O","G","E","X","A","C","O","E"],["A","L","N","E","G","N","A","R","O","R"],["T","O","U","L","O","N","G","L","R","E"],["N","D","S","T","N","U","E","I","E","Y"],["I","N","P","E","E","N","I","L","D","H"],["C","A","S","S","U","J","E","R","F","L"],["E","B","E","L","S","I","S","S","A","C"]],words=["AIX","APT","ARLES","AUBAGNE","AUPS","AVIGNON","BANDOL","CANNES","CASSIS","DIGNE","FREJUS","HYERES","LUNEL","MIRAMAS","NICE","ORANGE","SALON","SORGUES","TOULON","VENCE"],reponse="BA";!function(a,b,c,d,e,f,g){var h,i,j,k,l=new a.Canvas("c",{selection:!1}),m=[],n=[],o=!1;l.setDimensions({width:c*d+d,height:c*d+d});var p=a.util.createClass(a.Rect,{type:"labeledRect",initialize:function(a){a=a||{},this.callSuper("initialize",a),this.set("label",a.label||"")},toObject:function(){return a.util.object.extend(this.callSuper("toObject"),{label:this.get("label")})},_render:function(a){this.callSuper("_render",a),a.font="20px Helvetica",a.fillStyle="#333",a.fillText(this.label,-this.width/2+5,-this.height/2+20)}}),q=function(){var a,b,c,d=-1,f=m[0]===n[0],h=m[1]===n[1],i=Math.abs(m[0]-n[0])===Math.abs(m[1]-n[1]),j="";if(f){for(b=Math.min(m[1],n[1]),c=Math.max(m[1],n[1]),a=b;c>=a;a++)j+=e[m[0]][a];return Math.max(g.indexOf(j),g.indexOf(j.split("").reverse().join("")))}if(h){for(b=Math.min(m[0],n[0]),c=Math.max(m[0],n[0]),a=b;c>=a;a++)j+=e[a][m[1]];return Math.max(g.indexOf(j),g.indexOf(j.split("").reverse().join("")))}if(i){for(var k=m[0]-n[0]<0,l=m[1]-n[1]<0,o=0,p=Math.abs(m[0]-n[0]);p>=o;o++)j+=e[k?m[0]+o:m[0]-o][l?m[1]+o:m[1]-o];return Math.max(g.indexOf(j),g.indexOf(j.split("").reverse().join("")))}return d},r=function(a){var c=b.getElementById("words").getElementsByTagName("li"),d=c.length;for(j=0;d>j;j++)if(c[j].textContent===a){c[j].className="validate";break}};for(h=0;d>h;h++)for(i=0;d>i;i++){var s=new p({left:h*c,top:i*c,fill:"white",stroke:"black",width:c,height:c,label:e[i][h],selectable:!1});l.add(s)}for(var t=0;t<g.length;t++){var u=b.createElement("li");u.innerHTML=g[t].toUpperCase(),b.getElementById("words").appendChild(u)}l.on("mouse:down",function(b){o=!0;var d=l.getPointer(b.e),e=[d.x,d.y,d.x,d.y];m=[Math.floor(e[1]/c),Math.floor(e[0]/c)],k=new a.Line(e,{stroke:"black",strokeLineCap:"round",strokeWidth:c/6,strokeDashArray:[c/6,c/6],originX:"center",originY:"center"}),l.add(k)}),l.on("mouse:move",function(a){if(o){var b=l.getPointer(a.e);k.set({x2:b.x,y2:b.y}),l.renderAll()}}),l.on("mouse:up",function(b){o=!1;var d=l.getPointer(b.e),e=[d.x,d.y];if(n=[Math.floor(e[1]/c),Math.floor(e[0]/c)],l.remove(k),m[0]!==n[0]||m[1]!==n[1]){var f=q();if(-1!==f){var h=g[f];h=m.reverse().join("").concat(n.reverse().join("")).split(""),h=h.map(function(a){return a*c+c/2});var i=new a.Line(h,{stroke:"black",strokeLineCap:"round",strokeWidth:c/6,originX:"center",originY:"center",selectable:!1});r(g[f]),g.splice(f,1),l.add(i),0===g.length&&v()}}m=[],n=[]});var v=function(){}}(fabric,document,SIZE,NUMCASE,GRID,reponse,words);
|
||||||
|
@ -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';
|
|
@ -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,29 +76,63 @@
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// init grid
|
var validateGrid = function validateGrid() {
|
||||||
for (i = 0; i < NUMCASE; i++) {
|
var i = 1;
|
||||||
for (j = 0; j < NUMCASE; j++) {
|
var l = GRID.length;
|
||||||
var rect = new LabeledRect({
|
var supposed;
|
||||||
left: i*SIZE,
|
if(l !== 0 && GRID[0]) {
|
||||||
top: j*SIZE,
|
supposed = GRID[0].length;
|
||||||
fill: 'white',
|
for(;i<l;i++) {
|
||||||
stroke: 'black',
|
if(GRID[i].length !== supposed){
|
||||||
width: SIZE,
|
return false;
|
||||||
height: SIZE,
|
}
|
||||||
label: GRID[j][i],
|
}
|
||||||
selectable: false
|
return true;
|
||||||
});
|
|
||||||
canvas.add(rect);
|
|
||||||
}
|
}
|
||||||
}
|
return false;
|
||||||
// init words
|
};
|
||||||
// TODO eurk
|
|
||||||
for(var uno = 0; uno < words.length; uno++) {
|
// init grid
|
||||||
var tmpLi = document.createElement('li');
|
var init = function init() {
|
||||||
tmpLi.innerHTML = words[uno].toUpperCase();
|
if(validateGrid()) {
|
||||||
document.getElementById('words').appendChild(tmpLi);
|
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,
|
||||||
|
fill: 'white',
|
||||||
|
stroke: 'black',
|
||||||
|
width: SIZE,
|
||||||
|
height: SIZE,
|
||||||
|
label: GRID[j][i],
|
||||||
|
selectable: false
|
||||||
|
});
|
||||||
|
canvas.add(rect);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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) {
|
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);
|
||||||
|
Loading…
Reference in New Issue
Block a user