<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8" />
<title>パチンコ</title>
<script src="sample.js"></script>
<script src="jquery.js"></script>
<script src="svgpaint.js"></script>
</head>
<body onload="sample()">
<p id="point"></p>
<p id="memo"></p>
<input id="but" type="button" value="ハンドル" />
</body>
</html>
var bx = new Array();
var by = new Array();
var nx = new Array();
var ny = new Array();
var dx = new Array();
var dy = new Array();
var ball = new Array();
var number;
var ax = new Array();
var ay = new Array();
var number_a,number_n;
var mode;
function sample(){
var timer;
var delay = 100;
mode = 1;
faststep();
$("#but").click(function () {
strike();
});
var loop = function () {
move();
wall();
neck();
bomb();
turn();
paint();
clearTimeout(timer);
timer = setTimeout(loop, delay);
}
loop();
}
function turn() {
if (Math.random() > 0.9) mode = 1;
}
function bomb() {
for (s = 1; s < 101; s++) {
x1 = Math.floor(bx[s]/10);
y1 = Math.floor(by[s]/10);
for (sx = 1; sx < number_a+1; sx++) {
h = 0;
if (x1 == ax[sx]) h = h + 1;
if (y1 == ay[sx]) h = h + 1;
if (ball[s] > 50) h = h + 1;
if (h == 3) mode = 2;
}
}
}
function neck() {
for (s = 1; s < 101; s++) {
x1 = Math.floor(bx[s]/10);
y1 = Math.floor(by[s]/10);
for (sx = 1; sx < number_n+1; sx++) {
h = 0;
if (x1 == nx[sx]) h = h + 1;
if (y1 == ny[sx]) h = h + 1;
if (ball[s] > 50) h = h + 1;
if (h == 3)dx[s]=-dx[s];
}
}
}
function wall(){
for(s=1;s<101;s++){
h=0;
if(bx[s]>980)h=h+1;
if(dx[s]>0)h=h+1;
if(h==2)dx[s]=-dx[s];
h=0;
if(bx[s]<20)h=h+1;
if(dx[s]<0)h=h+1;
if(h==2)dx[s]=-dx[s];
if(by[s]<10)ball[s]=0;
}
}
function paint(){
var sub=new svgpaint();
var str="<svg width=\"500\" height=\"500\">";
if (mode == 1) str = str + sub.rect(0, 0, 500, 500, "blue");
if (mode == 2) str = str + sub.rect(0, 0, 500, 500, "green");
for(s=1;s<101;s++){
x1=bx[s]/10;
y1=by[s]/10;
if(ball[s]>50)str=str+sub.rect(5*x1,500-5*y1,5,5,"red");
}
for(s=1;s<number_n+1;s++){
str=str+sub.rect(5*nx[s],500-5*ny[s],5,5,"yellow");
}
str=str+"</svg>";
$("#memo").html(str);
}
function strike(){
sx = 0;
for(s=1;s<101;s++){
if(ball[s]<50)sx=s;
}
if (sx > 0) {
ball[sx] = 100;
bx[sx] = 500;
by[sx] = 1000;
dx[sx] = randx()-5;
dy[sx] = -randx();
number=number-1;
}
}
function move() {
for(s=1;s<101;s++){
bx[s]=bx[s]+dx[s];
by[s]=by[s]+dy[s];
}
}
function faststep(){
number = 100;
for(s=1;s<101;s++){
ball[s]=0;
bx[s]=0;
by[s]=0;
dx[s] = 0;
dy[s] = 0;
}
number_a = 3;
ax[1] = 50;
ay[1] = 50;
ax[2] = 49;
ay[2] = 49;
ax[3] = 43;
ay[3] = 50;
number_n = 500;
for(s=1;s<501;s++){
x1=100*Math.random();
nx[s] = Math.floor(x1) + 1;
x1=100*Math.random();
ny[s]=Math.floor(x1) + 1;
}
}
function randx(){
var n1,n2;
n1=10*Math.random();
n2=Math.floor(n1)+1;
return n2;
}
最終更新:2015年05月22日 15:15