Hi...I have posted here once with a question but it was way back and i figured it out by myself :) the thing is, i dont catch onto qbasic well at all. it involves math and a lot of memorization which i am really bad at :rolleyes: right now, i have a tictactoe game im working on. i will give you the code but i know very little in qbasic so i just know the bare minimum....
my question is, do you guys think this is how it should start out? Because I have been on it for 2 days trying to think of a logical way to even begin this program & I cant....i mean the "logic" half. I know I need to loop the questions & the game if the user would like to replay it. this is a 2 user game. also, i have nooo idea how to even be able to tell if the user has 3 in a row or anything. maybe by converting the answer to a number and somehow working from there? ugh sorry...im so bad at this. im extremely frustrated too so any help is greatly appreciated :cry:

omg not again...can someone PLEASE tell me how to paste the code here? when i do, it doesnt take it from qbasic....it takes it from the last place i copied from not in qbasic. for some reason, ive never been able to get how to paste anything INTO qbasic or copy and paste something out of qbasic. i can only do it in the program....
im sorry, i dont know barely ANYTHING and you guys probably think i havent tried hard enough but please help. :sad:

now i sound pathetic...ha
thank you
- Fara

## All 6 Replies

OK to copypaste it open the qbasic file in note pad

a: lots of ifs depending if you make levels for it

to be cheeky

