The QBasic / QB64 Discussion Forum      Other Subforums, Links and Downloads
 
 

 Return to Index  

tictaktoe

January 14 2008 at 2:28 PM
Dude  (Premier Login iorr5t)
Forum Owner

 
DECLARE SUB ExtraMove2.data ()
DECLARE SUB ExtraMove.data ()
DECLARE SUB Draw.data ()
DECLARE SUB Draw2.data ()
DECLARE SUB Check.data ()
DECLARE SUB Check2.data ()
DECLARE SUB Tie.data ()
DECLARE SUB Finish.data ()
DECLARE SUB Winner.data ()
DECLARE SUB Winner2.data ()
DECLARE SUB Input.data ()
DECLARE SUB Welcome.data ()
DECLARE SUB grid.data ()
DECLARE SUB anykey ()

DIM SHARED s1p1, s2p1, s3p1, s4p1, s5p1, s6p1, s7p1, s8p1, s9p1, s1p2, s2p2, s3p2, s4p2, s5p2, s6p2, s7p2, s8p2, s9p2, p1$, p2$, c, pl1name$, pl2name$

CLS

CALL Welcome.data
CALL grid.data
CALL Input.data
CALL Winner.data:

SUB anykey
WHILE INKEY$ = ""
WEND
END SUB

SUB Check.data
CLS
SCREEN 12
IF s1p1 + s2p1 + s3p1 = 3 THEN
CALL Winner.data
ELSEIF s3p1 + s5p1 + s6p1 = 3 THEN
CALL Winner.data
ELSEIF s7p1 + s8p1 + s9p1 = 3 THEN
CALL Winner.data
ELSEIF s1p1 + s4p1 + s7p1 = 3 THEN
CALL Winner.data
ELSEIF s2p1 + s5p1 + s8p1 = 3 THEN
CALL Winner.data
ELSEIF s3p1 + s6p1 + s9p1 = 3 THEN
CALL Winner.data
ELSEIF s1p1 + s5p1 + s9p1 = 3 THEN
CALL Winner.data
ELSEIF s3p1 + s5p1 + s7p1 = 3 THEN
CALL Winner.data
END IF

END SUB

SUB Check2.data
IF s1p2 + s2p2 + s3p2 = 3 THEN
CALL Winner2.data
ELSEIF s4p2 + s5p2 + s6p2 = 3 THEN
CALL Winner2.data
ELSEIF s7p2 + s8p2 + s9p2 = 3 THEN
CALL Winner2.data
ELSEIF s1p2 + s4p2 + s7p2 = 3 THEN
CALL Winner2.data
ELSEIF s2p2 + s5p2 + s8p2 = 3 THEN
CALL Winner2.data
ELSEIF s3p2 + s6p2 + s9p2 = 3 THEN
CALL Winner2.data
ELSEIF s1p2 + s5p2 + s9p2 = 3 THEN
CALL Winner2.data
ELSEIF s3p2 + s5p2 + s7p2 = 3 THEN
CALL Winner2.data
END IF


END SUB

SUB Draw.data
'Player 1 X's
IF p1$ = "a1" THEN
IF s1p2 = 1 THEN
CALL ExtraMove.data
GOTO SkipDraw
END IF
LINE (155, 55)-(245, 145), 1
LINE (245, 55)-(155, 145), 1
LET s1p1 = 1
ELSEIF p1$ = "a2" THEN
IF s2p2 = 1 THEN
CALL ExtraMove.data
GOTO SkipDraw
END IF
LINE (255, 55)-(345, 145), 1
LINE (345, 55)-(255, 145), 1
LET s2p1 = 1
ELSEIF p1$ = "a3" THEN
IF s3p2 = 1 THEN
CALL ExtraMove.data
GOTO SkipDraw
END IF
LINE (355, 55)-(445, 145), 1
LINE (445, 55)-(355, 145), 1
LET s3p1 = 1
ELSEIF p1$ = "b1" THEN
IF s4p2 = 1 THEN
CALL ExtraMove.data
GOTO SkipDraw
END IF
LINE (155, 155)-(245, 245), 1
LINE (245, 155)-(155, 245), 1
LET s4p1 = 1
ELSEIF p1$ = "b2" THEN
IF s5p2 = 1 THEN
CALL ExtraMove.data
GOTO SkipDraw
END IF
LINE (255, 155)-(345, 245), 1
LINE (345, 155)-(255, 245), 1
LET s5p1 = 1
ELSEIF p1$ = "b3" THEN
IF s6p2 = 1 THEN
CALL ExtraMove.data
GOTO SkipDraw
END IF
LINE (355, 155)-(445, 245), 1
LINE (445, 155)-(355, 245), 1
LET s6p1 = 1
ELSEIF p1$ = "c1" THEN
IF s7p2 = 1 THEN
CALL ExtraMove.data
GOTO SkipDraw
END IF
LINE (155, 255)-(245, 345), 1
LINE (245, 255)-(155, 345), 1
LET s7p1 = 1
ELSEIF p1$ = "c2" THEN
IF s8p2 = 1 THEN
CALL ExtraMove.data
GOTO SkipDraw
END IF
LINE (255, 255)-(345, 345), 1
LINE (345, 255)-(255, 345), 1
LET s8p1 = 1
ELSEIF p1$ = "c3" THEN
IF s9p2 = 1 THEN
CALL ExtraMove.data
GOTO SkipDraw
END IF
LINE (355, 255)-(445, 345), 1
LINE (445, 255)-(355, 345), 1
LET s9p1 = 1
END IF

