とっておきの手土産を教えて

このプログラムに、王手をかけた時に、「王手!」と表示できるようなプログラムを簡単で良いので教えてください!

var canvas;
var ctx;
var nametbl = [
"玉","飛","角","金","銀","桂","香","歩",
"" ,"竜","馬","" ,"全","圭","杏","と"
];
var x1 = [ 0, 1, 1, 1, 0,-1,-1,-1, 1,-1];
var y1 = [-1,-1, 0, 1, 1, 1, 0,-1,-2,-2];
var movtbl = [
[ 1,1,1,1,1,1,1,1,0,0 ],
[ 2,0,2,0,2,0,2,0,0,0 ],
[ 0,2,0,2,0,2,0,2,0,0 ],
[ 1,1,1,0,1,0,1,1,0,0 ],
[ 1,1,0,1,0,1,0,1,0,0 ],
[ 0,0,0,0,0,0,0,0,1,1 ],
[ 2,0,0,0,0,0,0,0,0,0 ],
[ 1,0,0,0,0,0,0,0,0,0 ],
[ 0,0,0,0,0,0,0,0,0,0 ],
[ 2,1,2,1,2,1,2,1,0,0 ],
[ 1,2,1,2,1,2,1,2,0,0 ],
[ 0,0,0,0,0,0,0,0,0,0 ],
[ 1,1,1,0,1,0,1,1,0,0 ],
[ 1,1,1,0,1,0,1,1,0,0 ],
[ 1,1,1,0,1,0,1,1,0,0 ],
[ 1,1,1,0,1,0,1,1,0,0 ]
];
var setup = [
[ -1, -1, -1, -1, -1, -1, -1, 0, 6 ],
[ -1, -1, -1, -1, -1, 3, 7, -1, -1 ],
[ -1, -1, -1, -1, -1, -1, -1, -1, 7 ],
[ -1, -1, -1, -1, -1, 2, -1, -1, -1 ],
[ -1, -1, -1, -1, -1, -1, -1, -1, -1 ],
[ -1, -1, -1, -1, -1, -1, -1, -1, -1 ],
[ -1, -1, -1, -1, -1, -1, -1, -1, -1 ],
[ -1, -1, -1, -1, -1, -1, -1, -1, -1 ],
[ -1, -1, -1, -1, -1, -1, -1, -1, -1 ]
];
var setup2 = [
[ -1, -1, -1, -1, -1, -1, -1, 1, 1 ],
[ -1, -1, -1, -1, -1, 1, 1, -1, -1 ],
[ -1, -1, -1, -1, -1, -1, -1, -1, 1 ],
[ -1, -1, -1, -1, -1, 0, -1, -1, -1 ],
[ -1, -1, -1, -1, -1, -1, -1, -1, -1 ],
[ -1, -1, -1, -1, -1, -1, -1, -1, -1 ],
[ -1, -1, -1, -1, -1, -1, -1, -1, -1 ],
[ -1, -1, -1, -1, -1, -1, -1, -1, -1 ],
[ -1, -1, -1, -1, -1, -1, -1, -1, -1 ]
];
var setMochi0 = [ 4, 1];
var setMochi1 = [ 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 1, 2, 6, 6, 6, 5, 5, 5, 5,];
var fontcolor = ["black","maroon"];
var boxcolor = ["pink","gray","blue","red"];
var fillcolor = ["pink","Khaki","white","LightPink"];
var psize = 32;
var board = [];
var bw = 17,bh = 11;
var ofsx = 4,ofsy = 1;
var turn = 0;
var startx = -1,starty = -1;
var username = ["ipad","iphone","android"];
var playtbl = ["先手","後手"];
function piece(){
this.id = -1;
this.player = 0;
this.movable = false;
}
function init(){
canvas = document.getElementById("world");
canvas.width = 640;
canvas.height = 400;
ctx = canvas.getContext('2d');
ctx.font = "24px 'Hiragino Mincho ProN', 'ヒラギノ明朝 ProN W3', serif";
user = window.navigator.userAgent.toLowerCase();
for(i=0; i<username.length; i++){
if(user.indexOf(username[i]) > 0)break;
}
if (i > username.length){
document.addEventListener("touchstart", touchstart);
} else {
document.addEventListener("mousedown", mousedown);
}
board = new Array(bh);
for (y=0; y<bh; y++) {
board[y] = new Array(bw);
for (x=0; x<bw; x++) {
board[y][x] = new piece();
}
}
for (y=0; y<9; y++) {
for (x=0; x<9; x++) {
board[ofsy+y][ofsx+x].id = setup[y][x];
board[ofsy+y][ofsx+x].player = setup2[y][x];
}
}
for (i=0; i<setMochi0.length; i++) {
setMochi(setMochi0[i], 0);
}
for (i=0; i<setMochi1.length; i++) {
setMochi(setMochi1[i], 1);
}
redraw();
}
function touchstart(e){
if (e.targetTouches.length == 1){
touch = e.targetTouches[0];
touchpiece(touch.pageX ,touch.pageY);
}
}
function mousedown(e){
touchpiece(e.clientX ,e.clientY);
}
function touchpiece(tx,ty){
cx = Math.floor((tx-8)/psize);
cy = Math.floor((ty-8)/psize);
if (isinside(cx,cy,0,0,bw,bh)==false)return;
if (startx == -1){
movestart(cx,cy);
} else {
moveend(cx,cy);
startx = -1;
redraw();
}
}

文字数制限がある為、続きのソースコードは次の質問に掲載しています。

A 回答 (1件)

王手を判定する


 本当に王手だったとき
  王手!と表示する
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!

このQ&Aを見た人はこんなQ&Aも見ています


おすすめ情報

このQ&Aを見た人がよく見るQ&A