sync on; sync rate 31; global width as integer; width = 32; global dim board(8,8) as integer; global currentx as integer;global currenty as integer;global clickedx as integer ;global clickedy as integer
for y = 1 to 8;for x = 1 to 8;board(x,y) = 0 ; ;if (x+y) mod 2 = 1;
;if y < 4 ; board(x,y) = 1; endif; if y > 5; board(x,y) = -1; endif; endif;next x;next y;
do
cls; displayGBoard(); getCurrentSquare(); if mouseclick()=1 and clickedx > 0 ; if currentx > 0; move(); endif;
; endif; if mouseclick()=2 and clickedx = 0; clickedx=currentx; clickedy=currenty; ; endif;sync;loop
function displayGBoard()
for y = 1 to 8;for x = 1 to 8;if (x+y) mod 2 = 0 ;box x*width,y*width,x*width+width, y*width+width, RGB(255,0,0), RGB(255,0,0) , RGB(255,0,0) , RGB(255,0,0) ;else; box x*width,y*width,x*width+width, y*width+width, 0,0,0,0; endif; next x;next y
for y = 1 to 8;for x = 1 to 8;if board(x,y) = 1 ; circle x*width+width/2, y*width+width/2, width/3
;circle x*width+width/2, y*width+width/2, width/2.5 ;endif ;if board(x,y) = -1; circle x*width+width/2, y*width+width/2, width/3 ;endif ;next x;next y
endfunction
function getCurrentSquare;for y = 1 to 8;for x = 1 to 8;if mousex() > x*width AND mousex() < x*width+width AND mousey() > y*width AND mousey() < y*width+width
;if board(x,y) <> 0 then circle x*width+width/2,y*width+width/2, width/1.5;currentx =x; currenty=y;
endif ;next x;next y;
endfunction
function move() ;if (currentx+currenty) mod 2 <> 0 ;;if board(currentx, currenty) = 0 ;if ABS(clickedx-currentx) < 2 AND ABS(clickedy-currenty) < 2
;board(currentx,currenty) = board(clickedx, clickedy) ;board(clickedx, clickedy) = 0; else if ABS(clickedx-currentx) < 3 AND ABS(clickedy-currenty) < 3 ;if board( ((currentx+clickedx)/2), ((currenty+clickedy)/2)) = board(clickedx,clickedy)*(-1)
;board(currentx,currenty) = board(clickedx, clickedy) ;board(clickedx, clickedy) = 0 ;board( ((currentx+clickedx)/2), ((currenty+clickedy)/2))=0;
; endif ;endif;endif; endif;endif;clickedx=0; clickedy=0;endfunction
And uncompressed with commenting:
`CHECKERS!!!!
sync on
sync rate 31
global width as integer
width = 32
global dim board(8,8) as integer
global currentx as integer
global currenty as integer
global clickedx as integer
global clickedy as integer
for y = 1 to 8
for x = 1 to 8
board(x,y) = 0 ; `initialize it
if (x+y) mod 2 = 1
`top half make p1 bottom half p2 aka neg 1
if y < 4
board(x,y) = 1
endif
if y > 5
board(x,y) = -1
endif
endif
next x
next y
`MAIN LOOP
do
cls
displayGBoard()
getCurrentSquare()
if mouseclick()=1 and clickedx > 0
if currentx > 0
move()
endif
rem only move if prev. selected then clear buff
endif
if mouseclick()=2 and clickedx = 0
clickedx=currentx; clickedy=currenty;
endif
print STR$(currentx)
print STR$(currenty)
print STR$(clickedx)
print STR$(clickedy)
sync
loop
function displayGBoard()
for y = 1 to 8
for x = 1 to 8
if (x+y) mod 2 = 0
box x*width,y*width,x*width+width, y*width+width, RGB(255,0,0), RGB(255,0,0) , RGB(255,0,0) , RGB(255,0,0)
else
box x*width,y*width,x*width+width, y*width+width, 0,0,0,0
endif
next x
next y
for y = 1 to 8
for x = 1 to 8
if board(x,y) = 1
circle x*width+width/2, y*width+width/2, width/3
circle x*width+width/2, y*width+width/2, width/2.5
endif
if board(x,y) = -1
circle x*width+width/2, y*width+width/2, width/3
endif
next x
next y
endfunction
function getCurrentSquare
for y = 1 to 8
for x = 1 to 8
if mousex() > x*width AND mousex() < x*width+width AND mousey() > y*width AND mousey() < y*width+width
`make sure it has a game piece
if board(x,y) <> 0 then circle x*width+width/2,y*width+width/2, width/1.5
currentx =x; currenty=y
`end game piece make-sureing
endif
next x
next y
endfunction
function move()
rem do movement, else, just reset due to invalid
if (currentx+currenty) mod 2 <> 0 ;`if it's a black square
if board(currentx, currenty) = 0
if ABS(clickedx-currentx) < 2 AND ABS(clickedy-currenty) < 2 `if it's less than 2 squares, normal movement
board(currentx,currenty) = board(clickedx, clickedy)
board(clickedx, clickedy) = 0
else if ABS(clickedx-currentx) < 3 AND ABS(clickedy-currenty) < 3 `check to make sure there's a jump
if board( ((currentx+clickedx)/2), ((currenty+clickedy)/2)) = board(clickedx,clickedy)*(-1) `if it's the enemy between
board(currentx,currenty) = board(clickedx, clickedy)
board(clickedx, clickedy) = 0 `then move. and
board( ((currentx+clickedx)/2), ((currenty+clickedy)/2))=0; `delete between guy
endif
endif
endif
endif
endif
clickedx=0; clickedy=0;
endfunction
I kept in the debug statements too... while AI is missing, logic isn't (except kingings and backwards-motion). I wrote this quick between now and my last post... it just took awhile to figure out how to make it 20 lines.
Controls are Right-click to select a checker and left-click to move it. Jumps work. A gift for the community during a work-break.
Signed
------