be dominogame domino end be domino ; Domino v0.91 ; Developped by Hensley Bass ; Email: hbass@intnet.mu ; Url: http://pages.intnet.mu/jhbpage hideTurtle playing=0 ; catch "error [fullscreen] ; windowset "Commander 0 ;------------------------ Drawing the window windowdomino=(Frame [][Domino] wxDefault_Frame_Style+wxStay_on_Top [0 0][640 60]) FrameSetFontSize windowdomino 15 bexit=Button windowdomino [&Exit] [ ern [windowdomino] (GC true) setSC "white cS OnMouseLeftDown [] playing=0 ; windowset "Commander 1 ] babout=Button windowdomino [&About][domino::about] bhelp=Button windowdomino [&Help][domino::helpmessage] bsetup=Button windowdomino [&Setup] [ mydialog=(Frame windowdomino [Game setup] wxDefault_Frame_Style+wxStay_on_top [-1 -1][200 350]) FrameSetBackgroundColor mydialog [.9 .9 .8] domino::setupwindow ] bnewgame=Button windowdomino [&New Game][domino::startnewgame] bnewround=Button windowdomino [New &round][domino::startnewround] bpass=Button windowdomino [&Pass][domino::passbuttonpressed] bdraw=Button windowdomino [&Draw][domino::drawrandomdomino 1] ButtonEnable bdraw false boxs=BoxSizer wxHorizontal BoxSizerAdd boxs bexit 4 wxExpand 0 BoxSizerAdd boxs babout 5 wxExpand 0 BoxSizerAdd boxs bhelp 4 wxExpand 0 BoxSizerAdd boxs bsetup 5 wxExpand 0 BoxSizerAdd boxs bnewgame 8 wxExpand 0 BoxSizerAdd boxs bnewround 9 wxExpand 0 BoxSizerAdd boxs bpass 4 wxExpand 0 BoxSizerAdd boxs bdraw 4 wxExpand 0 FrameSetSizer windowdomino boxs ;-------------- Initial settings and preferences gamefinished=-1 numberofbones=10 variations="draw winningscore=100 highestdoublet=true maxbones=:numberofbones maxtile=:maxbones nomorebones=false arraydomino=[] startx=0 starty=0 bonesdrawn1=0 bonesdrawn2=0 bonesplayed1=0 bonesplayed2=0 player1=[] player2=[] total1=0 total2=0 bigtotal1=0 bigtotal2=0 tilesplayed=[] tpls=0 tprs=0 lx=0 ly=0 rx=0 ry=0 roundvariations=0 roundwinningscore=0 gamemode=0 xxx=0 yyy=0 pass=0 ;------------- Starting a new game startnewgame be startnewgame ; setbitindex 0 stopcontinue=true if :gamefinished == 0 [ if wxNo == (MessageBox [Game not finished. Do you want to start a new game?] [Domino v0.91] wxYes_No) [ stopcontinue=false ] ] if :stopcontinue == true [ bigtotal1=0 bigtotal2=0 playing=-1 gamefinished=0 maxbones=:numberofbones roundvariations=:variations roundwinningscore=:winningscore startnewround ] end be startnewround FrameEnable windowdomino false ButtonEnable bnewround false OnMouseLeftDown [] setScreenColor "forestgreen maxtile=:maxbones bonesdrawn1=0 bonesdrawn2=0 bonesplayed1=0 bonesplayed2=0 pass=0 setPenSize [1 1] initialise shuffle board lx=142 ly=-100 rx=142 ry=-100 lx=-62 ly=100 rx=0 ry=100 tilesplayed=(Array 112 -55) tpls=0 tprs=1 whoplays=1 gamemode=1 playing=-1 setLabelSize [30 30] setPC 0 PU setXY -310 -170 setH 90 Label [Player 1] setH 0 PU setXY -310 210 setH 90 Label [Player 2] setH 0 printScore -200 :bigtotal1 printScore 180 :bigtotal2 ;------------ If the player who has the highest doublet or highest value should start if :highestdoublet == true [ highestdoublet1=-1 highestvalue1=-1 hd1=-1 hv1=-1 for [i 1 :maxtile 1] [ temp=(mditem (Se :i 1) :player1) domino1=first (mditem (Se :temp 1) :arraydomino) domino2=last (mditem (Se :temp 1) :arraydomino) if :domino1 == :domino2 [ if (:domino1 + :domino2) > :highestdoublet1 [ highestdoublet1=(:domino1 + :domino2) hd1=:i ] ] if (:domino1 + :domino2) > :highestvalue1 [ highestvalue1=(:domino1 + :domino2) hv1=:i ] ] highestdoublet2=-1 highestvalue2=-1 hd2=-1 hv2=-1 for [i 1 :maxtile 1] [ temp=(mditem (Se :i 1) :player2) domino1=first (mditem (Se :temp 1) :arraydomino) domino2=last (mditem (Se :temp 1) :arraydomino) if :domino1 == :domino2 [ if (:domino1 + :domino2) > :highestdoublet2 [ highestdoublet2=(:domino1 + :domino2) hd2=:i ] ] if (:domino1 + :domino2) > :highestvalue2 [ highestvalue2=(:domino1 + :domino2) hv2=:i ] ] ;----------- Player 1 has the highest doublet and should play if :highestdoublet1 > :highestdoublet2 [ message [player 1 starts] playerplays 1 :hd1 1 ] ;----------- Player 2 has the highest doublet and should play if :highestdoublet2 > :highestdoublet1 [ message [player 2 starts] playerplays 2 :hd2 1 computerplayed=true pass=0 ButtonEnable bpass true OnMouseLeftDown [domino::getmousemove -1] OnMouseRightDown [domino::getmousemove 1] ] if (and (:highestdoublet2 <0) (:highestdoublet1 < 0)) [ if :highestvalue1 == :highestvalue2 [ whostarts=(random 2) + 1 if :whostarts == 1 [ hv2=-1 highestvalue2=-1] if :whostarts == 2 [ hv1=-1 highestvalue1=-1] ] if :highestvalue1 > :highestvalue2 [ message [player 1 starts] playerplays 1 :hv1 1 ] if :highestvalue2 > :highestvalue1 [ message [player 2 starts] playerplays 2 :hv2 1 computerplayed=true pass=0 ButtonEnable bpass true OnMouseLeftDown [domino::getmousemove -1] OnMouseRightDown [domino::getmousemove 1] ] ] ] ifElse :roundvariations == "draw [ ButtonEnable bdraw true ButtonEnable bpass false nomorebones=false ][ nomorebones=true ButtonEnable bdraw false ] FrameEnable windowdomino true end be initialise FrameEnable windowdomino false arraydomino=(mdarray [28 2] 1) counter=0 for [i 7 0 -1] [ start=:i - 1 for [j :start 0 -1] [ counter=:counter + 1 mdsetitem (Se :counter 1) :arraydomino (Se :i - 1 :j) mdsetitem (Se :counter 2) :arraydomino 0 ] ] FrameEnable windowdomino true end be shuffle ;------------ Procedure that redistributes the bones at random to the player player1=(mdarray (Se :maxtile 2) 1) player2=(mdarray (Se :maxtile 2) 1) initPlayer player1 initPlayer player2 end be initPlayer player counter=0 while [counter < maxtile] [ randomdraw=(random 28) + 1 if (mditem (Se randomdraw 2) arraydomino) == 0 [ counter=:counter + 1 mdsetitem (Se randomdraw 2) arraydomino -1 mdsetitem (Se counter 1) player randomdraw mdsetitem (Se counter 2) player 0 ] ] end be board FrameEnable windowdomino false ;--------------- Procedure to draw the playing board startx=-350 starty=-220 drawbase 150 0 1 :bonesdrawn1 drawbase 150 370 2 :bonesdrawn2 FrameEnable windowdomino true end be drawbase :xx :yy :dbplayer :db FrameEnable windowdomino false x1=:startx+:xx y1=:starty+:yy setH 0 PU setXY :x1-5 :y1+5 PPt xxx=first Pos yyy=last Pos if :dbplayer == 1 [ maxloop=(:maxtile+:bonesdrawn1) repeat :maxloop [ PU setXY (:xxx+(repCount-1)*33) :yyy drawtile (mditem (Se repCount 1) :player1) 0 30 0 0 ] ] if :dbplayer == 2 [ maxloop=(:maxtile+:bonesdrawn2) repeat :maxloop [ PU setXY (:xxx+(repCount-1)*33) :yyy PPt setH 0 setPC [1 1 .8] PolyStart repeat 2 [ fd 60 rt 90 fd 30 rt 90] PolyEnd setPC 0 repeat 2 [ fd 60 rt 90 fd 30 rt 90] ] ] PU setXY :x1 :y1 PPt setPC 0 FrameEnable windowdomino true end be drawtile :tile :xval :yval :h :orient FrameEnable windowdomino false setPC [0 0 0] xx=first Pos yy=last Pos setH :orient leftside=first mditem (Se :tile 1) :arraydomino draw :leftside :h PU setXY :xx + :xval :yy + :yval PPt setH :orient rightside=last mditem (Se :tile 1) :arraydomino draw rightside h PU FrameEnable windowdomino true end be drawPoint x y local [p] p=Pos fd 9*y rt 90 fd 9*x lt 90 PenDown fillCircle 4 circle 4 PenUp setPos p end be draw0 :h PU if :h == 90 [ fd 30 rt 90] PD setPC [1 1 .8] PolyStart repeat 4 [ fd 30 rt 90] PolyEnd setPC 0 repeat 4 [ fd 30 rt 90] PU rt 90 fd 15 lt 90 fd 15 end be draw :n :h case n [ [0 draw0 :h ] [1 draw0 :h setFC "red drawPoint 0 0 ] [2 draw0 :h setFC "green drawPoint -1 -1 drawPoint 1 1 ] [3 draw0 :h setFC "blue drawPoint -1 -1 drawPoint 0 0 drawPoint 1 1 ] [4 draw0 :h setFC "magenta drawPoint -1 -1 drawPoint -1 1 drawPoint 1 1 drawPoint 1 -1 ] [5 draw0 :h setFC "cyan drawPoint -1 -1 drawPoint -1 1 drawPoint 1 1 drawPoint 1 -1 drawPoint 0 0 ] [6 draw0 :h setFC "violet drawPoint -1 -1 drawPoint -1 1 drawPoint 1 1 drawPoint 1 -1 drawPoint -1 0 drawPoint 1 0 ] ] end be message :msg updateGraph FrameEnable windowdomino false setLabelSize [30 30] PU setH 0 hdist=(first (LabelSize :msg)) + 30 vdist=(last (LabelSize :msg)) + 30 setXY -:hdist/2-2 -:vdist/2-2 setLabelSize [30 30] bmp1=BitCopy :hdist+4 :vdist+4 setXY -:hdist/2 -:vdist/2 PPt repeat 2 [fd :vdist rt 90 fd :hdist rt 90] PU Home setH 90 Label :msg setH 0 PU updateGraph wait 100 setXY -:hdist/2-2 -:vdist/2-2 BitPaste bmp1 FrameEnable windowdomino true end be playerplays :pplays :ptile :side FrameEnable windowdomino false match=true if :pplays == 1 [ if (mditem (Se :ptile 2) :player1) == -1 [stop] playtile mditem (Se :ptile 1) :player1 :side if :match == true [ bonesplayed1=:bonesplayed1 + 1 PU setXY :startx+145+:ptile*33 :starty+0 bmp=bitcopy (:maxtile+:bonesdrawn1-:ptile+2-:bonesplayed1)*33+1 70 PU setXY :startx+145+(:ptile-1)*33 :starty+0 BitPaste bmp tmp=(mdarray [1 2] 1) mdsetitem [1 1] :tmp mditem (Se :ptile 1) :player1 mdsetitem [1 2] :tmp mditem (Se :ptile 2) :player1 tmp2=(:maxtile + :bonesdrawn1 - 1) for [i :ptile :tmp2 1] [ mdsetitem (Se :i 1) :player1 mditem (Se :i + 1 1) :player1 mdsetitem (Se :i 2) :player1 mditem (Se :i + 1 2) :player1 ] mdsetitem (Se :maxtile + :bonesdrawn1 1) :player1 mditem [1 1] :tmp mdsetitem (Se :maxtile + :bonesdrawn1 2) :player1 -1 OnMouseLeftDown [] OnMouseRightDown [] checkwin if :playing == -1 [computerplays] ] ] if :pplays == 2 [ if (mditem (Se :ptile 2) :player2) == -1 [stop] playtile mditem (Se :ptile 1) :player2 :side if :match == true [ bonesplayed2=:bonesplayed2 + 1 PU setXY :startx+145+:ptile*33 :starty+370 bmp=BitCopy (:maxtile+:bonesdrawn2-:ptile-:bonesplayed2+2)*33+1 70 PU setXY :startx+145+(:ptile-1)*33 :starty+370 BitPaste bmp tmp=(mdarray [1 2] 1) mdsetitem [1 1] :tmp mditem (Se :ptile 1) :player2 mdsetitem [1 2] :tmp mditem (Se :ptile 2) :player2 tmp2=(:maxtile + :bonesdrawn2 - 1) for [i :ptile :tmp2 1] [ mdsetitem (Se :i 1) :player2 mditem (Se :i + 1 1) :player2 mdsetitem (Se :i 2) :player2 mditem (Se :i + 1 2) :player2 ] mdsetitem (Se :maxtile + :bonesdrawn2 1) :player2 mditem [1 1] :tmp mdsetitem (Se :maxtile + :bonesdrawn2 2) :player2 -1 checkwin ] ] updateGraph FrameEnable windowdomino true end be getmousemove :cl FrameEnable windowdomino false x1=:startx + 145 y1=:starty + 7 if (and ((first MousePos) > :x1) ((first MousePos) < (:x1+((:maxtile+:bonesdrawn1)*32))) ((first bf MousePos) > :y1) ((first bf MousePos) < (:y1+60))) [ catch "error ;because of a bug in math [diff=(first MousePos)-:x1 ] if empty? Error [ counter=(Int (:diff/33))+1 playerplays 1 :counter :cl pass=0 ] ] if :gamemode == 2 [ x1=:startx + 145 y1=:starty + 375 if (and ((first MousePos) > :x1) ((first MousePos) < (:x1+((:maxtile+:bonesdrawn2)*32))) ((first bf MousePos) > :y1) ((first bf MousePos) < (:y1 + 60))) [ diff=(first MousePos)-:x1 counter=(Int (:diff/33))+1 playerplays 2 :counter :cl pass=0 ] ] FrameEnable windowdomino true end be drawrandomdomino :drdplayer FrameEnable windowdomino false ;------ Procedure invoked in the draw variation when player has to draw a bone, if :drdplayer == 1 [ freebone=0 drdcounter=0 freedomino=false maxloop=(:maxtile + :bonesdrawn1) for [i 1 :maxloop 1] [ if (mditem (Se :i 2) :player1) == 0 [ tempp=mditem (Se :i 1) :player1 drdcounter=:drdcounter + 1 ] ] for [i 1 28 1] [ if (mditem (Se :i 2) :arraydomino) == 0 [ freedomino=true ] ] if :freedomino == true [ bonesdrawn1=:bonesdrawn1 + 1 tempdrdplayer=(mdarray (Se (:maxtile + :bonesdrawn1) 2) 1) tempp=:maxtile + :bonesdrawn1 for [j 1 :drdcounter 1] [ mdsetitem (Se :j 1) :tempdrdplayer mditem (Se :j 1) :player1 mdsetitem (Se :j 2) :tempdrdplayer mditem (Se :j 2) :player1 ] temp2=:drdcounter + 2 for [j :temp2 :tempp 1] [ mdsetitem (Se :j 1) :tempdrdplayer mditem (Se :j - 1 1) :player1 mdsetitem (Se :j 2) :tempdrdplayer mditem (Se :j - 1 2) :player1 ] while [:freebone == 0 ] [ randomdraw=(random 28) + 1 if (mditem (Se :randomdraw 2) :arraydomino) == 0 [ freebone=mditem (Se :randomdraw 1) :arraydomino mdsetitem (Se :randomdraw 2) :arraydomino -1 ] ] mdsetitem (Se :drdcounter + 1 1) :tempdrdplayer :randomdraw mdsetitem (Se :drdcounter + 1 2) :tempdrdplayer 0 temp=(:maxtile + :bonesdrawn1 ) player1=(mdarray (Se :temp 2) 1) for [k 1 :temp 1] [ mdsetitem (Se :k 1) :player1 (mditem (Se :k 1) :tempdrdplayer) mdsetitem (Se :k 2) :player1 (mditem (Se :k 2) :tempdrdplayer) ] PU setXY (:startx + 150 + (:drdcounter ) * 33) - 5 :starty + 5 drawtile (mditem (Se :drdcounter + 1 1) :player1) 0 30 0 0 ] ;----------------------------------------------------------------------------------------- ] if :drdplayer == 2 [ freebone=0 drdcounter=0 freedomino=false maxloop=(:maxtile + :bonesdrawn2) for [i 1 :maxloop 1] [ if (mditem (Se :i 2) :player2) == 0 [ tempp=mditem (Se :i 1) :player2 drdcounter=:drdcounter + 1 ] ] for [i 1 28 1] [ if (mditem (Se :i 2) :arraydomino) == 0 [ freedomino=true ] ] if :freedomino == true [ bonesdrawn2=:bonesdrawn2 + 1 tempdrdplayer=(mdarray (Se (:maxtile + :bonesdrawn2) 2) 1) tempp=:maxtile + :bonesdrawn2 for [j 1 :drdcounter 1] [ mdsetitem (Se :j 1) :tempdrdplayer mditem (Se :j 1) :player2 mdsetitem (Se :j 2) :tempdrdplayer mditem (Se :j 2) :player2 ] temp2=:drdcounter + 2 for [j :temp2 :tempp 1] [ mdsetitem (Se :j 1) :tempdrdplayer mditem (Se :j - 1 1) :player2 mdsetitem (Se :j 2) :tempdrdplayer mditem (Se :j - 1 2) :player2 ] while [:freebone == 0 ] [ randomdraw=(random 28) + 1 if (mditem (Se :randomdraw 2) :arraydomino) == 0 [ freebone=mditem (Se :randomdraw 1) :arraydomino mdsetitem (Se :randomdraw 2) :arraydomino -1 ] ] mdsetitem (Se :drdcounter + 1 1) :tempdrdplayer :randomdraw mdsetitem (Se :drdcounter + 1 2) :tempdrdplayer 0 temp=(:maxtile + :bonesdrawn2 ) player2=(mdarray (Se :temp 2) 1) for [k 1 :temp 1] [ mdsetitem (Se :k 1) :player2 (mditem (Se :k 1) :tempdrdplayer) mdsetitem (Se :k 2) :player2 (mditem (Se :k 2) :tempdrdplayer) ] PU setXY (:startx + 150 + (:drdcounter ) * 33) - 5 :starty + 375 ;drawtile (mditem (se :drdcounter + 1 1) :player2) 0 30 0 0 PPt setH 0 setPC [1 1 .8] repeat 2 [ fd 60 rt 90 fd 30 rt 90] PU ] ;----------------------------------------------------------------------------------------- ] updateGraph if :freedomino == false [ nomorebones=true ButtonEnable bdraw false buttonenable bpass true ] FrameEnable windowdomino true end be checkstale FrameEnable windowdomino false ;------------ Procedure invoked when neither player is able to play if :pass == 2 [ message [game over] displayopponenttile OnMouseLeftDown [] OnMouseRightDown [] maxloop=(:maxtile + :bonesdrawn1) total1=0 for [i 1 :maxloop 1] [ if (mditem (Se :i 2) :player1) == 0 [ temp=(mditem (Se :i 1) :player1) domino1=first (mditem (Se :temp 1) :arraydomino) domino2=last (mditem (Se :temp 1) :arraydomino) total1=:total1 + :domino1 + :domino2 ] ] maxloop=(:maxtile + :bonesdrawn2) total2=0 for [i 1 :maxloop 1] [ if (mditem (Se :i 2) :player2) == 0 [ temp=(mditem (Se :i 1) :player2) domino1=first (mditem (Se :temp 1) :arraydomino) domino2=last (mditem (Se :temp 1) :arraydomino) total2=:total2 + :domino1 + :domino2 ] ] setLabelSize [40 40] if :total2 > :total1 [ endofround 1 ] if :total1 > :total2 [ endofround 2 ] if :total1 == :total2 [ message [Stalemate] playing=0 OnMouseLeftDown [] OnMouseRightDown [] displayopponenttile ButtonEnable bnewround true ButtonEnable bpass false ButtonEnable bdraw false ] setLabelSize [30 30] setPC [.15 .15 .15] printTotalScore ] FrameEnable windowdomino true end be printTotalScore PU setXY 0 20 setH 90 Label (Se [Player 1:] :total1 ) setH 0 PU setXY 0 -20 setH 90 Label (Se [Player 2:] :total2 ) setH 0 end be checkwin FrameEnable windowdomino false ;------------ Checking whether a player has won the current turn or game total1=0 maxloop=(:maxtile + :bonesdrawn1) for [i 1 :maxloop 1] [ if (mditem (Se :i 2) :player1) == 0 [ temp=(mditem (Se :i 1) :player1) domino1=first (mditem (Se :temp 1) :arraydomino) domino2=last (mditem (Se :temp 1) :arraydomino) total1=:total1 + :domino1 + :domino2 ] ] total2=0 maxloop=(:maxtile + :bonesdrawn2) for [i 1 :maxloop 1] [ if (mditem (Se :i 2) :player2) == 0 [ temp=(mditem (Se :i 1) :player2) domino1=first (mditem (Se :temp 1) :arraydomino) domino2=last (mditem (Se :temp 1) :arraydomino) total2=:total2 + :domino1 + :domino2 ] ] c1=0 maxloop=(:maxtile + :bonesdrawn1) for [i 1 :maxloop 1] [ if (mditem (Se :i 2) :player1) == 0 [ c1=:c1 + 1 ] ] if :c1 == 0 [ endofround 1 setLabelSize [30 30] printTotalScore ] c2=0 maxloop=(:maxtile + :bonesdrawn2) for [i 1 :maxloop 1] [ if (mditem (Se :i 2) :player2) == 0 [ c2=:c2 + 1 ] ] if :c2 == 0 [ endofround 2 setLabelSize [30 30] printTotalScore ] FrameEnable windowdomino true end be computerplays FrameEnable windowdomino false ButtonEnable bpass false computerplayed=false if nomorebones == false [ freedomino=true ] maxloop=(:maxtile + :bonesdrawn2) do_until [ for [i 1 :maxloop 1] [ if (mditem (Se :i 2) :player2) == 0 [ no=mditem (Se :i 1) :player2 ;-------------- Checking whether computer can play lm1=(first mditem (Se :no 1) :arraydomino) == (Item :tpls + 1 :tilesplayed) lm2=(last mditem (Se :no 1) :arraydomino) == (Item :tpls + 1 :tilesplayed) rm1=(first mditem (Se :no 1) :arraydomino) == (Item :tprs - 1 :tilesplayed) rm2=(last mditem (Se :no 1) :arraydomino) == (Item :tprs - 1 :tilesplayed) if (or (:lm1) (:lm2) (:rm1) (:rm2)) [ ;--------------- Playing on the left side if (and (:computerplayed == false) (or (:lm1) (:lm2))) [ playerplays 2 :i -1 computerplayed=true pass=0 ] ;--------------- Playing on the right side if (and (:computerplayed == false) (or (:rm1) (:rm2))) [ playerplays 2 :i 1 computerplayed=true pass=0 ] ] ] ] ; messagebox [](se :computerplayed :roundvariations :freedomino) if :computerplayed == false [ ifElse :roundvariations == "draw [ drawrandomdomino 2 ][] if (or (equalP :roundvariations "block) (:freedomino == false)) [ message [I pass] pass=:pass + 1 checkstale ] if (and (:freedomino == false)(:playing == -1)) [ ButtonEnable bpass true ButtonEnable bdraw false ] ] ][ (or (:computerplayed == true) (:roundvariations == "block) (:freedomino == false)) ] OnMouseLeftDown [domino::getmousemove -1] OnMouseRightDown [domino::getmousemove 1] if (and (:playing == -1) (:nomorebones == true)) [ ButtonEnable bpass true ] FrameEnable windowdomino true end be displayopponenttile FrameEnable windowdomino false maxloop=(:maxtile + :bonesdrawn2) repeat :maxloop [ PU setXY (:xxx + (repCount - 1) * 33) :yyy if (mditem (Se repCount 2) :player2) == 0 [ drawtile (mditem (Se repCount 1) :player2) 0 30 0 0 ] ] updateGraph FrameEnable windowdomino true end be endofround :winner FrameEnable windowdomino false ifElse :winner == 1 [ message [player 1 wins] bigtotal1=:bigtotal1 + :total2 printScore -200 bigtotal1 ][ message [player 2 wins] bigtotal2=:bigtotal2 + :total1 printScore 180 bigtotal2 ] playing=0 OnMouseLeftDown [] OnMouseRightDown [] displayopponenttile ButtonEnable bpass false ButtonEnable bdraw false ifElse (or (:bigtotal1 > :roundwinningscore) (:bigtotal2 > :roundwinningscore)) [ gamefinished=-1 if (:bigtotal1 > :roundwinningscore) [ message [Congratulations! You win the game] ] if (:bigtotal2 > :roundwinningscore) [ message [The computer wins the game] ] ][ ButtonEnable bnewround true ] FrameEnable windowdomino true end be printScore y score PU setXY -380 y-20 setFC "forestgreen fillRect [0 0][150 35] setPC 0 setLabelSize [30 30] PU setXY -310 y setH 90 Label (Se [Score:] score) setH 0 end be helpmessage FrameEnable windowdomino false ButtonEnable bhelp false PU setH 0 setXY -202 -102 bmp=BitCopy 404 204 PPt setXY -200 -100 setPC [1 1 .8] PolyStart repeat 2 [ fd 200 rt 90 fd 400 rt 90 ] PolyEnd PU setXY 0 70 setH 90 setPC 0 setLabelSize [40 40] Label [Domino player help] setLabelSize [30 30] setXY 0 0 Label [right click to play clockwise] setXY 0 -50 Label [left click to play anti-clockwise] setH 0 selection=-1 OnMouseLeftDown [domino::mousepressed] while [:selection < 0] [dispatchMessages wait 1] PU setXY -202 -102 BitPaste bmp updateGraph ButtonEnable bhelp true FrameEnable windowdomino true end be mousepressed if :playing == -1 [ OnMouseLeftDown [domino::getmousemove -1] OnMouseRightDown [domino::getmousemove 1] ] selection=0 end be passbuttonpressed FrameEnable windowdomino false ButtonEnable bpass false pass=:pass + 1 checkstale computerplays FrameEnable windowdomino true end be placetile :tileno :side :option FrameEnable windowdomino false local [tileplaced] tileplaced=false PU ;---------------- Player plays a doublet anti-clockwise if :option == -11 [ if (and (:lx > -349) (:ly == 100) (:tileplaced == false)) [ lx=:lx + 30 setXY :lx :ly - 15 drawtile :tileno 0 30 0 0 lx=:lx - 62 tileplaced=true ] if (and (:lx < -349) (:ly == 100) (:tileplaced == false)) [ ly=:ly - 32 if (Item :tpls + 1 :tilesplayed) == (Item :tpls + 2 :tilesplayed) [ ly=:ly - 15 ] setXY :lx + 92 :ly drawtile :tileno 0 30 0 180 ly=:ly - 62 tileplaced=true ] if (and (:lx < -349) (:ly < 100) (:tileplaced == false)) [ setXY :lx + 47 :ly + 30 drawtile :tileno 30 0 0 90 ly=:ly - 32 tileplaced=true ] if (and (:lx > -349) (:ly < -70) (:tileplaced == false)) [ setXY :lx + 62 :ly + 47 drawtile :tileno 0 30 90 90 lx=:lx + 32 tileplaced=true ] if (and (:lx < 300) (:ly > 70) (:tileplaced == false)) [ setXY :lx + 30 :ly - 15 drawtile :tileno 0 30 0 0 lx=:lx - 32 tileplaced=true ] if (and (:lx > 300) (:ly > 70) (:tileplaced == false)) [ lx=:lx - 62 setXY :lx :ly drawtile :tileno 30 0 90 0 lx=:lx - 62 tileplaced=true ] if (and (:lx > 300) (:ly > -70) (:tileplaced == false)) [ setXY :lx :ly + 62 drawtile :tileno 0 -30 0 0 tileplaced=true ly=:ly + 62 ] ] ;---------------- Player plays a non double anti-clockwise if :option == -1 [ if (and (:lx > -349) (:ly == 100) (:tileplaced == false)) [ setXY :lx :ly drawtile :tileno 30 0 90 0 lx=:lx - 62 tileplaced=true ] if (and (:lx < -349) (:ly == 100) (:tileplaced == false)) [ ly=:ly - 32 if (Item :tpls + 1 :tilesplayed) == (Item :tpls + 2 :tilesplayed) [ ly=:ly - 15 ] setXY :lx + 92 :ly drawtile :tileno 0 30 0 180 ly=:ly - 62 tileplaced=true ] if (and (:lx < -349) (:ly < -70) (:tileplaced == false)) [ if (Item :tpls + 1 :tilesplayed) == (Item :tpls + 2 :tilesplayed) [ lx=:lx + 15 ] lx=:lx + 62 setXY :lx + 62 :ly + 32 drawtile :tileno -30 0 90 0 lx=:lx + 32 tileplaced=true ] if (and (:lx > 240) (:ly < -70) (:tileplaced == false)) [ setXY :lx + 62 :ly + 62 drawtile :tileno 0 -30 0 0 tileplaced=true ly=:ly + 62 lx=:lx + 62 ] if (and (:lx < 300) (:ly > 70) (:tileplaced == false)) [ setXY :lx :ly drawtile :tileno 30 0 90 0 lx=:lx - 62 tileplaced=true ] if (and (:lx > 300) (:ly > 70) (:tileplaced == false)) [ lx=:lx - 62 setXY :lx :ly drawtile :tileno 30 0 90 0 lx=:lx - 62 tileplaced=true ] if (and (:lx > 300) (:ly > -70) (:tileplaced == false)) [ setXY :lx :ly + 62 drawtile :tileno 0 -30 0 0 tileplaced=true ly=:ly + 62 ] if (and (:lx > -349) (:ly < -70) (:tileplaced == false)) [ lx=:lx + 62 setXY :lx + 30 :ly + 32 drawtile :tileno -30 0 90 0 tileplaced=true ] if (and (:lx < -349) (:ly < 100) (:tileplaced == false)) [ setXY :lx + 92 :ly drawtile :tileno 0 30 0 180 ly=:ly - 62 tileplaced=true ;how [mmm] ] ] ;---------------- Player plays a double clockwise if :option == 11 [ if (and (:rx < 300) (:ry == 100) (:tileplaced == false)) [ setXY :rx :ry - 15 drawtile :tileno 0 30 0 0 rx=:rx + 32 tileplaced=true ] if (and (:rx > 300) (:ry == 100) (:tileplaced == false)) [ rx=:rx - 32 ry=:ry - 62 setXY :rx :ry drawtile :tileno 0 30 0 0 rx=:rx + 30 ry=:ry + 13 tileplaced=true ] if (and (:rx > -269) (:ry > 90) (:tileplaced == false)) [ setXY :rx :ry - 15 drawtile :tileno 0 30 90 90 rx=:rx + 32 tileplaced=true ] if (and (:rx < -269) (:ry < -50) (:tileplaced == false)) [ ry=:ry + 30 setXY :rx :ry drawtile :tileno 0 30 90 90 ry=:ry + 62 tileplaced=true ] if (and (:rx < -269) (:ry < 100) (:tileplaced == false)) [ setXY :rx - 15 :ry - 30 drawtile :tileno 30 0 90 0 ry=:ry + 32 tileplaced=true ] if (and (:rx > 300) (:ry < 100) (:tileplaced == false)) [ setXY :rx - 15 :ry drawtile :tileno -30 0 0 90 ry=:ry - 17 tileplaced=true ] if (and (:rx < 300) (:ry < -50) (:tileplaced == false)) [ setXY :rx :ry - 15 drawtile :tileno 0 30 0 0 rx=:rx - 32 tileplaced=true ] ] ;---------------- Player plays a non-doublet clockwise if :option == 1 [ if (and (:rx > 300) (:ry == 100) (:tileplaced == false)) [ ry=:ry - 2 rx=:rx - 2 if (Item :tprs - 1 :tilesplayed) == (Item :tprs - 2 :tilesplayed) [ ry=:ry - 15 ] setXY :rx :ry drawtile :tileno 0 -30 0 180 ry=:ry - 62 tileplaced=true ] if (and (:rx < 300) (:ry == 100) (:tileplaced == false)) [ setXY :rx :ry drawtile :tileno 30 0 90 0 rx=:rx + 62 tileplaced=true ] if (and (:rx > -269) (:ry > 90) (:tileplaced == false)) [ setXY :rx :ry - 32 drawtile :tileno 30 0 90 0 rx=:rx + 62 tileplaced=true ] if (and (:rx < -269) (:ry > 90) (:tileplaced == false)) [ setXY :rx :ry - 32 drawtile :tileno 30 0 90 0 rx=:rx + 62 ; make "ry :ry - 32 tileplaced=true ] if (and (:rx < -269) (:ry < -50) (:tileplaced == false)) [ ry=:ry + 30 setXY :rx :ry drawtile :tileno 0 30 90 90 ry=:ry + 62 tileplaced=true ] if (and (:rx < -269) (:ry < 100) (:tileplaced == false)) [ setXY :rx :ry drawtile :tileno 0 30 90 90 ry=:ry + 62 tileplaced=true ] if (and (:rx < 300) (:ry < -50) (:tileplaced == false)) [ setXY :rx :ry drawtile :tileno -30 0 90 0 rx=:rx - 62 tileplaced=true ] if (and (:rx > 300) (:ry < -50) (:tileplaced == false)) [ rx=:rx - 62 ry=:ry + 2 if (Item :tprs - 1 :tilesplayed) == (Item :tprs - 2 :tilesplayed) [ rx=:rx - 15 ry=:ry - 15 ] setXY :rx :ry drawtile :tileno -30 0 90 0 rx=:rx - 62 tileplaced=true ] if (and (:rx > 300) (:ry < 100) (:tileplaced == false)) [ if (Item :tprs - 1 :tilesplayed) == (Item :tprs - 2 :tilesplayed) [ ry=:ry - 15 ] setXY :rx :ry drawtile :tileno 0 -30 0 180 ry=:ry - 62 tileplaced=true ] ] FrameEnable windowdomino true end be playtile :tileno :side ;------------- LinTP stands for left in tiles played LinTP=(Item :tpls + 1 :tilesplayed) ;------------- RinTP stands for right in tiles played RinTP=(Item :tprs - 1 :tilesplayed) ls=(first mditem (Se :tileno 1) :arraydomino) rs=(last mditem (Se :tileno 1) :arraydomino) if :side == -1 [ ifElse (or (:ls == :LinTP) (:rs == :LinTP) ((:tprs - :tpls) == 1)) [ PU setXY :lx :ly ;-------- Checking whether tile has to be "rotated/swapped" if (not equalP :rs :LinTP) [ tmp=mditem (Se :tileno 1) :arraydomino mdsetitem (Se :tileno 1) :arraydomino (Se last :tmp first :tmp ) ] ;---------- Determining how to place the tile ifElse :ls == :rs [ placetile :tileno :side -11 ][ placetile :tileno :side -1 ] ][ message [no match] match=false stop ] ] if :side == 1 [ ifElse (or (:ls == :RinTP) (:rs == :RinTp) ((:tprs - :tpls) == 1)) [ PU setXY :rx :ry ;-------- Checking whether tile has to be "rotated/swapped" if (not equalP :ls :RinTP) [ tmp=mditem (Se :tileno 1) :arraydomino mdsetitem (Se :tileno 1) :arraydomino (Se last :tmp first :tmp ) ] ifElse :ls == :rs [ placetile :tileno :side 11 ][ placetile :tileno :side 1 ] ][ message [no match] match=false stop ] ] ;----------------- Recording the move if (:side == -1) [ setItem (:tpls ) :tilesplayed last mditem (Se :tileno 1) :arraydomino setItem (:tpls - 1) :tilesplayed first mditem (Se :tileno 1) :arraydomino tpls=:tpls - 2 ] if (:side == 1) [ setItem :tprs :tilesplayed (first mditem (Se :tileno 1) :arraydomino) setItem (:tprs + 1) :tilesplayed (last mditem (Se :tileno 1) :arraydomino) tprs=:tprs + 2 ] end be setupwindow ButtonEnable bsetup false staticoption=(StaticText mydialog [Game variations] wxAlign_centre) rblock=(RadioButton mydialog [&Block mode][] wxRB_GROUP) rdraw=RadioButton mydialog [&Draw mode][] ifelse :variations == "block [ RadioButtonSet rblock true ][ RadioButtonSet rdraw true ] staticscore=(StaticText mydialog [Winning score] wxAlign_centre) r100=(RadioButton mydialog [&100][] wxRB_GROUP) r200=RadioButton mydialog [&200][] r300=RadioButton mydialog [&300][] case :winningscore [ [100 RadioButtonSet r100 true] [200 RadioButtonSet r200 true] [300 RadioButtonSet r300 true] ] staticbones=(StaticText mydialog [Number of bones] wxAlign_centre) r5=(RadioButton mydialog [&5][] wxRB_GROUP) r7=RadioButton mydialog [&7][] r10=RadioButton mydialog [1&0][] case :numberofbones [ [5 RadioButtonSet r5 true] [7 RadioButtonSet r7 true] [10 RadioButtonSet r10 true] ] staticgeneral=(StaticText mydialog [General] wxAlign_centre) cdoublet=CheckBox mydialog [&Highest doublet starts][] ifElse :highestdoublet == true [ CheckBoxSet cdoublet true ][ CheckBoxSet cdoublet false ] dclose=Button mydialog [&Close] [ domino::updatesetup ern "domino::mydialog (GC true) hT ] dcancel=Button mydialog [Ca&ncel] [ ern "domino::mydialog (GC true) hT ] bs=BoxSizer wxVertical bsoption=BoxSizer wxVertical BoxSizerAdd bsoption staticoption 100 wxTop+wxExpand 0 BoxSizerAdd bsoption rblock 100 wxExpand 0 BoxSizerAdd bsoption rdraw 100 wxExpand 0 BoxSizerAdd bs bsoption 300 wxAll+wxExpand 10 BoxSizerAdd bs staticscore 100 wxTop+wxExpand 10 bsscore=BoxSizer wxHorizontal BoxSizerAdd bsscore r100 100 wxExpand 0 BoxSizerAdd bsscore r200 100 wxExpand 0 BoxSizerAdd bsscore r300 100 wxExpand 0 BoxSizerAdd bs bsscore 100 wxAll-wxTop+wxExpand 10 BoxSizerAdd bs staticbones 100 wxTop+wxExpand 10 bsbones=BoxSizer wxHorizontal BoxSizerAdd bsbones r5 100 wxExpand 0 BoxSizerAdd bsbones r7 100 wxExpand 0 BoxSizerAdd bsbones r10 100 wxExpand 0 BoxSizerAdd bs bsbones 100 wxAll-wxTop+wxExpand 10 BoxSizerAdd bs staticgeneral 100 wxTop+wxExpand 10 BoxSizerAdd bs cdoublet 100 wxAll+wxExpand 10 bsbtn=BoxSizer wxHorizontal BoxSizerAdd bsbtn dclose 100 wxExpand 0 BoxSizerAdd bsbtn dcancel 100 wxExpand 0 BoxSizerAdd bs bsbtn 100 wxExpand 0 FrameSetSizer mydialog bs end be updatesetup ifElse RadioButtonValue rblock [ domino::variations="block ][ domino::variations="draw ] if RadioButtonValue r7 [numberofbones=7] if RadioButtonValue r5 [numberofbones=5] if RadioButtonValue r10 [numberofbones=10] if RadioButtonValue r100 [winningscore=100] if RadioButtonValue r200 [winningscore=200] if RadioButtonValue r300 [winningscore=300] ignore (Messagebox [Any changes made will take effect when you start a new game] [Domino v0.91]) ButtonEnable bsetup true end be about FrameEnable windowdomino false ;------------- Procedure that displays the credits msg= [ Domino v0.91 written by Hensley Bass\ Email: hbass@intnet.mu\ Url: http://pages.intnet.mu/jhbpage\ \ Ported to aUCBLogo by Andreas Micheler ] ignore (MessageBox :msg [Domino v0.91]) FrameEnable windowdomino true end end