you could use the random function (i think it's in qbas) but is in vb

as there are 9 squares use integers

use an aray, for i = 1-(random*1) [making sure it is only 1 number therfore 1] (this giving a random square for the Prog to go)

make sure that the square isn't already taken

hope some of this logic helps abit you could always look on www.planetsourcecode.com

CLS
SCREEN 12
WINDOW (0, 0)-(1000, 800)
COLOR 11
REM VERTICAL LINE 1
LINE (435, 400)-(435, 600)
REM VERTICAL LINE 2
LINE (515, 400)-(515, 600)
REM HORIZONTAL LINE 1
LINE (375, 460)-(575, 460)
REM HORIZONTAL LINE 2
LINE (375, 535)-(575, 535)
LOCATE 7.1, 32
PRINT "A"
LOCATE 7, 37.5
PRINT "B"
LOCATE 7, 44
PRINT "C"
LOCATE 9, 28
PRINT "1"
LOCATE 12, 28
PRINT "2"
LOCATE 15, 28
PRINT "3"
LOCATE 20, 1
INPUT "USER 1: ENTER A COLUMN LETTER THEN ROW NUMBER (FOR EXAMPLE, B2 WILL MAKE AN X IN THE CENTER SQUARE)"; X\$
INPUT "USER 2: ENTER A COLUMN LETTER THEN ROW NUMBER (FOR EXAMPLE, B2 WILL MAKE AN O IN THE MIDDLE SQUARE)"; O\$
IF X\$ = "A1" THEN
LINE (379, 539)-(431, 598)
LINE (379, 598)-(431, 539)
ELSEIF X\$ = "B1" THEN
LINE (439, 598)-(511, 539)
LINE (439, 539)-(511, 598)
ELSEIF X\$ = "C1" THEN
LINE (519, 539)-(571, 598)
LINE (519, 598)-(571, 539)
ELSEIF X\$ = "A2" THEN
LINE (379, 463)-(435, 531)
LINE (379, 531)-(435, 463)
ELSEIF X\$ = "B2" THEN
LINE (439, 463)-(511, 531)
LINE (439, 531)-(511, 463)
ELSEIF X\$ = "C2" THEN
LINE (519, 463)-(571, 531)
LINE (519, 531)-(571, 463)
ELSEIF X\$ = "A3" THEN
LINE (379, 400)-(435, 458)
LINE (379, 458)-(435, 400)
ELSEIF X\$ = "B3" THEN
LINE (439, 400)-(511, 458)
LINE (439, 458)-(511, 400)
ELSEIF X\$ = "C3" THEN
LINE (519, 400)-(571, 458)
LINE (519, 458)-(571, 400)
ELSEIF O\$ = "A1" AND X\$ <> "A1" THEN
CIRCLE (402, 568), 28
ELSEIF O\$ = "B1" AND X\$ <> "B1" THEN
CIRCLE (475, 570), 28
ELSEIF O\$ = "C1" AND X\$ <> "C1" THEN
CIRCLE (548, 570), 28
ELSEIF O\$ = "A2" AND X\$ <> "A2" THEN
CIRCLE (402, 497), 28
ELSEIF O\$ = "B2" AND X\$ <> "B2" THEN
CIRCLE (475, 497), 30
ELSEIF O\$ = "C2" AND X\$ <> "C2" THEN
CIRCLE (550, 499), 30
ELSEIF O\$ = "A3" AND X\$ <> "A3" THEN
CIRCLE (402, 425), 28
ELSEIF O\$ = "B3" AND X\$ <> "B3" THEN
CIRCLE (475, 425), 30
ELSEIF O\$ = "C3" AND X\$ <> "C3" THEN
CIRCLE (550, 425), 28
END IF

thats what i have...i dontthink i did anything right but as you can see, im not that skilled. i know randomize, int, and all that but nothing too complicated. suroot: i have no idea what that means but i'll check out the site, thanks!

``````CLS
SCREEN 12
WINDOW (0, 0)-(1000, 800)
COLOR 11
REM VERTICAL LINE 1
LINE (435, 400)-(435, 600)
REM VERTICAL LINE 2
LINE (515, 400)-(515, 600)
REM HORIZONTAL LINE 1
LINE (375, 460)-(575, 460)
REM HORIZONTAL LINE 2
LINE (375, 535)-(575, 535)
LOCATE 7.1, 32
PRINT "A"
LOCATE 7, 37.5
PRINT "B"
LOCATE 7, 44
PRINT "C"
LOCATE 9, 28
PRINT "1"
LOCATE 12, 28
PRINT "2"
LOCATE 15, 28
PRINT "3"
LOCATE 20, 1
INPUT "USER 1: ENTER A COLUMN LETTER THEN ROW NUMBER (FOR EXAMPLE, B2 WILL MAKE AN X IN THE CENTER SQUARE)"; X\$
INPUT "USER 2: ENTER A COLUMN LETTER THEN ROW NUMBER (FOR EXAMPLE, B2 WILL MAKE AN O IN THE MIDDLE SQUARE)"; O\$
IF X\$ = "A1" THEN
LINE (379, 539)-(431, 598)
LINE (379, 598)-(431, 539)
ELSEIF X\$ = "B1" THEN
LINE (439, 598)-(511, 539)
LINE (439, 539)-(511, 598)
ELSEIF X\$ = "C1" THEN
LINE (519, 539)-(571, 598)
LINE (519, 598)-(571, 539)
ELSEIF X\$ = "A2" THEN
LINE (379, 463)-(435, 531)
LINE (379, 531)-(435, 463)
ELSEIF X\$ = "B2" THEN
LINE (439, 463)-(511, 531)
LINE (439, 531)-(511, 463)
ELSEIF X\$ = "C2" THEN
LINE (519, 463)-(571, 531)
LINE (519, 531)-(571, 463)
ELSEIF X\$ = "A3" THEN
LINE (379, 400)-(435, 458)
LINE (379, 458)-(435, 400)
ELSEIF X\$ = "B3" THEN
LINE (439, 400)-(511, 458)
LINE (439, 458)-(511, 400)
ELSEIF X\$ = "C3" THEN
LINE (519, 400)-(571, 458)
LINE (519, 458)-(571, 400)
ELSEIF O\$ = "A1" AND X\$ <> "A1" THEN
CIRCLE (402, 568), 28
ELSEIF O\$ = "B1" AND X\$ <> "B1" THEN
CIRCLE (475, 570), 28
ELSEIF O\$ = "C1" AND X\$ <> "C1" THEN
CIRCLE (548, 570), 28
ELSEIF O\$ = "A2" AND X\$ <> "A2" THEN
CIRCLE (402, 497), 28
ELSEIF O\$ = "B2" AND X\$ <> "B2" THEN
CIRCLE (475, 497), 30
ELSEIF O\$ = "C2" AND X\$ <> "C2" THEN
CIRCLE (550, 499), 30
ELSEIF O\$ = "A3" AND X\$ <> "A3" THEN
CIRCLE (402, 425), 28
ELSEIF O\$ = "B3" AND X\$ <> "B3" THEN
CIRCLE (475, 425), 30
ELSEIF O\$ = "C3" AND X\$ <> "C3" THEN
CIRCLE (550, 425), 28
END IF``````

as you can see, im very dumb in qbasic. i am just taking this class for one semester but i need help..am i doing this right at all? or should i redo it in another way thank you suroot. ~Fara

I created a seperate subprogram for each player for most aspects of the game. The into screen may not work on some computers if it doesn't you can just delete the part that writes "Tic Tac Toe" onto the screen.

1. In a normal game of tic tac toe the first player gets one more turn than the other. This means that you need to put the first 8 moves in a loop but then have an "extra"move for player one outside of the loop.

2. Have the input for player 1 and player 2 in seperate sub-programs. This will make it easier to read and alter.

3. To determine if someone has won is really very simple. There are only 8 ways to get three in a row in tic tac toe. Assign each square a variable. If player one puts and X in a square let the variable for that square = 1. ( I made 18 variables: p1s1,p1s5,p2s1) where p is the player and s is the square. Then after each turn have a subprogram that checks to see if someone won by seeing if squares 1+2+3 = 3 for one of the players.

Here is the code for the program. Please don't just copy it. Try to figure out what I did and why yours isn't working.

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 ()
'Tic Tac Toe
'Created October 6, 2006 by Michael Burgoyne
'Final Project
'Contains 13 Sub-Programs

COMMON 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 Check.data

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 Draw.data
CALL Check.data
CALL Check2.data

END SUB

SUB ExtraMove2.data

INPUT "Player 2: ", p2\$
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"

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
INPUT "Player 1: ", p1\$
LET c = c + 1
CALL Draw.data
CALL Check.data
CALL Check2.data
COLOR 4
INPUT "Player 2: ", p2\$
LET c = c + 1
CALL Draw2.data
CALL Check.data
CALL Check2.data
LOOP
'Ninth turn
COLOR 1
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
'TIC TAC
COLOR 2
LOCATE 5, 14
PRINT "_______ _______ _____ _______ __ _____"
LOCATE 6, 14
PRINT " | | | | / \ | "
LOCATE 7, 14
PRINT " | | | | / \ | "
LOCATE 8, 14
PRINT " | | | | | | | "
LOCATE 9, 14
PRINT " | | | | |----| | "
LOCATE 10, 14
PRINT " | | | | | | | "
LOCATE 11, 14
PRINT " | | | | | | | "
LOCATE 12, 14
PRINT " | | | | | | | "
LOCATE 13, 14
PRINT " | | | | | | | "
LOCATE 14, 14
PRINT " | ___|___ |_____ | | | |_____"
'TOE
LOCATE 32, 27
PRINT "_______ _____ _______"
LOCATE 33, 27
PRINT " | | | | "
LOCATE 34, 27
PRINT " | | | | "
LOCATE 35, 27
PRINT " | | | | "
LOCATE 36, 27
PRINT " | | | | "
LOCATE 37, 27
PRINT " | | | |----- "
LOCATE 38, 27
PRINT " | | | | "
LOCATE 39, 27
PRINT " | | | | "
LOCATE 40, 27
PRINT " | | | | "
LOCATE 41, 27
PRINT " | | | | "
LOCATE 42, 27
PRINT " | |_____| |_______"

COLOR 15
LOCATE 25, 5
PRINT " Welcome to my game of Tic-Tac-Toe. This game is for two people only."
LOCATE 27, 20
PRINT " Created October 6,2006 by Michael Burgoyne"
LOCATE 29, 5
COLOR 1
INPUT "Player 1's name: ", pl1name\$
LOCATE 29, 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

i am just taking this class for one semester but i need help..am i doing this right at all? or should i redo it in another way thank you suroot. ~Fara
Posted on Dec 14th 2004

I created a seperate subprogram for each player for most aspects of the game. The into screen may not work on some computers if it doesn't you can just delete the part that writes "Tic Tac Toe" onto the screen.

Here is the code for the program. Please don't just copy it. Try to figure out what I did and why yours isn't working.

This must be on loooooooooooooooong semester, over 2 years :surprised

We might be able to help more if you ask a specific question - what are you wondering?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.