Stringstar="«"
Stringcheck="ü"

colorfirst=1
colorlast=9

colorwrapup=colorfirst-1
colorwrapdown=colorlast+1
colors=strcat(colorwrapup,"|",colorwrapdown)  ; one extra in each direction for wrap
colorcount=colorlast
;colornames="white red orange yellow green teal blue purple black"
colorcodes="192|192|192 255|0|0 255|128|0 255|255|0 0|192|0 0|255|192 0|0|255 255|0|255 0|0|0"
G1=2
G2=3
G3=4
G4=5
I="This is the game of StarCheck."
I=StrCat(I,@crlf,@crlf,"In this game you must deduce the color of 4 pegs by making guesses.")
I=StrCat(I,@crlf,@crlf,"For each guess where both the color and position of the peg is correct, you get a star.")
Instructions=StrCat(I,@crlf,@crlf,"If only the color is correct, then you get a check mark.")
Instructions2=StrCat("You have only 10 guesses to win.",@CRLF,@CRLF,"Good Luck!")

;proc constants
   InitDialog=0 
   DC_ButtonPressed= 2 ; some constant we define laters
   DC_SetTitle = 4
   DC_Spinner=10
   DC_ADDSTYLE=3
   DC_REMSTYLE=4
   GETSET_COLOR=11
   STYLE_INVISIBLE=1

#DefineSubroutine ResetGame()
   ;hide all the results
   for xx=10 to 59
      DialogControlState(MyDialogHandle,xx,DC_ADDSTYLE,STYLE_INVISIBLE)
   next
   Guessnum=0
   ;pick winning combo
   W1=Random(colorcount-1)+1
   W2=Random(colorcount-1)+1
   W3=Random(colorcount-1)+1
   W4=Random(colorcount-1)+1
   return(0)
#EndSubroutine


