perubahan logika permainan
This commit is contained in:
parent
60de57f1c5
commit
31c073b09c
@ -2,7 +2,6 @@ const canvas = document.getElementById("board");
|
|||||||
if (!canvas) alert("Canvas tidak ditemukan! ID harus 'board'");
|
if (!canvas) alert("Canvas tidak ditemukan! ID harus 'board'");
|
||||||
const ctx = canvas.getContext("2d");
|
const ctx = canvas.getContext("2d");
|
||||||
|
|
||||||
// ensure canvas actual pixel size used for tileSize calculation
|
|
||||||
const CANVAS_W = canvas.width;
|
const CANVAS_W = canvas.width;
|
||||||
const CANVAS_H = canvas.height;
|
const CANVAS_H = canvas.height;
|
||||||
|
|
||||||
@ -20,7 +19,8 @@ let aiPlays = 2;
|
|||||||
let aiThinkingDelay = 300;
|
let aiThinkingDelay = 300;
|
||||||
|
|
||||||
let hintsEnabled = (typeof ENABLE_HINTS !== "undefined") ? !!ENABLE_HINTS : true;
|
let hintsEnabled = (typeof ENABLE_HINTS !== "undefined") ? !!ENABLE_HINTS : true;
|
||||||
/********** SOUND EFFECT **********/
|
|
||||||
|
// SOUND EFFECTS
|
||||||
const SFX = {
|
const SFX = {
|
||||||
move: new Audio("assets/sound/move.mp3"),
|
move: new Audio("assets/sound/move.mp3"),
|
||||||
capture: new Audio("assets/sound/capture.mp3")
|
capture: new Audio("assets/sound/capture.mp3")
|
||||||
@ -67,16 +67,15 @@ function resetBoard(){
|
|||||||
startTimer();
|
startTimer();
|
||||||
|
|
||||||
draw();
|
draw();
|
||||||
// small defer so UI painted before AI moves
|
// TRIGGER AI JIKA PERMAINAN DIMULAI OLEH AI
|
||||||
if(aiEnabled && currentTurn === aiPlays){
|
if(aiEnabled && currentTurn === aiPlays){
|
||||||
setTimeout(()=> triggerAI(), 120);
|
setTimeout(()=> triggerAI(), 120);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/********** DRAW **********/
|
// MENGGAMBAR PAPAN PADA CANVAS
|
||||||
function draw(){
|
function draw(){
|
||||||
// safety: re-compute tileSize if canvas resized via CSS (keep consistent)
|
// MENGGAMBAR PAPAN
|
||||||
// (we keep original tileSize computed from initial canvas.width)
|
|
||||||
ctx.clearRect(0,0,CANVAS_W,CANVAS_H);
|
ctx.clearRect(0,0,CANVAS_W,CANVAS_H);
|
||||||
|
|
||||||
for(let r=0;r<size;r++){
|
for(let r=0;r<size;r++){
|
||||||
@ -114,7 +113,7 @@ function drawPiece(cx,cy,v){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/********** HINTS DRAW **********/
|
// MENGGAMBAR HINTS MOVE
|
||||||
function drawMoveHints(moves){
|
function drawMoveHints(moves){
|
||||||
if(!moves || moves.length===0) return;
|
if(!moves || moves.length===0) return;
|
||||||
for(const m of moves){
|
for(const m of moves){
|
||||||
@ -127,7 +126,7 @@ function drawMoveHints(moves){
|
|||||||
ctx.fillStyle = m.capture ? "#dc2626" : "#22c55e";
|
ctx.fillStyle = m.capture ? "#dc2626" : "#22c55e";
|
||||||
ctx.fill(); ctx.closePath();
|
ctx.fill(); ctx.closePath();
|
||||||
|
|
||||||
// line
|
// GARIS HINT DARI MEMILIH PION KE TUJUAN
|
||||||
const sx = selected.c*tileSize + tileSize/2;
|
const sx = selected.c*tileSize + tileSize/2;
|
||||||
const sy = selected.r*tileSize + tileSize/2;
|
const sy = selected.r*tileSize + tileSize/2;
|
||||||
const tx = x+tileSize/2, ty = y+tileSize/2;
|
const tx = x+tileSize/2, ty = y+tileSize/2;
|
||||||
@ -149,7 +148,7 @@ function tryMove(r1,c1,r2,c2){
|
|||||||
const isKing = (v===3||v===4);
|
const isKing = (v===3||v===4);
|
||||||
const dir = (v===1||v===3) ? -1 : 1;
|
const dir = (v===1||v===3) ? -1 : 1;
|
||||||
|
|
||||||
// move
|
// GERAKAN BIASA
|
||||||
if(Math.abs(dr)===1 && Math.abs(dc)===1){
|
if(Math.abs(dr)===1 && Math.abs(dc)===1){
|
||||||
if(isKing || dr === dir){
|
if(isKing || dr === dir){
|
||||||
saveHistory();
|
saveHistory();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user