アットウィキロゴ

hg59

var life_a = new Array();
var life_b = new Array();
var x_a = new Array();
var x_b = new Array();
var area = new Array();
var power_a, power_b;
 
function sample(){
 
for(s=1;s<11;s++){
area[s]=0;    
}
 
area[1] = 1;
area[10] = 2;
 
for(s=1;s<5;s++){
x_a[s]=1;
life_a[s]=100;    
x_b[s]=10;
life_b[s]=100;  
}
 
power_a = 100;
power_b = 100;
 
   var timer;
var delay = 1000;
 
var loop = function () {
 
    move_a();
    move_b();
 
for(a=1;a<11;a++){
game(a);
}
 
 
    check();
 
    paint();
 
    clearTimeout(timer);
    timer = setTimeout(loop, delay);
}
 
loop();
 
}
 
function paint(){
 
var sub=new svgpaint();
 
str="<svg width=\"500\" height=\"500\">";
for(s=1;s<11;s++){
if(area[s]==1)str=str+sub.rect(50*s,100,50,100,"blue"); 
if(area[s]==2)str=str+sub.rect(50*s,100,50,100,"red"); 
}
str=str+"</svg>";
 
$("#memo").html(str);   
 
}
 
 
function game(a1){
 
 
    c1 = 0;
for(s=1;s<5;s++){
if(x_a[s]==a1)c1=c1+power_a;    
}    
 
 
c2 = 0;
for(s=1;s<5;s++){
if(x_b[s]==a1)c2=c2+power_b;    
}
 
h=0;
if (c1 > 0) h = h + 1;
if (c2 > 0) h = h + 1;
if (h == 2) fight(a1,c1, c2);
 
}
 
function fight(a1,c1,c2){
 
m2 = 1;
m1=(c1+c2)*Math.random();
if(m1>c1)m2=2;
 
for(s=1;s<5;s++){
h=0;
if(x_a[s]==a1)h=h+1;
if(m2==2)h=h+1;
if(h==2)life_a[s]=0;  
}
 
for(s=1;s<5;s++){
h=0;
if(x_b[s]==a1)h=h+1;
if(m2==1)h=h+1;
if(h==2)life_b[s]=0;  
}
 
 
} 
 
 
 
 
function check(){
 
for(s=1;s<5;s++){
sx = x_a[s];
if(life_a[s]>50)area[sx]=1;
}
 
 
for(s=1;s<5;s++){
sx = x_b[s];
if(life_b[s]>50)area[sx]=2;
}
 
 
}
 
 
function move_a(){
 
    for (s = 1; s < 5; s++) {
        dx = 0;
        if (Math.random() > 0.5) dx = 1;
        x_a[s] = x_a[s] + dx;
        if (x_a[s] > 10) x_a[s] = 10;
    }
 
 
 
 
}
 
 
function move_b(){
 
    for (s = 1; s < 5; s++) {
        dx = 0;
        if (Math.random() > 0.5) dx = -1;
        x_b[s] = x_b[s] + dx;
        if (x_b[s] <1) x_b[s] = 1;
    }
 
 
 
 
}
最終更新:2015年06月11日 02:03