This article shares the specific code for JavaScript to implement Goziqi mini-game for your reference. The specific content is as follows
HTML part
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Gozi Chess</title> <style> * { padding: 0; margin: 0; } body{ padding-top: 100px; } .main { width: 600px; height: 600px; margin: 0 auto; background-color: burlywood; } .col { position: relative; width: 40px; height: 40px; box-sizing: border-box; border: 1px solid #000; border-collapse: collapse; /*border-radius: 20px;*/ } .row { position: relative; display: flex; height: 40px; /*background-color: brown;*/ } .col-action { background-color: blue; } .col-actionA { /*background-color: white;*/ } .col-actionB { /*background-color: black;*/ } .col-actionA::before{ content: ""; position: absolute; width: 30px; height: 30px; background-color: white; border-radius: 99px; top:4.5px; left:4.5px; box-shadow: 0 0 2px rgba(0,0,0,0.5); } .col-actionB::before{ content: ""; width: 30px; height: 30px; background-color: black; border-radius: 99px; position: absolute; top:4.5px; left:4.5px; box-shadow: 0 0 2px rgba(128,128,128,0.5); } .hq{ width: 600px; height: 600px; margin: 0 auto; } </style> <script type="text/javascript" src="js/" ></script> </head> <body> <div class="main"> <div class="qipan" > </div> <div class="hq"><button >Regret chess</button></div> </div> </body> </html>
JavaSrcipt
= function(){ var busz = new Array(); //div click event var ansj = function () { const x = ("col"); const y = ("row"); // (x, y, nowPlayer) if (nowPlayer) { qjck[("row")][("col")] = 1; ("col-actionA"); nowPlayer = !nowPlayer; } else { qjck[("row")][("col")] = 2; ("col-actionB"); nowPlayer = !nowPlayer; } (this); var js = pdsl(y,x); if(js) { setTimeout(function(){ alert("game over"); (); //Refresh the browser },50); } = null; } //Judge whether it is over var pdsl = function(x,y){ var sx=1,zy=1,zs=1,ys=1,t=1; //superior for(t=1;t<=5;t++){ if(x-t < 0) break; ("superior"+zy); if(qjck[x-t][y]==qjck[x][y] && qjck[x-t][y]!=0) sx++; else break; } //Down for(t=1;t<=5;t++){ if(Number(x)+t >= 10) break; ("Down"+zy); if(qjck[Number(x)+t][y]==qjck[Number(x)][y] && qjck[Number(x)+t][y]!=0) sx++; else break; } //Left for(t=1;t<=5;t++){ if(y-t < 0) break; ("Left"+zy); if(qjck[x][y-t]==qjck[x][y] && qjck[x][y-t]!=0) zy++; else break; } //right for(t=1;t<=5;t++){ if(Number(y)+t >= 10) break; ("right"+zy); if(qjck[x][Number(y)+t]==qjck[x][y] && qjck[x][Number(y)+t]!=0) zy++; else break; } //Up left for(t=1;t<=5;t++){ if(x-t < 0) break; ("Up left"+zy); if(qjck[x-t][y-t]==qjck[x][y] && qjck[x-t][y-t]!=0) zs++; else break; } //Lower right for(t=1;t<=5;t++){ if(Number(x)+t >= 10 || Number(y)+t >= 10) break; ("Lower Right"+zy); if(qjck[Number(x)+t][Number(y)+t]==qjck[x][y] && qjck[Number(x)+t][Number(y)+t]!=0) zs++; else break; } //Up right for(t=1;t<=5;t++){ if(x-t < 0 || Number(y)+t >= 10) break; ("Up to the right"+zy); if(qjck[x-t][Number(y)+t]==qjck[x][y] && qjck[x-t][Number(y)+t]!=0) ys++; else break; } //Lower left for(t=1;t<=5;t++){ if(Number(x)+t >= 10 || y-t < 0) break; ("Lower Right"+zy); if(qjck[Number(x)+t][y-t]==qjck[x][y] && qjck[Number(x)+t][y-t]!=0) ys++; else break; } (sx + " " + zy + " " + zs + " " + ys); if(sx == 5 || zy==5 || zs==5 || ys==5) return true; else return false; } var nowPlayer = 0; //Chessboard array var qjck = Array(); //div var piece = ("div"); = "piece"; //Get div var qipan = ("qipan"); //Generate a chessboard for (let r = 0; r < 15; r++) { let newrow = ("div"); = "row" + r; ("row") let arrCol = Array() (arrCol) for (let c = 0; c < 15; c++) { (0) let newcol = ("div"); = "col" + c; ("col"); ("row", r); ("col", c) (newcol) = ansj; } // (newrow) (newrow) } //Repent chess var hq = ("hq"); = function(){ if( <= 0) return; var divt = (); = ansj; ("col-actionA"); ("col-actionB"); qjck[("row")][("col")] = 0; nowPlayer = !nowPlayer; // (qjck); (divt); } }
More interesting classic game implementation topics, share with you:
Summary of C++ classic games
Summary of classic python games
python Tetris game collection
JavaScript classic game
Summary of classic javascript games
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.