//var n=1;
//initial settings
var min1=1;
var max1=1;
var min2=12;
var max2=50;
var GONews;
var grid;
function setHTML(id,text){
var e=document.getElementById(id);
if (e==null) return;
e.innerHTML=text;
}
function gravity (x){
x=Math.floor(x/50)*50;
return x+25;
}
class Movable {
static DOWN=1;
static UP=2;
static mouse=2;
static x1=0;
static y1=0;
static ctx;
static list=new Array();
static list1=new Array();
static list2=new Array();
static selected=null;
constructor(x,y){
this.x0=x;
this.y0=y;
this.fixed=false;
}
inside(x,y){
return true;
}
draw (ctx1){
;
}
move (e){
if (this.fixed==true) return;
var dx=e.offsetX-Movable.x1;
var dy=e.offsetY-Movable.y1;
this.x0+=dx;
this.y0+=dy;
Movable.x1=e.offsetX;
Movable.y1=e.offsetY;
this.draw(Movable.ctx);
}
fixPosition(x,y){
this.x0=x;
this.y0=y;
this.fixed=true;
}
static mouseUp() {
Movable.mouse=Movable.UP;
/*if (Movable.selected!=null){
Movable.selected.x0=gravity(Movable.selected.x0)+25;
Movable.selected.y0=gravity(Movable.selected.y0)+25;
}*/
}
static mouseDown(e) {
Movable.mouse=Movable.DOWN;
Movable.x1=e.offsetX;
Movable.y1=e.offsetY;
}
static isMouseDown() {
if (Movable.mouse==Movable.DOWN)
return true;
return false;
}
static isInside (e){
for (var i=0;i
(2*50+500)&&x1<3*50+500)&&(y1>(3*50+100)&&y1<4*50+100))NUM1=1;
if ((x2>(3*50+500)&&x2<4*50+500)&&(y2>(1*50+100)&&y2<2*50+100))NUM2=1;
if ((x3>(3*50+500)&&x3<4*50+500)&&(y3>(2*50+100)&&y3<3*50+100))NUM3=1;
if ((x4>(3*50+500)&&x4<4*50+500)&&(y4>(3*50+100)&&y4<4*50+100))NUM4=1;
if ((x5>(3*50+500)&&x5<4*50+500)&&(y5>(4*50+100)&&y5<5*50+100))NUM5=1;
if ((x6>(4*50+500)&&x6<5*50+500)&&(y6>(2*50+100)&&y6<3*50+100))NUM6=1;
if ((x7>(4*50+500)&&x7<5*50+500)&&(y7>(3*50+100)&&y7<4*50+100))NUM7=1;
*/
/*var x =
for (i=1;i<6;i++)
for (j=1;j<5;j++)
ctx.rect(50*i+300, 50*j+100, 50,50);
for (k=1;k<21;k++)
var x(k)=Movable.list[k].x0;
var y(k)=Movable.list[k].y0;
if (x(k)>50*i+300 && x(k)<50*i+300+50; */
var x = new Array();
var y = new Array();
var pp=Movable.list[0];
var p;
for (k=1;k<20;k++){
p=Movable.list[k];
var diff=Math.abs(pp.x0-p.x0)+Math.abs(pp.y0-p.y0);
//tx.fillText("diff"+diff, 300, 50);
if (diff!=50){
OK1=1;
return false;}
pp=p;
OK1+=OK1
}
ctx.fillStyle="red";
ctx.font="25px Arial";
//if (NUM1==1&&NUM2==1&&NUM3==1&&NUM4==1&&NUM5==1&&NUM6==1&&NUM7==1)
if (OK1==0)
if (lang==0){
ctx.fillText("Good Job!",400, 50);
}else{
ctx.fillText("恭喜成功!",400, 50);
}
}
class MyRect extends Movable {
constructor (x,y,w,h){
super (x,y);
this.w=w;
this.h=h;
//this.id=id;
}
inside(x,y){
x-=this.x0;
y-=this.y0;
if(x>=0 && x<=this.w && y>=0 &&y<=this.h)
return true;
return false;
}
draw (ctx){
ctx.fillStyle="blue";
ctx.fillRect(this.x0, this.y0, this.w, this.h);
;
}
}
class MyCircle extends Movable {
constructor (xx,y,r,id){
super (xx,y);
this.r=r;
//this.h=h;
this.id=id;
}
setlocation (x,y){
this.x0=x;
this.y0=y;
}
inside(x,y){
if(this.fixed==true)
return false;
x-=this.x0;
y-=this.y0;
var r=this.r;
if((x*x+y*y)<(r*r))
return true;
return false;
}
/*move (e){
var x=Math.floor(e.offsetX/50)*50;
var y=Math.floor(e.offsetY/50)*50;
//var dx=e.offsetX-Movable.x1;
//var dy=e.offsetY-Movable.y1;
super.move(e);
var dx=x-Movable.x1;
var dy=y-Movable.y1;
this.x0+=dx;
this.y0+=dy;
Movable.x1=e.offsetX;
Movable.y1=e.offsetY;
this.draw(Movable.ctx);
var newx0=this.x0-300;
var newy0=this.y0-200;
var angleP=Math.atan2(newy0,newx0);
this.x0=300+75*Math.cos(angleP);
this.y0=200+75*Math.sin(angleP);
}*/
draw (ctx){
ctx.strokeStyle="brown";
ctx.beginPath();
//ctx.lineTo(this.x0+20,this.y0+20);
var newx0=this.x0-300;
var newy0=this.y0-200;
var angleP=Math.atan2(newy0,newx0);
var d=Math.sqrt(newx0*newx0+newy0*newy0);
var newx=300+(d+this.r)*Math.cos(angleP);
var newy=200+(d+this.r)*Math.sin(angleP);
var newx1=300+(d-this.r)*Math.cos(angleP);
var newy1=200+(d-this.r)*Math.sin(angleP);
//this.x0=300+75*Math.cos(angleP);
//this.y0=200+75*Math.sin(angleP);
//ctx.moveTo(newx1,newy1);
//ctx.lineTo(newx,newy);
//ctx.arc(this.x0, this.y0, this.r,0,2*Math.PI);
ctx.fillStyle="green";
if (this.fixed==true) ctx.fillStyle="black";
ctx.font="20px Arial";
ctx.textAlign = "center";
ctx.fillText(""+this.id,this.x0, this.y0+7);
if (angleP<0)angleP+=Math.PI*2;
angleP=angleP*180/Math.PI;
angleP=360-angleP;
angleP=angleP-90;
if (angleP<0)angleP=angleP+360;
//if (angleP<0) angleP=-angleP;
//ctx.fillText(""+(angleP).toFixed(0),this.x0, this.y0+7);
//ctx.moveTo(0, 0);
//ctx.lineTo(this.x0, this.y0)
ctx.stroke();
}
}
class MyContainer {
constructor (x,y,r,type, color){
//constructor (x,y,w, h,color){
this.x0=x;
this.y0=y;
this.r=r;
this.type=type;
this.color=color;
}
inside(x,y){
x-=this.x0;
y-=this.y0;
var r=this.r;
if((x*x+y*y)<(r*r))
return true;
return false;
}
draw (ctx){
ctx.strokeStyle=this.color;
ctx.beginPath();
ctx.arc(this.x0, this.y0, this.r,0,2*Math.PI);
ctx.stroke();
}
isOK(n){
if (this.inside(n.x0,n.y0)==false)
return 0;
var re=0;
switch (this.type) {
case 1:
if (n.id%2==1)
re= 1;
break;
case 2:
if (n.id%2==0)
re= 1;
break;
case 3:
if (n.id%3==0)
re= 1;
break;
}
}
}
function doMouseDown(event) {
//alert("mouse is down");
//var m=document.getElementById("mouseInfo");
//m.innerHTML="mouse is down";
Movable.mouseDown(event);
Movable.isInside(event);
}
function doMouseUp(event) {
//alert("mouse is up");
//var m=document.getElementById("mouseInfo");
//m.innerHTML="mouse is up";
Movable.mouseUp();
//Movable.positionOK();
var inGrid=0;
for (var i=0;i
) processed by MyLexV4 -->