Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'TIC TAC TOE
- 'Made by Daniël Haazen
- '
- 'S for Start
- Lbl S
- ClrText
- 'The matrix for gamefield
- [[0,0,0][0,0,0][0,0,0]]→Mat A
- 'Create the board.
- 'Prog WRITE: List(x,y,Text in numbers,...)
- {9,2,40,0,40}→List 1
- Prog "WRITE"
- {8,3,40,40,40,40,40}→List 1
- Prog "WRITE"
- {9,4,40,0,40}→List 1
- Prog "WRITE"
- {8,5,40,40,40,40,40}→List 1
- Prog "WRITE"
- {9,6,40,0,40}→List 1
- Prog "WRITE"
- 'U for User/Player
- Lbl U
- 'Make C the character "X"
- 24→C
- 'Get Key loop
- Lbl K
- GetKey→K
- K=0⇒Goto K
- 'If K is a valid key, and it's an empty cell, go fill that cell.
- K=54 And Mat A[3,3]=0⇒Goto 9
- K=64 And Mat A[3,2]=0⇒Goto 8
- K=74 And Mat A[3,1]=0⇒Goto 7
- K=53 And Mat A[2,3]=0⇒Goto 6
- K=63 And Mat A[2,2]=0⇒Goto 5
- K=73 And Mat A[2,1]=0⇒Goto 4
- K=52 And Mat A[1,3]=0⇒Goto 3
- K=62 And Mat A[1,2]=0⇒Goto 2
- K=72 And Mat A[1,1]=0⇒Goto 1
- 'If not, go to K
- Goto K
- 'Set the x and y, and fill the matrix cell, go to P
- Lbl 1
- 8→A
- 6→B
- C→Mat[1,1]
- Goto P
- Lbl 2
- 10→A
- 6→B
- C→Mat A[1,2]
- Goto P
- Lbl 3
- 12→A
- 6→B
- C→Mat A[1,3]
- Goto P
- Lbl 4
- 8→A
- 4→B
- C→Mat A[2,1]
- Goto P
- Lbl 5
- 10→A
- 4→B
- C→Mat A[2,2]
- Goto P
- Lbl 6
- 12→A
- 4→B
- C→Mat A[2,3]
- Goto P
- Lbl 7
- 8→A
- 2→B
- C→Mat A[3,1]
- Goto P
- Lbl 8
- 10→A
- 2→B
- C→Mat A[3,2]
- Goto P
- Lbl 9
- 12→A
- 2→B
- C→Mat A[3,3]
- Goto P
- 'P for Put
- Lbl P
- 'Prog "PUT": Puts number C as character on position A,B
- PROG "PUT"
- Goto Q
- 'B for.. no idea actually
- Lbl B
- 'If the Player/Computer was previous turn, let the other go this turn
- C=24⇒Goto C
- C=15⇒Goto U
- Lbl C
- 15→C
- 'R for.. repeat?
- Lbl R
- 'Let K be an integer between 1 and 9
- Int (Ran#x9)+1→K
- 'If K is a cell that is not occupied..
- K=1 And Mat A[1,1]=0⇒Goto 1
- K=2 And Mat A[1,2]=0⇒Goto 2
- K=3 And Mat A[1,3]=0⇒Goto 3
- K=4 And Mat A[2,1]=0⇒Goto 4
- K=5 And Mat A[2,2]=0⇒Goto 5
- K=6 And Mat A[2,3]=0⇒Goto 6
- K=7 And Mat A[3,1]=0⇒Goto 7
- K=8 And Mat A[3,2]=0⇒Goto 8
- K=9 And Mat A[3,3]=0⇒Goto 9
- 'If not, retry with a new random number
- Goto R
- 'Q for.. okay these are made up mostly.
- Lbl Q
- For 1→I To 3
- 'If cell 1 is equal to cell 2 and 3, and cell 1 is not empty, go to W
- Mat A[I,1]=Mat A[I,2] And Mat A[I,1]=Mat A[I,3] And Mat A[I,1]≠0⇒Goto W
- Mat A[1,I]=Mat A[2,I] And Mat A[1,I]=Mat A[3,I] And Mat A[1,I]≠0⇒Goto W
- Next
- 'Checking for diagonal lines.
- 'If the center is not filled, we already know there is no diagonal line.
- Mat A[2,2]=0⇒Goto B
- 'If the diagonal cells are the same
- Mat A[1,1]=Mat A[2,2] And Mat A[1,1]=Mat A[3,3]⇒Goto W
- Mat A[3,1]=Mat A[2,2] And Mat A[3,1]=Mat A[1,3]⇒Goto W
- 'If these are all false, we need to check if it's not a tie
- For 1→I To 3
- for 1→J To 3
- 'If a cell is empty, there is no tie
- Mat A[I,J]=0⇒Goto B
- Next
- Next
- 'All cells are filled, it's a tie
- {9,1,20,9,5}→List 1
- Goto E
- 'W for Win
- Lbl W
- 'Write "(X or O) WINS"!
- {8,1,C,0,23,9,1,4,19}→List 1
- 'E for End
- Lbl E
- Prog "WRITE"
- 'Big for-loop for pause
- For 1→I To 500
- Next
- Goto S
- Libraries:
- WRITE
- 'WRITE
- 'By Daniël Haazen
- '
- List 1[1]→X
- List 1[2]→Y
- For 1→I To Dim List 1-2
- List 1[2+I]→C
- I-1→J
- If X+J>21
- Then 21→B
- J+X→A
- Prog "MOD"
- A+1→A
- Int ((X+J)/21)+Y→B
- If B<8
- Then Prog "PUT"
- IfEnd
- Else J+X→A
- Y→B
- Prog "PUT"
- IfEnd
- Next
- Return
- MOD
- 'MOD
- '
- A-Int (A/B)xB→A
- Return
- PUT
- 'PUT
- 'By Daniël Haazen
- '
- If C≤20
- Then If C≤10
- Then If C≤5
- Then C=0⇒Locate A,B," "
- C=1⇒Locate A,B,"A"
- C=2⇒Locate A,B,"B"
- C=3⇒Locate A,B,"C"
- C=4⇒Locate A,B,"D"
- C=5⇒Locate A,B,"E"
- Else C=6⇒Locate A,B,"F"
- C=7⇒Locate A,B,"G"
- C=8⇒Locate A,B,"H"
- C=9⇒Locate A,B,"I"
- C=10⇒Locate A,B,"J"
- IfEnd
- Else If C≤15
- Then C=11⇒Locate A,B,"K"
- C=12⇒Locate A,B,"L"
- C=13⇒Locate A,B,"M"
- C=14⇒Locate A,B,"N"
- C=15⇒Locate A,B,"O"
- Else C=16⇒Locate A,B,"P"
- C=17⇒Locate A,B,"Q"
- C=18⇒Locate A,B,"R"
- C=19⇒Locate A,B,"S"
- C=20⇒Locate A,B,"T"
- IfEnd
- IfEnd
- Else If C≤30
- Then if C≤25
- Then C=21⇒Locate A,B,"U"
- C=22⇒Locate A,B,"V"
- C=23⇒Locate A,B,"W"
- C=24⇒Locate A,B,"X"
- C=25⇒Locate A,B,"Y"
- Else Then C=26⇒Locate A,B,"Z"
- C=27⇒Locate A,B,"0"
- C=28⇒Locate A,B,"1"
- C=29⇒Locate A,B,"2"
- C=30⇒Locate A,B,"3"
- IfEnd
- Else If C≤35
- Then C=31⇒Locate A,B,"4"
- C=32⇒Locate A,B,"5"
- C=33⇒Locate A,B,"6"
- C=34⇒Locate A,B,"7"
- Else C=35⇒Locate A,B,"8"
- C=36⇒Locate A,B,"9"
- C=37⇒Locate A,B,"."
- C=38⇒Locate A,B,","
- C=39⇒Locate A,B,"/"
- C=40⇒Locate A,B,"+"
- IfEnd
- IfEnd
- Return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement