PegSolitare v1.0 - Classic Peg puzzle game (iPad only)
Posted: Mon Sep 25, 2017 12:54 am
I adapted my frogjump game to make a classic peg solitare jump game. I tried to make it look classic. It's for iPad only right now, just didn't have time to make it all device compatible. I'm posting it now anyway. Hope you enjoy it!
- Dav
- Dav
Code: Select all
'PegSolitare.txt v1.0 (ipad only)
'Classic peg puzzle game
'Coded by Dav, SEP/2017
'Note: Sorry, this is for ipad only right now.
'I'll finish making it 'all devices' later this
'week, maybe, if I have time....
'initialize program
randomize
option base 1
set toolbar off
get orientation ort
set orientation vertical
get screen size sw,sh
rw=sw/768!rh=sh/1024 'all device fix
sound=1
showjumps=1
'======
restart:
'======
graphics
graphics clear .2,.2,.2
set buttons custom
'draw background texture
draw alpha .3
draw font size 100
draw color 0,0,0
'a litte background
for x=1 to sw step 61
for y =1 to sh step 102
draw text chr$(9619) at x,y
next y
next x
draw alpha 1
'draw title...
shadow on
peg$=chr$(9439)&chr$(9428)&chr$(9430) 'peg emoji
draw color .3,.3,.3
draw font size 56
draw text peg$ at 295,25
draw color .5,.5,.5
draw text peg$ at 293,23
draw font size 44
draw text "SOLITARE" at 279,74
shadow off
'draw board background
fill color .4,.4,.4! fill rect 244,180 to 524,788
fill color .8,.8,.8 ! fill rect 264,200 to 504,770
fill color .4,.4,.4!fill rect 84,330 to 688,642
fill color .8,.8,.8!fill rect 104,346 to 668,622
'black ball, empty ball
x$=chr$(9899)!o$=chr$(9898)
'make an array for button data, 35 places
dim bv$(35)!for t=1 to 35!bv$(t)=x$!next t
'mark center as empty
bv$(17)=o$
gosub makebuttons
'===
main:
'===
selected=0
gosub drawboard
gosub checkifmovesleft
second:
do
for t=1 to 33
if button_pressed(str$(t)) then
'if first choice...
if selected=0 then
'only select an x$ pad
if bv$(t)=x$ then
selected=1 ! selbtn=t ! but(t)
'show jump options
if showjumps=1 then
show=1!gosub checkandmove!show=0
end if
if sound=1 then
notes set "120:sg7"!notes play
end if
goto second 'now get second choice
end if
else 'making second choice
'only jump to blank pads
if bv$(t)=o$ then
gosub checkandmove
goto main
else
'clear previous highlighted btn
selected=0!gosub drawboard!selected=1
'set new one now...
selbtn=t!but(t)
'show jump options
if showjumps=1 then
show=1!gosub checkandmove!show=0
end if
if sound=1 then
notes set "120:sg7"!notes play
end if
goto second
end if
end if
end if
next t
if button_pressed("restart") then goto restart
if button_pressed("jumps") then
if showjumps=1 then
showjumps=0
else
showjumps=1
end if
gosub makebuttons
end if
if button_pressed("quit") then
set orientation ort ! end
end if
if button_pressed("sound") then
if sound=1 then
sound=0
else
sound=1
end if
gosub makebuttons
end if
if button_pressed("quit") then
set orientation ort ! end
end if
until 0
end
end
'========
drawboard:
'========
for b=1 to 33
but(b)
next b
return
'==========
makebuttons:
'==========
'make a restart button
set buttons custom
set buttons font size 36*rw
draw color 0,0,0
fill color 1,1,.8
button "restart" text "Restart" at 325*rw,900*rh
'make a quit button
draw color 0,0,0
fill color 1,.5,.5
button "quit" text "Quit" at 25*rw,25*rh
'make sound on/off button
if sound=0 then
fill color .3,.3,.3
button "sound" text "Sound=Off" at 25*rw,900*rh
else
fill color .6,.6,.6
button "sound" text "Sound=On" at 25*rw,900*rh
end if
'make show jump on/off button
if showjumps=0 then
fill color .3,.3,.3
button "jumps" text "Jumps=Off" at 550*rw,900*rh
else
fill color .6,.6,.6
button "jumps" text "Jumps=On" at 550*rw,900*rh
end if
return
'===============================
def but(n) 'draws puzzle buttons
draw color .8,.8,.8
set buttons font size 70*.rw
if .selected = 1 then
fill color 1,1,.9
else
fill color .8,.8,.8
end if
if n=1 then button n text .bv$(n) at 264*.rw,210*.rh size 80*.rw,80*.rh
if n=2 then button n text .bv$(n) at 344*.rw,210*.rh size 80*.rw,80*.rh
if n=3 then button n text .bv$(n) at 424*.rw,210*.rh size 80*.rw,80*.rh
if n=4 then button n text .bv$(n) at 264*.rw,290*.rh size 80*.rw,80*.rh
if n=5 then button n text .bv$(n) at 344*.rw,290*.rh size 80*.rw,80*.rh
if n=6 then button n text .bv$(n) at 424*.rw,290*.rh size 80*.rw,80*.rh
if n=7 then button n text .bv$(n) at 104*.rw,370*.rh size 80*.rw,80*.rh
if n=8 then button n text .bv$(n) at 184*.rw,370*.rh size 80*.rw,80*.rh
if n=9 then button n text .bv$(n) at 264*.rw,370*.rh size 80*.rw,80*.rh
if n=10 then button n text .bv$(n) at 344*.rw,370*.rh size 80*.rw,80*.rh
if n=11 then button n text .bv$(n) at 424*.rw,370*.rh size 80*.rw,80*.rh
if n=12 then button n text .bv$(n) at 504*.rw,370*.rh size 80*.rw,80*.rh
if n=13 then button n text .bv$(n) at 584*.rw,370*.rh size 80*.rw,80*.rh
if n=14 then button n text .bv$(n) at 104*.rw,450*.rh size 80*.rw,80*.rh
if n=15 then button n text .bv$(n) at 184*.rw,450*.rh size 80*.rw,80*.rh
if n=16 then button n text .bv$(n) at 264*.rw,450*.rh size 80*.rw,80*.rh
if n=17 then button n text .bv$(n) at 344*.rw,450*.rh size 80*.rw,80*.rh
if n=18 then button n text .bv$(n) at 424*.rw,450*.rh size 80*.rw,80*.rh
if n=19 then button n text .bv$(n) at 504*.rw,450*.rh size 80*.rw,80*.rh
if n=20 then button n text .bv$(n) at 584*.rw,450*.rh size 80*.rw,80*.rh
if n=21 then button n text .bv$(n) at 104*.rw,530*.rh size 80*.rw,80*.rh
if n=22 then button n text .bv$(n) at 184*.rw,530*.rh size 80*.rw,80*.rh
if n=23 then button n text .bv$(n) at 264*.rw,530*.rh size 80*.rw,80*.rh
if n=24 then button n text .bv$(n) at 344*.rw,530*.rh size 80*.rw,80*.rh
if n=25 then button n text .bv$(n) at 424*.rw,530*.rh size 80*.rw,80*.rh
if n=26 then button n text .bv$(n) at 504*.rw,530*.rh size 80*.rw,80*.rh
if n=27 then button n text .bv$(n) at 584*.rw,530*.rh size 80*.rw,80*.rh
if n=28 then button n text .bv$(n) at 264*.rw,610*.rh size 80*.rw,80*.rh
if n=29 then button n text .bv$(n) at 344*.rw,610*.rh size 80*.rw,80*.rh
if n=30 then button n text .bv$(n) at 424*.rw,610*.rh size 80*.rw,80*.rh
if n=31 then button n text .bv$(n) at 264*.rw,690*.rh size 80*.rw,80*.rh
if n=32 then button n text .bv$(n) at 344*.rw,690*.rh size 80*.rw,80*.rh
if n=33 then button n text .bv$(n) at 424*.rw,690*.rh size 80*.rw,80*.rh
end def
'===========
checkandmove:
'===========
'selbtn = first selected button
't = the second selected button (destination)
'====== logic for btn 1
if selbtn=1 then
'go from 1 to 4, jumping over 2,etc...
if t=3 or show=1 or moves=1 then jump(1,2,3)
if t=9 or show=1 or moves=1 then jump(1,4,9)
end if
'====== logic for btn 2
if selbtn=2 then
if t=10 or show=1 or moves=1 then jump(2,5,10)
end if
'====== logic for btn 3
if selbtn=3 then
if t=1 or show=1 or moves=1 then jump(3,2,1)
if t=11 or show=1 or moves=1 then jump(3,6,11)
end if
'====== logic for btn 4
if selbtn=4 then
if t=6 or show=1 or moves=1 then jump(4,5,6)
if t=16 or show=1 or moves=1 then jump(4,9,16)
end if
'====== logic for btn 5
if selbtn=5 then
if t=17 or show=1 or moves=1 then jump(5,10,17)
end if
'====== logic for btn 6
if selbtn=6 then
if t=4 or show=1 or moves=1 then jump(6,5,4)
if t=18 or show=1 or moves=1 then jump(6,11,18)
end if
'====== logic for btn 7
if selbtn=7 then
if t=9 or show=1 or moves=1 then jump(7,8,9)
if t=21 or show=1 or moves=1 then jump(7,14,21)
end if
'====== logic for btn 8
if selbtn=8 then
if t=10 or show=1 or moves=1 then jump(8,9,10)
if t=22 or show=1 or moves=1 then jump(8,15,22)
end if
'====== logic for btn 9
if selbtn=9 then
if t=1 or show=1 or moves=1 then jump(9,4,1)
if t=11 or show=1 or moves=1 then jump(9,10,11)
if t=7 or show=1 or moves=1 then jump(9,8,7)
if t=23 or show=1 or moves=1 then jump(9,16,23)
end if
'====== logic for btn 10
if selbtn=10 then
if t=8 or show=1 or moves=1 then jump(10,9,8)
if t=2 or show=1 or moves=1 then jump(10,5,2)
if t=12 or show=1 or moves=1 then jump(10,11,12)
if t=24 or show=1 or moves=1 then jump(10,17,24)
end if
'====== logic for btn 11
if selbtn=11 then
if t=13 or show=1 or moves=1 then jump(11,12,13)
if t=3 or show=1 or moves=1 then jump(11,6,3)
if t=9 or show=1 or moves=1 then jump(11,10,9)
if t=25 or show=1 or moves=1 then jump(11,18,25)
end if
'====== logic for btn 12
if selbtn=12 then
if t=10 or show=1 or moves=1 then jump(12,11,10)
if t=26 or show=1 or moves=1 then jump(12,19,26)
end if
'====== logic for btn 13
if selbtn=13 then
if t=11 or show=1 or moves=1 then jump(13,12,11)
if t=27 or show=1 or moves=1 then jump(13,20,27)
end if
'====== logic for btn 14
if selbtn=14 then
if t=16 or show=1 or moves=1 then jump(14,15,16)
end if
'====== logic for btn 15
if selbtn=15 then
if t=17 or show=1 or moves=1 then jump(15,16,17)
end if
'====== logic for btn 16
if selbtn=16 then
if t=14 or show=1 or moves=1 then jump(16,15,14)
if t=4 or show=1 or moves=1 then jump(16,9,4)
if t=18 or show=1 or moves=1 then jump(16,17,18)
if t=28 or show=1 or moves=1 then jump(16,23,28)
end if
'====== logic for btn 17
if selbtn=17 then
if t=19 or show=1 or moves=1 then jump(17,18,19)
if t=15 or show=1 or moves=1 then jump(17,16,15)
if t=5 or show=1 or moves=1 then jump(17,10,5)
if t=29 or show=1 or moves=1 then jump(17,24,29)
end if
'====== logic for btn 18
if selbtn=18 then
if t=20 or show=1 or moves=1 then jump(18,19,20)
if t=16 or show=1 or moves=1 then jump(18,17,16)
if t=6 or show=1 or moves=1 then jump(18,11,6)
if t=30 or show=1 or moves=1 then jump(18,25,30)
end if
'====== logic for btn 19
if selbtn=19 then
if t=17 or show=1 or moves=1 then jump(19,18,17)
end if
'====== logic for btn 20
if selbtn=20 then
if t=18 or show=1 or moves=1 then jump(20,19,18)
end if
'====== logic for btn 21
if selbtn=21 then
if t=23 or show=1 or moves=1 then jump(21,22,23)
if t=7 or show=1 or moves=1 then jump(21,14,7)
end if
'====== logic for btn 22
if selbtn=22 then
if t=24 or show=1 or moves=1 then jump(22,23,24)
if t=8 or show=1 or moves=1 then jump(22,15,8)
end if
'====== logic for btn 23
if selbtn=23 then
if t=25 or show=1 or moves=1 then jump(23,24,25)
if t=21 or show=1 or moves=1 then jump(23,22,21)
if t=9 or show=1 or moves=1 then jump(23,16,9)
if t=31 or show=1 or moves=1 then jump(23,28,31)
end if
'====== logic for btn 24
if selbtn=24 then
if t=26 or show=1 or moves=1 then jump(24,25,26)
if t=22 or show=1 or moves=1 then jump(24,23,22)
if t=10 or show=1 or moves=1 then jump(24,17,10)
if t=32 or show=1 or moves=1 then jump(24,29,32)
end if
'====== logic for btn 25
if selbtn=25 then
if t=27 or show=1 or moves=1 then jump(25,26,27)
if t=23 or show=1 or moves=1 then jump(25,24,23)
if t=11 or show=1 or moves=1 then jump(25,18,11)
if t=33 or show=1 or moves=1 then jump(25,30,33)
end if
'====== logic for btn 26
if selbtn=26 then
if t=24 or show=1 or moves=1 then jump(26,25,24)
if t=12 or show=1 or moves=1 then jump(26,19,12)
end if
'====== logic for btn 27
if selbtn=27 then
if t=25 or show=1 or moves=1 then jump(27,26,25)
if t=13 or show=1 or moves=1 then jump(27,20,13)
end if
'====== logic for btn 28
if selbtn=28 then
if t=30 or show=1 or moves=1 then jump(28,29,30)
if t=16 or show=1 or moves=1 then jump(28,23,16)
end if
'====== logic for btn 29
if selbtn=29 then
if t=17 or show=1 or moves=1 then jump(29,24,17)
end if
'====== logic for btn 30
if selbtn=30 then
if t=28 or show=1 or moves=1 then jump(30,29,28)
if t=18 or show=1 or moves=1 then jump(30,25,18)
end if
'====== logic for btn 31
if selbtn=31 then
if t=33 or show=1 or moves=1 then jump(31,32,33)
if t=23 or show=1 or moves=1 then jump(31,28,23)
end if
'====== logic for btn 32
if selbtn=32 then
if t=24 or show=1 or moves=1 then jump(32,29,24)
end if
'====== logic for btn 33
if selbtn=33 then
if t=25 or show=1 or moves=1 then jump(33,30,25)
if t=31 or show=1 or moves=1 then jump(33,32,31)
end if
return
'===============
checkifmovesleft:
'===============
moves=1 'check move flag on
movesleft=0
for selbtn=1 to 33 'checl all buttons
gosub checkandmove
next selbtn
moves=0 'turn off flag
'if no moves left, game over
if movesleft= 0 then
'count how many left
bc=0
for b=1 to 33
if bv$(b)=x$ then bc=bc+1
next b
'show number
set buttons font size 36*rw
draw color 1,1,1
fill color 0,0,1
if bc>1 then
tx$=str$(bc)&" left. Not bad."
else
tx$=str$(bc)&" left. Awesome!"
end if
tl=text_width(tx$)
button "over" text tx$ at 260*rw,(sh/2-100)*rh
'notes set "111:h(d3fa)(dga#)(dfa)"
'notes play ! pause 3
button "over" delete
goto restart
end if
return
def jump(s,j,d)
'This little function reduced code size 40%.
'Does the jump if possible, and alters button array data.
'If show flag on, just highlight button instead.
'If moves flag on, see if move possible, but dont move.
's=first selected button
'j=button to jump over
'd=destination button
if .moves=1 then
if .bv$(s)=.x$ and .bv$(j)=.x$ and .bv$(d)=.o$ then
.movesleft=1 ! return
end if
end if
if .bv$(j)=.x$ then
if .show=1 then
if .bv$(d)=.o$ then but(d)
end if
if .show=0 and .moves=0 then
.bv$(s)=.o$!.bv$(j)=.o$!.bv$(d)=.x$
if .sound=1 then
notes set "120:sa6"!notes play
end if
end if
end if
end def