remstart
   ==============================================================
   =  Title  : Hangman
   =  Author : Latch
   =  Date   : 02/05/2009
   =  Update :
   =  Version: .01
   ==============================================================
   Comments
   ==============================================================
remend
 
rem =============================================================
rem = SET UP DISPLAY
rem =============================================================
   autocam off
   set display mode 800,600,32
   sync on
   sync rate 60
   hide mouse
 
rem =============================================================
rem = MAIN
rem =============================================================
_main:
   cls 128
   gosub _make_victim
   gosub _read_puzzle
   newgame=1
 
   do
      if newgame=1
         gosub _choose_puzzle
         newgame=0
      endif
 
      gosub _make_boxes
 
      sync
   loop
 
   end
 
rem =============================================================
rem = SUBROUTINES - PROCEDURES
rem =============================================================
   _make_victim:
      make object sphere 1,27
      make object box 2,10,60,10
      make mesh from object 2,2
      add limb 1,1,2
      offset limb 1,1,0,-30-12,0
      delete object 2
      delete mesh 2
      make object box 2,5,30,5
      offset limb 2,0,0,-15,0
      make mesh from object 2,2
      delete object 2
      make object 2,2,0
      delete mesh 2
      make mesh from object 2,2
      add limb 1,2,2
      offset limb 1,2,-5,-20,0
      rotate limb 1,2,0,0,wrapvalue(-50)
      add limb 1,3,2
      offset limb 1,3,5,-20,0
      rotate limb 1,3,0,0,wrapvalue(50)
      add limb 1,4,2
      offset limb 1,4,-5,-70,0
      rotate limb 1,4,0,0,wrapvalue(-50)
      add limb 1,5,2
      offset limb 1,5,5,-70,0
      rotate limb 1,5,0,0,wrapvalue(50)
      delete mesh 2
      delete object 2
 
      for lb=0 to 5
         hide limb 1,lb
      next lb
 
      position camera -60,-50,-200
   return
`----------------------------------------------------------------
   _read_puzzle:
      ct=110
      maxc=255
      dim puzzle(ct,maxc)
      randomize 15
      for p=1 to ct
         read a
         for n=1 to a
            variance=rnd(31)
            read puzzle(p,n)
            puzzle(p,n)=puzzle(p,n)+variance
         next n
      next p
      randomize timer()
   return
`----------------------------------------------------------------
   _choose_puzzle:
      p=rnd(ct-1)+1
      for n=1 to maxc
         if puzzle(p,n)=0 then exit
      next n
      psize=n-1
      dim guessed(psize)
      set text transparent
      set text font "courier new",1
      set text size 36
      sync
      wd=text width("Q")
      ht=text height("gM")
      dim alphabet(26)
      acount=0
      strikes=0
   return
`----------------------------------------------------------------
   _make_boxes:
      ink rgb(255,255,255),0
      for b=1 to psize
         rem check for spaces and don't draw a box
         if puzzle(p,b)<>32
            line (b*wd)+1,51+ht,(b*wd)+wd-2,51+ht
         endif
         if puzzle(p,b)=39 or puzzle(p,b)=32 then guessed(b)=1
         if guessed(b)
            text b*wd,50,chr$(puzzle(p,b))
         endif
      next b
      set text font "arial",1
      set text size 20
      text 0,0,"Chosen Letters : "
      for a=1 to acount
         text 120+a*wd,0,chr$(alphabet(a))
      next acount
 
      gosub _guess
   return
`----------------------------------------------------------------
   _guess:
      backdrop off
      ink rgb(255,255,0),0
 
      sync
      text 0,160,"Type a letter key to make a guess"
      text 0,200,"Press"
      set text opaque
      text text width("Press "),200,"ENTER"
      set text transparent
      text text width("Press ENTER "),200,"to solve puzzle"
 
      rem check for keypresses
      letter=asc(upper$(inkey$()))
 
      rem stop key repeat
      ok=nk
      nk=keystate(scancode())
 
      rem a regular entry, first check that it is alpha
      if letter > 64 and letter < 91
         sum=0
 
         rem key repeat check
         if nk > ok
 
            rem add letter to chosen letter list
            inc acount
            for a=1 to acount
               if alphabet(a)=letter
                  dec acount
                  letterhit=1
                  exit
               endif
            next a
            if letterhit=1
               letterhit=0
            else
               alphabet(acount)=letter
            endif
 
            rem test guess
            for n=1 to psize
               if puzzle(p,n)=letter
                  guessed(n)=1
                  nostrike=1
               endif
               rem check for a win
               sum=sum+guessed(n)
               if sum=psize then goto _win
            next n
            rem show the hangman
            if nostrike ! 1
               inc strikes
               show limb 1,strikes-1
               if strikes=6 then goto _lose
            endif
            nostrike=0
         endif
      endif
 
      rem check for return key
      if letter=13
         ink rgb(255,255,0),128
         text 0,240,"CAREFULLY type the solution to the puzzle and press ENTER"
         set cursor 0,280
         repeat
            sync
         until scancode()=0
         input ">>> ";sol$
         sol$=upper$(sol$)
         a$=""
         for n=1 to psize
            a$=a$+chr$(puzzle(p,n))
         next n
         if sol$=a$
            gosub _win
         else
            gosub _lose
         endif
      endif
 
      set text transparent
      set text font "courier new",1
      set text size 36
      backdrop on
 
   return
