() Prgm Local y,x,a,b,c,f,t,r,g,z ClrDraw PxlLine 5,27,71,27 PxlLine 5,49,71,49 PxlLine 27,5,27,71 PxlLine 49,5,49,71 PxlText "___ ___ ___",7,80 PxlText "Tic-Tac-Toe",5,80 RclPic tcursor,20,82 PxlText "'s Turn",26,102 PxlText "Turn:",45,75 PxlText "Mode:",60,75 PxlText "2 Player",60,103 7»y:7»x:1»b:1»c 0»f:0»t:0»r:0»g:0»z newMat(3,3)»a Lbl st Dialog Title "Welcome to Tic-Tac-Toe" Text "Player one will be" DropDown "X or O?",{"X","O"},f EndDlog If f=0:Goto st rand(2)»t If t=1 Then f»z Else If f=1:2»z If f=2:1»z EndIf If z=1:RclPic tbigx,20,82 If z=2:RclPic tbigo,20,82 Dialog Title "Tic-Tac-Toe" Text "Guess who gets to go first." EndDlog If t=1 Then PxlText "Player 1",45,104 Dialog Title "Tic-Tac-Toe" Text "1st player does!" EndDlog EndIf If t=2 Then PxlText "Player 2",45,104 Dialog Title "Tic-Tac-Toe" Text "2nd player does!" EndDlog EndIf Lbl a Loop RclPic tcursor,y,x For f,1,50 getKey()»g If g¥0:Exit EndFor If a[b,c]=0 Then XorPic tcursor,y,x ElseIf a[b,c]=2 Then AndPic tbigo,y,x Else AndPic tbigx,y,x EndIf If g¥0:Goto b For f,1,50 getKey()»g If g¥0:Exit EndFor If g¥0:Goto b EndLoop Lbl b If g=268:Goto c If g=4360:Goto q If g=337 and c¥1 Then c-1»c:x-22»x EndIf If g=340 and c¥3 Then c+1»c:x+22»x EndIf If g=338 and b¥1 Then b-1»b:y-22»y EndIf If g=344 and b¥3 Then b+1»b:y+22»y EndIf Goto a Lbl c If a[b,c]¥0:Goto a r+1»r z»a[b,c] If a[b,c]=1:RclPic tbigx,y,x If a[b,c]=2:RclPic tbigo,y,x If a[1,1]¥0 Then If a[1,1]=a[1,2] and a[1,2]=a[1,3]:Goto w If a[1,1]=a[2,1] and a[2,1]=a[3,1]:Goto w EndIf If a[2,2]¥0 Then If a[1,2]=a[2,2] and a[2,2]=a[3,2]:Goto w If a[2,1]=a[2,2] and a[2,2]=a[2,3]:Goto w If a[1,1]=a[2,2] and a[2,2]=a[3,3]:Goto w If a[1,3]=a[2,2] and a[2,2]=a[3,1]:Goto w EndIf If a[3,3]¥0 Then If a[3,1]=a[3,2] and a[3,2]=a[3,3]:Goto w If a[1,3]=a[2,3] and a[2,3]=a[3,3]:Goto w EndIf If r=9:Goto c2 If t=1 Then PxlText "Player 2",45,104 2»t Else PxlText "Player 1",45,104 1»t EndIf If z=1 Then 2»z Else 1»z EndIf AndPic tbigx,20,82 AndPic tbigo,20,82 RclPic tcursor,20,82 If z=1:RclPic tbigx,20,82 If z=2:RclPic tbigo,20,82 Goto a Lbl w If a[1,1]=a[1,2] and a[1,2]=a[1,3] and a[1,1]¥0 Then 7»g:16»b:69»c:16»f 1»x:0»y:1»r EndIf If a[2,1]=a[2,2] and a[2,2]=a[2,3] and a[2,1]¥0 Then 7»g:38»b:69»c:38»f 1»x:0»y:1»r EndIf If a[3,1]=a[3,2] and a[3,2]=a[3,3] and a[3,1]¥0 Then 7»g:60»b:69»c:60»f 1»x:0»y:1»r EndIf If a[1,1]=a[2,1] and a[2,1]=a[3,1] and a[1,1]¥0 Then 16»g:7»b:16»c:69»f 0»x:1»y:1»r EndIf If a[1,2]=a[2,2] and a[2,2]=a[3,2] and a[1,2]¥0 Then 38»g:7»b:38»c:69»f 0»x:1»y:1»r EndIf If a[1,3]=a[2,3] and a[2,3]=a[3,3] and a[1,3]¥0 Then 60»g:7»b:60»c:69»f 0»x:1»y:1»r EndIf If a[1,1]=a[2,2] and a[2,2]=a[3,3] and a[1,1]¥0 Then 7»g:7»b:69»c:69»f 1»x:1»y:2»r EndIf If a[3,1]=a[2,2] and a[2,2]=a[1,3] and a[3,1]¥0 Then 7»g:69»b:69»c:7»f 1»x:ª1»y:2»r EndIf If r=1 Then Loop PxlOff b-2*x,g-2*y PxlOn b-x,g-y PxlOn b,g PxlOn b+x,g+y PxlOff b+2*x,g+2*y g+x»g:b+y»b If g>c:Exit If b>f:Exit EndLoop EndIf If r=2 Then Loop PxlOff b-2*y,g PxlOn b-y,g PxlOn b,g PxlOn b+y,g PxlOff b+2*y,g g+x»g:b+y»b If g>c:Exit EndLoop EndIf 10»c PxlText "¢ tic-tac-toe !",5,68 Lbl w1 getKey()»g If g¥0:Goto pa PxlText " i -t c- o ",5,80 For b,1,c+5 EndFor PxlText "t c- a -t e",5,80 For b,1,c EndFor Goto w1 Lbl c2 PxlText "It's a Draw!",5,78 10»f StoPic a,7,7,62,62 Lbl c3 getKey()»g If g¥0:Goto pa RclPic a,7,7 rand(35)+17»b rand(35)+17»c For z,1,f PxlCrcl b,c,z EndFor For z,f,1,ª1 PxlCrcl b,c,z,0 EndFor Goto c3 Lbl pa 0»b Dialog Title "Tic-Tac-Toe" DropDown "Play again?",{"Yes","No"},b EndDlog If b=0:Goto pa If b=1:Goto s If b=2:Goto q Lbl s Dialog Title "IMPORTANT" Text "Just hit [ENTER] after the program exits." EndDlog Lbl q ClrHome 1»xmin:0»xmin DispHome EndPrgm