#DEFINESUBROUTINE DoItToIt(MyDialogHandle,MyDialogMessage,MyDialogControlID,param4,param5)
   switch MyDialogMessage

          case InitDialog   ; Init_Dialog  (case number 0 subject to change on implementation)
               DialogProcOptions(MyDialogHandle,DC_ButtonPressed,1)   ; enable buttonclicked messages
               DialogProcOptions(MyDialogHandle,DC_Spinner,1)   ; enable spinclicked messages
               ResetGame()
               return (-1)

          case DC_ButtonPressed
              switch MyDialogControlID
                 case 1     ;guess
                     ;work out indexes for current guess
                     b1=10+(Guessnum*5)
                     b2=b1+4

                     ;Set static colors
                     DialogControlSet(MyDialogHandle,b1+0,GETSET_COLOR,ItemExtract(G1,colorcodes," "))
                     DialogControlSet(MyDialogHandle,b1+1,GETSET_COLOR,ItemExtract(G2,colorcodes," "))
                     DialogControlSet(MyDialogHandle,b1+2,GETSET_COLOR,ItemExtract(G3,colorcodes," "))
                     DialogControlSet(MyDialogHandle,b1+3,GETSET_COLOR,ItemExtract(G4,colorcodes," "))

                     ;Set results visible
                     for xx=b1 to b2
                        DialogControlState(MyDialogHandle,xx,DC_REMSTYLE,STYLE_INVISIBLE)
                     next

                     ;Message(strcat(w1,w2,w3,w4),strcat(g1,g2,g3,g4))

                     ;score
                     stars=0
                     checks=0
                     for xx=1 to 4
                       C%xx%=W%xx%
                       D%xx%=G%xx%
                     next
                     ;check stars
                     for xx=1 to 4
                        if D%xx% == C%xx%
                           stars=stars+1
                           C%xx% = -2
                           D%xx% = -1
                        endif
                     next
                     ;check checks
                     for xx=1 to 4
                        for yy=1 to 4
                           if D%xx% == C%yy%
                              checks=checks+1
                              C%yy% = -2
                              D%xx% = -1

                           endif
                        next
                     next

                     ;Display Score
                     score=strcat(strfill(StringStar,stars),strfill(StringCheck,checks))
                     DialogControlSet(MyDialogHandle,b1+4,DC_SETTITLE,score)

                     ;did user win?
                     if w1==g1 && w2==g2 && w3==g3 && w4==g4
                        ;Message("Yay!","You Won")
                        ShowResults("You Won!",w1,w2,w3,w4,colorcodes)
                        ResetGame()
                        return(-2)
                     endif

                     ;did user lose (used up 10 guesses)
                     if guessnum==9
                        ;Message("Sorry","out of guesses")
                        ShowResults("You lost.",w1,w2,w3,w4,colorcodes)
                        ResetGame()
                        Return(-2)
                      endif

                     Guessnum=Guessnum+1
                   return(-2)
                 case 60    ;exit
                   return (-1)
              endswitch              
              return (-1

          case DC_Spinner
              val=DialogControlGet(MyDialogHandle,MyDialogControlID,8)
              if val==colorwrapup then val=colorlast
              if val==colorwrapdown then val=colorfirst
              DialogControlSet(MyDialogHandle,MyDialogControlID,8,val)
              colorcode=ItemExtract(val,colorcodes," ")
              DialogControlSet(MyDialoghandle,MyDialogControlID,11,colorcode)
              switch MyDialogControlID
                  case 6   ; the color spinner
                     G1=val
                     break
                  case 7   ; the color spinner
                     G2=val
                     break
                  case 8   ; the color spinner
                     G3=val
                     break
                  case 9   ; the color spinner
                     G4=val
                     break
               endswitch   ;DC_ButtonPressed
               return(-1)  ; do default processing


   endswitch ; MyDialogMessage
   Return(-1) ; Do default processing#EndFunction
#ENDSUBROUTINE
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
#DefineSubroutine ShowResults(msg,r1,r2,r3,r4,colorcodes)
r1c=ItemExtract(r1,colorcodes," ")
r2c=ItemExtract(r2,colorcodes," ")
r3c=ItemExtract(r3,colorcodes," ")
r4c=ItemExtract(r4,colorcodes," ")
ResultsFormat=`WWWDLGED,6.1`

ResultsCaption=msg
ResultsX=-01
ResultsY=-01
ResultsWidth=116
ResultsHeight=096
ResultsNumControls=007
ResultsProcedure=`DEFAULT`
ResultsFont=`DEFAULT`
ResultsTextColor=`DEFAULT`
ResultsBackground=`DEFAULT,128|255|255`

Results001=`038,078,033,010,PUSHBUTTON,DEFAULT,"OK",1,1,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
Results002=`014,007,090,024,VARYTEXT,msg,"You lost.",DEFAULT,3,DEFAULT,"Microsoft Sans Serif|16384|70|34","0|0|0","128|255|255"`
Results003=`010,038,094,028,GROUPBOX,DEFAULT,"Winning Combination",DEFAULT,2,DEFAULT,"Microsoft Sans Serif|6963|70|34","0|0|0","128|255|255"`
Results004=`018,050,009,009,STATICTEXT,DEFAULT,"",DEFAULT,4,DEFAULT,DEFAULT,DEFAULT,%r1c%`
Results005=`039,050,009,009,STATICTEXT,DEFAULT,"",DEFAULT,4,DEFAULT,DEFAULT,DEFAULT,%r2c%`
Results006=`060,050,009,009,STATICTEXT,DEFAULT,"",DEFAULT,4,DEFAULT,DEFAULT,DEFAULT,%r3c%`
Results007=`081,050,009,009,STATICTEXT,DEFAULT,"",DEFAULT,4,DEFAULT,DEFAULT,DEFAULT,%r4c%`

ButtonPushed=Dialog("Results")




#EndSubroutine

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


StarCheckFormat=`WWWDLGED,6.1`

StarCheckCaption=`StarCheck`
StarCheckX=-01
StarCheckY=-01
StarCheckWidth=352
StarCheckHeight=215
StarCheckNumControls=061 
StarCheckProcedure=`DoItToIt`
StarCheckFont=`Microsoft Sans Serif|6144|70|34`
StarCheckTextColor=`0|0|128`
StarCheckBackground=`DEFAULT,128|255|255`

StarCheck001=`258,018,059,013,PUSHBUTTON,DEFAULT,"Guess",1,1,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
StarCheck002=`006,006,098,191,GROUPBOX,DEFAULT,"StarCheck Instructions",DEFAULT,2,DEFAULT,"Microsoft Sans Serif|8192|70|34","0|0|128","128|255|255"`
StarCheck003=`126,006,199,031,GROUPBOX,DEFAULT,"Current Guess",DEFAULT,3,DEFAULT,DEFAULT,DEFAULT,"128|255|255"`
StarCheck004=`126,044,199,153,GROUPBOX,DEFAULT,"Results",DEFAULT,4,DEFAULT,DEFAULT,DEFAULT,"128|255|255"`
StarCheck005=`014,022,086,120,VARYTEXT,Instructions,"Blah Blah and then balh before tou balh the balh and then you",DEFAULT,5,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
StarCheck006=`135,017,022,015,SPINNER,colors,"2",DEFAULT,6,DEFAULT,"Microsoft Sans Serif|1000|40|34","128|128|128","255|0|0"`
StarCheck007=`166,017,022,015,SPINNER,colors,"3",DEFAULT,7,DEFAULT,"Microsoft Sans Serif|1000|40|34","128|128|128","255|128|0"`
StarCheck008=`196,017,022,015,SPINNER,colors,"4",DEFAULT,8,DEFAULT,"Microsoft Sans Serif|1000|40|34","128|128|128","255|255|0"`
StarCheck009=`225,017,022,015,SPINNER,colors,"5",DEFAULT,9,DEFAULT,"Microsoft Sans Serif|1000|40|34","128|128|128","0|192|0"`
StarCheck010=`135,055,009,009,STATICTEXT,DEFAULT,".",DEFAULT,10,DEFAULT,DEFAULT,DEFAULT,"255|128|64"`
StarCheck011=`166,055,009,009,STATICTEXT,DEFAULT,".",DEFAULT,10,DEFAULT,DEFAULT,DEFAULT,"255|128|64"`
StarCheck012=`196,055,009,009,STATICTEXT,DEFAULT,".",DEFAULT,10,DEFAULT,DEFAULT,DEFAULT,"255|128|64"`
StarCheck013=`225,055,009,009,STATICTEXT,DEFAULT,".",DEFAULT,10,DEFAULT,DEFAULT,DEFAULT,"255|128|64"`
StarCheck014=`262,055,070,011,VARYTEXT,Score1,"",DEFAULT,14,DEFAULT,"Wingdings|9000|70|514","0|0|0",DEFAULT`
StarCheck015=`135,068,009,009,STATICTEXT,DEFAULT,".",DEFAULT,10,DEFAULT,DEFAULT,DEFAULT,"255|128|64"`
StarCheck016=`166,068,009,009,STATICTEXT,DEFAULT,".",DEFAULT,10,DEFAULT,DEFAULT,DEFAULT,"255|128|64"`
StarCheck017=`196,068,009,009,STATICTEXT,DEFAULT,".",DEFAULT,10,DEFAULT,DEFAULT,DEFAULT,"255|128|64"`
StarCheck018=`225,068,009,009,STATICTEXT,DEFAULT,".",DEFAULT,10,DEFAULT,DEFAULT,DEFAULT,"255|128|64"`
StarCheck019=`262,068,070,011,VARYTEXT,Score2,"",DEFAULT,14,DEFAULT,"Wingdings|9000|70|514","0|0|0",DEFAULT`
StarCheck020=`135,081,009,009,STATICTEXT,DEFAULT,".",DEFAULT,10,DEFAULT,DEFAULT,DEFAULT,"255|128|64"`
StarCheck021=`166,081,009,009,STATICTEXT,DEFAULT,".",DEFAULT,10,DEFAULT,DEFAULT,DEFAULT,"255|128|64"`
StarCheck022=`196,081,009,009,STATICTEXT,DEFAULT,".",DEFAULT,10,DEFAULT,DEFAULT,DEFAULT,"255|128|64"`
StarCheck023=`225,081,009,009,STATICTEXT,DEFAULT,".",DEFAULT,10,DEFAULT,DEFAULT,DEFAULT,"255|128|64"`
StarCheck024=`262,081,070,011,VARYTEXT,Score3,"",DEFAULT,14,DEFAULT,"Wingdings|9000|70|514","0|0|0",DEFAULT`
StarCheck025=`135,094,009,009,STATICTEXT,DEFAULT,".",DEFAULT,10,DEFAULT,DEFAULT,DEFAULT,"255|128|64"`
StarCheck026=`166,094,009,009,STATICTEXT,DEFAULT,".",DEFAULT,10,DEFAULT,DEFAULT,DEFAULT,"255|128|64"`
StarCheck027=`196,094,009,009,STATICTEXT,DEFAULT,".",DEFAULT,10,DEFAULT,DEFAULT,DEFAULT,"255|128|64"`
StarCheck028=`225,094,009,009,STATICTEXT,DEFAULT,".",DEFAULT,10,DEFAULT,DEFAULT,DEFAULT,"255|128|64"`
StarCheck029=`262,094,070,011,VARYTEXT,Score4,"",DEFAULT,14,DEFAULT,"Wingdings|9000|70|514","0|0|0",DEFAULT`
StarCheck030=`135,108,009,009,STATICTEXT,DEFAULT,".",DEFAULT,10,DEFAULT,DEFAULT,DEFAULT,"255|128|64"`
StarCheck031=`166,108,009,009,STATICTEXT,DEFAULT,".",DEFAULT,10,DEFAULT,DEFAULT,DEFAULT,"255|128|64"`
StarCheck032=`196,108,009,009,STATICTEXT,DEFAULT,".",DEFAULT,10,DEFAULT,DEFAULT,DEFAULT,"255|128|64"`
StarCheck033=`225,108,009,009,STATICTEXT,DEFAULT,".",DEFAULT,10,DEFAULT,DEFAULT,DEFAULT,"255|128|64"`
StarCheck034=`262,108,070,011,VARYTEXT,Score5,"",DEFAULT,14,DEFAULT,"Wingdings|9000|70|514","0|0|0",DEFAULT`
StarCheck035=`135,121,009,009,STATICTEXT,DEFAULT,".",DEFAULT,10,DEFAULT,DEFAULT,DEFAULT,"255|128|64"`
StarCheck036=`166,121,009,009,STATICTEXT,DEFAULT,".",DEFAULT,10,DEFAULT,DEFAULT,DEFAULT,"255|128|64"`
StarCheck037=`196,121,009,009,STATICTEXT,DEFAULT,".",DEFAULT,10,DEFAULT,DEFAULT,DEFAULT,"255|128|64"`
StarCheck038=`225,121,009,009,STATICTEXT,DEFAULT,".",DEFAULT,10,DEFAULT,DEFAULT,DEFAULT,"255|128|64"`
StarCheck039=`262,121,070,011,VARYTEXT,Score6,"",DEFAULT,14,DEFAULT,"Wingdings|9000|70|514","0|0|0",DEFAULT`
StarCheck040=`135,134,009,009,STATICTEXT,DEFAULT,".",DEFAULT,10,DEFAULT,DEFAULT,DEFAULT,"255|128|64"`
StarCheck041=`166,134,009,009,STATICTEXT,DEFAULT,".",DEFAULT,10,DEFAULT,DEFAULT,DEFAULT,"255|128|64"`
StarCheck042=`196,134,009,009,STATICTEXT,DEFAULT,".",DEFAULT,10,DEFAULT,DEFAULT,DEFAULT,"255|128|64"`
StarCheck043=`225,134,009,009,STATICTEXT,DEFAULT,".",DEFAULT,10,DEFAULT,DEFAULT,DEFAULT,"255|128|64"`
StarCheck044=`262,134,070,011,VARYTEXT,Score7,"",DEFAULT,14,DEFAULT,"Wingdings|9000|70|514","0|0|0",DEFAULT`
StarCheck045=`135,146,009,009,STATICTEXT,DEFAULT,".",DEFAULT,10,DEFAULT,DEFAULT,DEFAULT,"255|128|64"`
StarCheck046=`166,146,009,009,STATICTEXT,DEFAULT,".",DEFAULT,10,DEFAULT,DEFAULT,DEFAULT,"255|128|64"`
StarCheck047=`196,146,009,009,STATICTEXT,DEFAULT,".",DEFAULT,10,DEFAULT,DEFAULT,DEFAULT,"255|128|64"`
StarCheck048=`225,146,009,009,STATICTEXT,DEFAULT,".",DEFAULT,10,DEFAULT,DEFAULT,DEFAULT,"255|128|64"`
StarCheck049=`262,146,070,011,VARYTEXT,Score8,"",DEFAULT,14,DEFAULT,"Wingdings|9000|70|514","0|0|0",DEFAULT`
StarCheck050=`135,159,009,009,STATICTEXT,DEFAULT,".",DEFAULT,10,DEFAULT,DEFAULT,DEFAULT,"255|128|64"`
StarCheck051=`166,159,009,009,STATICTEXT,DEFAULT,".",DEFAULT,10,DEFAULT,DEFAULT,DEFAULT,"255|128|64"`
StarCheck052=`196,159,009,009,STATICTEXT,DEFAULT,".",DEFAULT,10,DEFAULT,DEFAULT,DEFAULT,"255|128|64"`
StarCheck053=`225,159,009,009,STATICTEXT,DEFAULT,".",DEFAULT,10,DEFAULT,DEFAULT,DEFAULT,"255|128|64"`
StarCheck054=`262,159,070,011,VARYTEXT,Score9,"",DEFAULT,14,DEFAULT,"Wingdings|9000|70|514","0|0|0",DEFAULT`
StarCheck055=`135,172,009,009,STATICTEXT,DEFAULT,".",DEFAULT,10,DEFAULT,DEFAULT,DEFAULT,"255|128|64"`
StarCheck056=`166,172,009,009,STATICTEXT,DEFAULT,".",DEFAULT,10,DEFAULT,DEFAULT,DEFAULT,"255|128|64"`
StarCheck057=`196,172,009,009,STATICTEXT,DEFAULT,".",DEFAULT,10,DEFAULT,DEFAULT,DEFAULT,"255|128|64"`
StarCheck058=`225,172,009,009,STATICTEXT,DEFAULT,".",DEFAULT,10,DEFAULT,DEFAULT,DEFAULT,"255|128|64"`
StarCheck059=`262,172,070,011,VARYTEXT,Score10,"",DEFAULT,14,DEFAULT,"Wingdings|9000|70|514","0|0|0",DEFAULT`
StarCheck060=`326,202,022,010,PUSHBUTTON,DEFAULT,"Exit",0,60,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
StarCheck061=`014,130,086,50,VARYTEXT,Instructions2,"Blah Blah and then balh before tou balh the balh and then you",DEFAULT,5,DEFAULT,DEFAULT,DEFAULT,DEFAULT`

ButtonPushed=Dialog("StarCheck")



