アットウィキロゴ

sensoux

var a = new Array();
var b = new Array();
var life_a = new Array();
var life_b = new Array();
var x=new Array();
var y=new Array();
var dir = new Array();
var number_dir = new Array();
var area = new Array();
var power_a, power_b;
 
function sample(){
 
    power_a = 1;
    power_b = 1;
 
 
for(s=1;s<6;s++){
a[s]=1;
b[s]=25;
life_a[s]=100;
life_b[s]=100;   
 }
 
 faststep();
 
 var timer;
var delay = 1000;
 
month = 1;
 
var loop = function () {
 
    month = month + 1;
    if (month > 12) shuffle();
    if (month > 12) month = 1;
 
    move();
 
    game();
 
    check();
 
    if (area[1] == 2) rev();
     if (area[25] == 1) rev();
 
    paint();
 
    clearTimeout(timer);
    timer = setTimeout(loop, delay);
}
 
loop();
 
 
}
 
function rev(){
 
    for(s=1;s<6;s++){
a[s]=1;
b[s]=25;
life_a[s]=100;
life_b[s]=100;   
 }
 
 power_a = 1;
 power_b = 1;
 
   for (t = 1; t < 26;t++ ){
    area[t] = 0;
    }
 
 
}
 
function shuffle(){
 
 
for(s=1;s<6;s++){
a[s]=1;
b[s]=25;
life_a[s]=100;
life_b[s]=100;   
 }
 
 power_a=0;
   for (t = 1; t < 26;t++ ){
    if(area[t]==1)power_a=power_a+1;
    }
 
power_b=0;
   for (t = 1; t < 26;t++ ){
    if(area[t]==2)power_b=power_b+1;
    }
 
 
 
}
 
 
function game(){
 
    var cha = new Array();
    var chb = new Array();
    for (s = 1; s < 26; s++) {
        cha[s] = 0;
        chb[s] = 0;
    }
 
for(s=1;s<6;s++){
sx=a[s];
if(life_a[s]>50)cha[sx]=100;    
sx=b[s];
if(life_a[s]>50)chb[sx]=100; 
}
 
 for (a1 = 1; a1 < 26; a1++) {
     h = 0;
     if(cha[a1]>50)h=h+1;
     if(cha[a1]>50)h=h+1;
     if (h == 2) fight(a1);
    }
 
 
 
 
}
 
function check(){
 
 
 for(s=1;s<6;s++){
     sx = a[s];
        if (life_a[s] > 50) area[sx]=1;
    }
 
     for(s=1;s<6;s++){
     sx = b[s];
        if (life_b[s] > 50) area[sx]=2;
    }
 
 
 
}
 
 
function fight(a1){
 
    var c1, c2;
    c1 = 0;
    c2 = 0;
    for(s=1;s<6;s++){
        h = 0;
        if (life_a[s] > 50) h = h + 1;
         if (a[s]==a1) h = h + 1;
         if (h == 2) c1 = c1 + power_a;
    }
 
     for(s=1;s<6;s++){
        h = 0;
        if (life_b[s] > 50) h = h + 1;
         if (b[s]==a1) h = h + 1;
         if (h == 2) c2 = c2 + power_b;
    }
 
 
    m1 = 2;
    n1 = (c1+c2)*Math.random();
    if (n1 < c1) m1 = 1;
 
 
    for(s=1;s<6;s++){
        h = 0;
        if (m1==2) h = h + 1;
         if (a[s]==a1) h = h + 1;
         if (h == 2) life_a[s]=0;
    }
 
    for(s=1;s<6;s++){
        h = 0;
        if (m1==1) h = h + 1;
         if (b[s]==a1) h = h + 1;
         if (h == 2) life_b[s]=0;
    }
 
 
 
 
 
 
 
}
 
 
 
 
function faststep(){
 
    for (t = 1; t < 26;t++ ){
    dir[t]=new Array();
    area[t] = 0;
    }
 
        tx = 0;
for(s=1;s<6;s++){
for(sx=1;sx<6;sx++){
tx=tx+1;
x[tx]=s;
y[tx]=sx;
}}
 
for(t=1;t<26;t++){
    tx = 0;
for(s1=-1;s1<2;s1++){
for(s2=-1;s2<2;s2++){
    x1 = x[t] + s1;
    y1 = y[t] + s2;
    sx = search(x1, y1);
  if(sx==t)sx=0;
    if (sx > 0) tx = tx + 1;
    if (sx > 0) dir[t][tx] = sx;
}}
number_dir[t] = tx;
}
 
 
 
}
 
function move(){
 
    for (s = 2; s < 6; s++) {
        sx = a[s];
        n1 = number_dir[sx] * Math.random();
        n2 = Math.floor(n1) + 1;
        a[s] = dir[sx][n2];
    }
 
    for (s = 2; s < 6; s++) {
        sx = b[s];
        n1 = number_dir[sx] * Math.random();
        n2 = Math.floor(n1) + 1;
        b[s] = dir[sx][n2];
    }
 
 
 
}
 
 
function search(x1,y1){
 
    var s,sx,h;
    sx=0;
    for (s = 1; s < 26; s++) {
        h = 0;
        if (x[s] == x1) h = h + 1;
        if (y[s] == y1) h = h + 1;
        if (h == 2) sx = s;
    }
    return sx;
 
}
 
 
 
 
function paint(){
 
 var sub=new svgpaint();
 
str="<svg width=\"500\" height=\"500\">";
 
for(s=1;s<26;s++){   
str=str+sub.rect(100*x[s]-100,100*y[s]-100,100,100,"green");
if(area[s]==1)str=str+sub.rect(100*x[s]-100,100*y[s]-100,100,100,"blue");
if(area[s]==2)str=str+sub.rect(100*x[s]-100,100*y[s]-100,100,100,"red");
 
}
 
 
 
str=str+"</svg>";
 
$("#memo").html(str);   
 
}
 
最終更新:2015年06月15日 15:41