SkipDraw:
END SUB

SUB Draw2.data

'Player 2 O's
IF p2$ = "a1" THEN
IF s1p1 = 1 THEN
CALL ExtraMove2.data
GOTO Skipdraw2
END IF
CIRCLE (200, 100), 48, 4
LET s1p2 = 1
ELSEIF p2$ = "a2" THEN
IF s2p1 = 1 THEN
CALL ExtraMove2.data
GOTO Skipdraw2
END IF
CIRCLE (300, 100), 48, 4
LET s2p2 = 1
ELSEIF p2$ = "a3" THEN
IF s3p1 = 1 THEN
CALL ExtraMove2.data
GOTO Skipdraw2
END IF
CIRCLE (400, 100), 48, 4
LET s3p2 = 1
ELSEIF p2$ = "b1" THEN
IF s4p1 = 1 THEN
CALL ExtraMove2.data
GOTO Skipdraw2
END IF
CIRCLE (200, 200), 48, 4
LET s4p2 = 1
ELSEIF p2$ = "b2" THEN
IF s5p1 = 1 THEN
CALL ExtraMove2.data
GOTO Skipdraw2
END IF
CIRCLE (300, 200), 48, 4
LET s5p2 = 1
ELSEIF p2$ = "b3" THEN
IF s6p1 = 1 THEN
CALL ExtraMove2.data
GOTO Skipdraw2
END IF
CIRCLE (400, 200), 48, 4
LET s6p2 = 1
ELSEIF p2$ = "c1" THEN
IF s7p1 = 1 THEN
CALL ExtraMove2.data
GOTO Skipdraw2
END IF
CIRCLE (200, 300), 48, 4
LET s7p2 = 1
ELSEIF p2$ = "c2" THEN
IF s8p1 = 1 THEN
CALL ExtraMove2.data
GOTO Skipdraw2
END IF
CIRCLE (300, 300), 48, 4
LET s8p2 = 1
ELSEIF p2$ = "c3" THEN
IF s9p1 = 1 THEN
CALL ExtraMove2.data
GOTO Skipdraw2
END IF
CIRCLE (400, 300), 48, 4
LET s9p2 = 1
END IF

Skipdraw2:
END SUB

SUB ExtraMove.data

INPUT "Player 1: ", p1$
CALL grid.data
CALL Draw.data
CALL Check.data
CALL Check2.data

END SUB

SUB ExtraMove2.data

INPUT "Player 2: ", p2$
CALL grid.data
CALL Draw2.data
CALL Check.data
CALL Check2.data


END SUB

SUB Finish.data
END
END SUB

SUB grid.data

SCREEN 12
'Vertical
LINE (150, 50)-(150, 350), 2
LINE (250, 50)-(250, 350), 2
LINE (350, 50)-(350, 350), 2
LINE (450, 50)-(450, 350), 2
'Horizontal
LINE (150, 50)-(450, 50), 2
LINE (150, 150)-(450, 150), 2
LINE (150, 250)-(450, 250), 2
LINE (150, 350)-(450, 350), 2
'Labels
LOCATE 7, 15
PRINT "a"
LOCATE 13, 15
PRINT "b"
LOCATE 19, 15
PRINT "c"
LOCATE 2, 26
PRINT "1"
LOCATE 2, 38
PRINT "2"
LOCATE 2, 50
PRINT "3"
CALL anykey
END SUB

SUB Input.data

LOCATE 24, 1
PRINT "Input the row and column number (example a1 or b3)"
LOCATE 5, 1
DO UNTIL c >= 8
COLOR 1
CALL grid.data
INPUT "Player 1: ", p1$
LET c = c + 1
CALL Draw.data
CALL Check.data
CALL Check2.data
COLOR 4
CALL grid.data
INPUT "Player 2: ", p2$
LET c = c + 1
CALL Draw2.data
CALL Check.data
CALL Check2.data
LOOP
'Ninth turn
COLOR 1
CALL grid.data
INPUT "Player 1: ", p1$
CALL Draw.data
CALL Check.data
CALL Check2.data
CALL Tie.data


END SUB

SUB Tie.data

LOCATE 26, 1
COLOR 15
PRINT "Draw"
CALL Finish.data

END SUB

SUB Welcome.data

COLOR 15
LOCATE 20, 5
INPUT "Player 1's name: ", pl1name$
LOCATE 21, 40
COLOR 4
INPUT "Player 2's name: ", pl2name$

END SUB

SUB Winner.data

LOCATE 26, 1
COLOR 1
PRINT pl1name$; " has won!"
COLOR 15
CALL Finish.data

END SUB

SUB Winner2.data

LOCATE 26, 1
COLOR 4
PRINT pl2name$; " has won!"
COLOR 15
CALL Finish.data

END SUB

 
 Respond to this message   
Response TitleAuthor and Date
FixedSweet on Jan 14
 Copyright © 1999-2014 Network54. All rights reserved.   Terms of Use   Privacy Statement  

Newbies usually go to www.qbasic.com and click on The QBasic Forum
Forum regulars have their own ways, which include The QBasic Community Forums