`----------------------------------------------------------------
   _win:
      cls 0
      repeat
         text 0,0,"You WIN!!!"
         text 0,20,"Play Again? (Y/N)"
         result$=upper$(inkey$())
         sync
      until result$="Y" or result$="N"
 
      if result$="Y"
         for lb=0 to 5
            hide limb 1,lb
         next lb
         cls 128
         goto _choose_puzzle
      endif
      end
   return
`----------------------------------------------------------------
   _lose:
      cls 0
      repeat
         text 0,0,"You lose"
         text 0,20,"Play Again? (Y/N)"
         result$=upper$(inkey$())
         sync
      until result$="Y" or result$="N"
 
      if result$="Y"
         for lb=0 to 5
            hide limb 1,lb
         next lb
         cls 128
         goto _choose_puzzle
      endif
      end
   return
 
 
rem =============================================================
rem = FUNCTIONS
rem =============================================================
 
rem =============================================================
rem = DATA STATEMENTS
rem =============================================================
data 8,46,59,53,54,51,55,66,60
data 10,55,56,59,45,60,55,71,49,65,71
data 10,42,49,62,61,43,47,39,73,38,69
data 10,66,72,63,73,75,59,74,47,63,66
data 6,56,62,73,70,69,75
data 8,61,58,46,64,35,66,53,40
data 9,56,59,62,67,57,36,71,56,40
data 24,64,65,63,24,75,73,65,1,50,44,59,45,56,51,11,69,42,24,54,54,76,68,68,82
data 6,54,70,48,59,60,67
data 41,56,3,38,73,51,53,28,61,64,21,56,70,49,32,68,50,54
data 56,10,47,56,3,65,78,70,62,62,27,57,67,67,23,57,61,2,42,3,57,55,79,55
data 7,57,46,48,17,51,73,66
data 8,47,64,66,41,74,51,66,69
data 18,76,52,65,67,20,69,63,23,70,71,49,84,26,52,73,46,71,51
data 32,62,41,50,59,56,68,17,37,82,70,76,42,69,23,51
data 75,64,11,51,63,70,67,77,13,58,62,74,43,87,61,48,61
data 3,56,50,41
data 14,75,49,62,48,44,25,89,56,84,81,65,38,65,41
data 5,42,77,78,65,52
data 11,52,63,66,65,39,2,63,62,79,43,67
data 9,80,81,37,65,30,69,55,51,60
data 9,54,49,78,75,84,13,47,64,58
data 6,83,70,70,74,71,50
data 26,64,52,53,49,58,47,55,79,50,26,57,57,47,62,18,66,44,57,26,78,42,65,73,49,53,84
data 21,66,27,50,62,21,65,48,70,56,4,75,71,54,14,42,17,55,51,60,72,61
data 5,68,52,80,64,87
data 20,84,56,58,57,21,67,82,7,69,54,7,78,70,82,76,6,47,62,62,68
data 10,47,82,53,82,43,82,56,61,66,76
data 8,76,64,62,59,74,47,58,77
data 10,47,48,78,70,60,77,81,50,66,49
data 12,57,72,61,42,57,67,47,71,58,45,59,76
data 4,73,68,67,84
data 4,54,49,61,66
data 8,56,58,57,55,63,57,50,83
data 9,70,58,65,55,40,56,65,79,77
data 34,56,49,40,67,43,28,65,53,45,68,53,25,60,30,39
data 8,59,65,62,61,1,81,57,46,77,45,10,83,18,47,22,80,49,84
data 4,65,85,73,62
data 7,68,55,55,54,66,73,65
data 10,55,75,62,59,49,46,56,58,74,62
data 9,65,85,51,40,69,72,58,62,80
data 12,65,69,47,54,69,77,23,60,64,57,45,38
data 13,49,79,61,47,48,79,18,56,54,38,53,64,60
data 19,53,45,7,57,71,69,74,27,55,73,55,44,62,55,57,66,73,62,67
data 11,60,48,59,45,61,63,63,54,43,61,76
data 6,60,55,53,52,38,42
data 14,58,77,58,60,49,62,19,57,67,65,71,64,61,72
data 24,76,55,60,55,58,46,27,59,74,64,77,65,64,27,79,63,4,53,75,41,69,55,57,36
data 5,36,48,73,78,61
data 8,38,54,69,63,57,61,54,43
data 6,69,66,57,58,62,78
data 5,59,59,61,50,69
data 4,51,47,52,61
data 7,75,44,46,67,45,53,67
data 8,34,78,49,46,59,71,68,60
data 8,34,76,42,57,52,59,67,56
data 7,55,58,35,60,60,57,66
data 10,46,40,67,46,46,59,53,61,68,51
data 9,56,58,62,53,65,60,48,70,60
data 6,50,51,51,62,68,48
data 3,73,64,49
data 12,49,61,68,45,54,48,66,13,68,54,69,53
data 11,58,79,83,14,60,67,23,75,80,45,68
data 13,66,48,64,66,12,60,54,66,25,63,47,38,42
data 17,56,66,58,64,20,47,80,3,62,61,74,57,17,55,48,48,69
data 17,66,61,41,52,62,18,66,55,12,63,73,57,1,53,47,55,44
data 26,57,68,34,59,5,55,76,17,71,70,66,61,1,39,44,79,77,72,50,63,42,8,68,57,60,68
data 5,50,42,63,65,38
data 4,45,45,59,66
data 10,34,80,78,75,38,53,56,79,64,41
data 11,43,70,57,75,71,49,36,59,45,48,78
data 13,49,42,57,60,58,30,42,63,48,70,59,63,65
data 4,51,46,64,56
data 11,65,62,71,50,66,56,55,57,61,43,70
data 5,60,41,57,40,70
data 9,60,58,45,81,52,72,63,42,52
data 30,62,52,19,65,69,41,76,45,3,48,32,65,55,52,63,63,69,2,69,59,15,75,52,60,3,43,57,71,71,51
data 7,62,62,65,56,72,63,63
data 13,50,59,45,72,80,46,73,73,61,52,45,40,62
data 44,81,45,52,43,30,81,56,79,12,64,71,75,71,52
data 44,53,72,16,65,72,64,24,48,64,47,72,23,47,63,26,58,70,15,79,57,52,7,75,59,75,74,43,62,62
data 7,72,69,58,60,60,73,49
data 8,60,76,70,56,52,44,50,58
data 20,46,68,74,59,18,43,66,75,44,81,19,78,45,55,20,73,79,41,42,63
data 12,68,42,54,45,34,61,8,77,59,64,47,47
data 5,68,59,78,61,37
data 11,49,49,59,59,69,65,46,79,57,54,60
data 9,75,66,47,65,82,52,60,39,52
data 11,71,71,73,62,53,62,49,74,67,81,58
data 7,82,50,66,49,45,58,68
data 27,44,56,69,42,23,75,78,66,25,55,56,66,74,61,44,24,61,72,82,78,12,37,48,65,70,53,68
data 6,50,73,37,54,71,67
data 9,62,58,53,59,65,69,65,57,63
data 7,60,42,65,52,62,67,69
data 16,54,70,76,43,32,76,66,41,4,69,50,58,66,68,49,67
data 13,75,42,55,27,48,44,81,53,27,73,61,56,41
data 10,54,47,64,52,72,67,64,57,70,44
data 7,83,75,54,63,58,59,61
data 11,67,43,58,80,56,62,56,87,62,70,68
data 8,74,51,75,65,59,48,82,51
data 14,62,65,40,44,76,68,51,66,32,72,72,73,83,56
data 5,63,37,56,81,49
data 4,70,48,72,74
data 4,78,47,82,85
data 10,56,53,72,76,42,53,65,64,42,68
data 13,69,65,58,52,73,58,82,77,67,59,65,56,60
data 4,56,73,58,62
data 8,60,45,70,64,45,77,40,69
data 4,60,59,50,47
data 7,83,82,61,73,61,57,43
data 5,66,85,73,59,65
data 5,49,73,52,71,62
data 5,66,66,56,62,78
data 3,83,63,81