Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

can't get this to work

Status
Not open for further replies.

rqtmom

Technical User
Apr 24, 2002
1
US

can someone please help me i cant get this to work

DIM Board$

FOR row = 1 TO 3
FOR col = 1 TO 3
PRINT Board$(col) + "| _ ";
NEXT col
PRINT "|"
NEXT row


PRINT "This is a game of Tic Tac Toe. Please type in the letter O for the"
PRINT "Second player and not the number."
INPUT "If you are the first player please type in X or O for the second player"; Player$
INPUT "Please type in 1 for the 1st position, 2 for the second etc."; position


DO WHILE Player$ <> Q$
IF Player$ = X$ THEN
SELECT CASE position
CASE 1
position = 1
LOCATE 1, 3
PRINT &quot;X&quot;
CASE 2
position = 2
LOCATE 1, 7
PRINT &quot;X&quot;
CASE 3
position = 3
LOCATE 1, 11
PRINT &quot;X&quot;
CASE 4
positon = 3
LOCATE 2, 3
PRINT &quot;X&quot;
CASE 5
position = 4
LOCATE 2, 7
PRINT &quot;X&quot;
CASE 6
position = 5
LOCATE 2, 11
PRINT &quot;X&quot;
CASE 7
position = 6
LOCATE 3, 3
PRINT &quot;X&quot;
CASE 8
position = 7
LOCATE 3, 7
PRINT &quot;X&quot;
CASE ELSE
position = 8
LOCATE 3, 11
PRINT &quot;X&quot;
END SELECT
ELSEIF Player$ = Q$ THEN
END
END IF

IF Player$ = O$ THEN
INPUT &quot;Please type in 1 for the 1st position, 2 for the second etc.&quot;; position
SELECT CASE position
CASE 1
position = 1
LOCATE 1, 3
PRINT &quot;O&quot;
CASE 2
position = 2
LOCATE 1, 7
PRINT &quot;O&quot;
CASE 3
position = 3
LOCATE 1, 11
PRINT &quot;O&quot;
CASE 4
positon = 3
LOCATE 2, 3
PRINT &quot;O&quot;
CASE 5
position = 4
LOCATE 2, 7
PRINT &quot;O&quot;
CASE 6
position = 5
LOCATE 2, 11
PRINT &quot;O&quot;
CASE 7
position = 6
LOCATE 3, 3
PRINT &quot;O&quot;
CASE 8
position = 7
LOCATE 3, 7
PRINT &quot;O&quot;
CASE ELSE
position = 8
LOCATE 3, 11
PRINT &quot;O&quot;
END SELECT
ELSEIF Player$ = Q$ THEN

END
END IF
LOOP

 
Most imoprtant, that you use non-initialised variables like X$ O$
You must assign them a values, or use constant strings &quot;X&quot; &quot;O&quot; and so on (and don't forget about case of the entered letters: &quot;X&quot; and &quot;x&quot; are different)
 
I would rebuild the whole bloody thing, there is a whole mess of things that you don't need.
Have you ever used two dimensional arrays?
draw the screen, then use the arrays to determine which square is marked and how. Use the arrow keys to move around the screen, using INKEY$ and then use:
a$ = INKEY$
IF UCASE$(a$) = &quot;X&quot; THEN mark(xpos,ypos) = &quot;X&quot;
 
Maybe I'm into mud but it seem to me that you didn't consider variables for there true meaning and fonctionality.

Variables are like boxes. They can contain differents things into them. A variable have:
- A NAME: that identify it from others one
- A TYPE: that determine the size and the kind of things it could have in
- A VALUE: the data store in it

A$ B% C&
|-----| |-----| |----------|
| X | | 8 | | 64200 |
|-----| |-----| |----------|

Lets take a look at your code now:
INPUT &quot;If you are the first player please type in X or O for the second player&quot;; Player$

You ask the player to put a value INTO the variable named Player$.

Lets take a look further:
DO WHILE Player$ <> Q$
IF Player$ = X$ THEN
SELECT CASE position

So there is the problem; you ask if Player$ = X$, you ask if the VALUE of Player$ EQUAL the VALUE of X$. And X$ as an undefine variable = &quot;&quot; or nothing. So, this is why your code always skip the select case.

Replace the variable NAME X$ by a VALUE &quot;X&quot; and you will get a better response from Qbasic ;-)

IF Player$ = &quot;X&quot; then
SELECT CASE position
...

But don't be too much happy with that; there's a lot of bugs that deserve(or must!!) be fixed! So keep working on your code, make tests and send it back if you need help again.

Oak
 
A couple of other points.

You are showing Board$(col) which is an array. What it is is not clear but if it IS an array you need to dimension it as an array.

In case someone is using lower case on the keyboard, check for upper case equivalent of player$ like this

IF UCASE$(player$) = &quot;X&quot; THEN

Your DO loop only checks the initial inputs, so having acted on them, it will go on for ever because there is no means to get other inputs.

There's no instruction for the user about entering 'Q'.

That should get you started.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top