<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8" />
<script src="sample.js"></script>
<script src="jquery.js"></script>
<script src="ex.js"></script>
<script src="svgpaint.js"></script>
<title>信長の野望</title>
</head>
<body onload="sample()">
<p id="memo"></p>
</body>
</html>
var dir=new Array();
var number_dir=new Array();
var c=new Array();
var x=new Array();
var y=new Array();
var number_c;
var ball;
function sample(){
for(s=1;s<101;s++){
dir[s]=new Array();
}
var sub = new ex();
sub.dir = dir;
sub.faststep();
c = sub.c;
x = sub.x;
y = sub.y;
dir = sub.dir;
number_dir = sub.number_dir;
number_c = sub.number_c;
var timer;
var delay = 100;
ball = 5;
var loop = function () {
n1 = number_dir[ball] * Math.random();
n2 = Math.floor(n1) + 1;
ball = dir[ball][n2];
c[ball] = 1;
paint();
clearTimeout(timer);
timer = setTimeout(loop, delay);
}
loop();
}
function paint(){
var sub=new svgpaint();
str="<svg width=\"500\" height=\"500\">";
for (s = 1; s < number_c+1; s++) {
if(c[s]==1)str = str + sub.rect(50 * x[s], 500 - 50 * y[s], 50, 50, "green");
if(c[s]==2)str = str + sub.rect(50 * x[s], 500 - 50 * y[s], 50, 50, "blue");
if(c[s]==3)str = str + sub.rect(50 * x[s], 500 - 50 * y[s], 50, 50, "pink");
if(c[s]==4)str = str + sub.rect(50 * x[s], 500 - 50 * y[s], 50, 50, "red");
if(c[s]==5)str = str + sub.rect(50 * x[s], 500 - 50 * y[s], 50, 50, "brown");
}
str = str + "</svg>";
$("#memo").html(str);
}
class ex{
x:number[]=new Array();
y:number[]=new Array();
dir:any[]=new Array();
number_dir:number[]=new Array();
c:number[]=new Array();
number_c:number;
faststep():void{
var s,sx,tx:number;
tx=0;
for(s=1;s<11;s++){
for(sx=1;sx<11;sx++){
tx=tx+1;
this.x[tx]=s;
this.y[tx]=sx;
this.c[tx]=this.randcol();
}}
this.number_c=tx;
for(s=1;s<this.number_c+1;s++){
tx=0;
for(sx=1;sx<this.number_c+1;sx++){
if(this.check(s,sx)>60)tx=tx+1;
if(this.check(s,sx)>60)this.dir[s][tx]=sx;
}
this.number_dir[s]=tx;
}
}
check(s1:number,s2:number):number{
var x1,y1,ch:number;
x1=this.x[s1]-this.x[s2];
y1=this.y[s1]-this.y[s2];
ch=100;
if(x1*x1>1)ch=0;
if(y1*y1>1)ch=0;
if(s1==s2)ch=0;
return ch;
}
randcol():number{
var n1:number;
var n2:number;
n1=5*Math.random();
n2=Math.floor(n1)+1;
return n2;
}
}
最終更新:2015年10月02日 10:08