simpele brein puzzel

Vragen en suggesties over het programmeren van spelletjes, sprites en dergelijke in Liberty BASIC

Moderator: anthonio

simpele brein puzzel

Berichtdoor bluatigro » do nov 06, 2014 3:00 pm

dit idee heb ik uit n oud [1960] boek

volgens de text kan je dit altijd in 6 zetten oplossen

Code: Selecteer alles
WindowWidth = DisplayWidth
WindowHeight = DisplayHeight
global winx , winy , tx , ty , tw , th , tkl , tnr
winx = WindowWidth
winy = WindowHeight
tx = 0
ty = 1
tw = 2
th = 3
tkl = 4
tnr = 5
sx = winx / 3
sy = winy / 3
dim p( 8 , 5 )
for i = 0 to 8
  y = 2 - int( i / 3 )
  x = i mod 3
  call createrect i,x*sx,y*sy,sx,sy,0,i+1
next i
for i = 0 to 100
  call change int( rnd(0) * 9 )
next i
menu #m , "game" _
        , "new game" , [new] _
        , "instructions" , [uitleg]
nomainwin
open "BRAIN TEESER" for graphics as #m
  #m "trapclose [quit]"
  #m "when characterInput [key]"
  #m "when leftButtonDown [leftdown]"
  #m "setfocus"
  #m "font Ariel 150 bold"
  for i = 0 to 8
    call drawrect i
  next i
wait
sub zet no
  select case no
    case 0
      call change 0
      call change 1
      call change 3
      call change 4
    case 1
      call change 0
      call change 1
      call change 2
    case 2
      call change 1
      call change 2
      call change 4
      call change 5
    case 3
      call change 0
      call change 3
      call change 6
    case 4
      call change 1
      call change 3
      call change 4
      call change 5
      call change 7
    case 5
      call change 2
      call change 5
      call change 8
    case 6
      call change 3
      call change 4
      call change 6
      call change 7
    case 7
      call change 6
      call change 7
      call change 8
    case 8
      call change 4
      call change 5
      call change 7
      call change 8
    case else
  end select
  for i = 0 to 8
    call drawrect i
  next i
end sub
[new]
  for i = 0 to 100
    dice = int( rnd(0) * 9 )
    call change dice
  next i
  for i = 0 to 8
    call drawrect i
  next i
wait
[uitleg]
  notice chr$( 13 ) _
  + "Welkome by Brain teeser ." + chr$( 13 ) _
  + "a simple game by bluatigro ." + chr$( 13 ) _
  + "Target :" + chr$( 13 ) _
  + "change all squares to yellow exept" + chr$( 13 ) _
  + "for the center one by clicking on them ."
wait
[key]
  key = val( right$( Inkey$ , 1 ) )
  if key <> 0 then
    call zet key - 1
  end if
wait
[leftdown]
  z = welke( MouseX , MouseY )
  if z >= 0 then
    call zet z
  end if
wait
[quit]
  close #m
end
sub createrect no , x , y , w , h , kl , nr
  p( no , tx ) = x
  p( no , ty ) = y
  p( no , tw ) = w + x
  p( no , th ) = h + y
  p( no , tkl ) = kl
  p( no , tnr ) = nr
end sub
sub change no
  p( no , tkl ) = 1 - p( no , tkl )
end sub
sub drawrect no
  if p( no , tkl ) = 0 then
    #m "color white"
    #m "backcolor blue"
  else
    #m "color black"
    #m "backcolor yellow"
  end if
  x1 = p( no , tx )
  y1 = p( no , ty )
  x2 = p( no , tw )
  y2 = p( no , th )
  nr = p( no , tnr )
  #m "goto " ; x1 ; " " ; y1
  #m "down"
  #m "boxfilled " ; x2 ; " " ; y2
  #m "up"
  #m "goto " ; x1+(x2-x1)/2 ; " " ; y1+(y2-y1)/2+50
  #m "down"
  #m "\" ; str$( nr )
  #m "up"
end sub
function welke( x , y )
  uit = -1
  for i = 0 to 8
    if x > p( i , tx ) and x < p( i , tw ) _
    and y > p( i , ty ) and y < p( i , th ) then
      uit = i
    end if
  next i
  welke = uit
end function
bluatigro
 
Berichten: 306
Geregistreerd: za sep 27, 2008 6:01 pm

Keer terug naar Games

Wie is er online

Gebruikers op dit forum: Geen geregistreerde gebruikers. en 1 gast

cron