Game Programming and Development Tools

Repeating Function – Commander_ACE

Commander_ACE
Junior Member

Posts: 7
From:
Registered: 02-14-2007
Hi, I am relatively new to programming. In Blitz Basic, I have been trying to make a Text-Based Tic-Tac-Toe. But, the PrintBoard() Function
keeps repeating and just draws boards straight down the left side of the screen. I would really like to know how to make it stop doing that.
Here is the code:

Graphics 800,600

AppTitle "Tic-Tac-Toe"

o_string$ = "O"
x_string$ = "X"

.begin

While Not KeyDown(1)

PrintBoard()

If KeyHit(57)
Cls
Goto begin
EndIf

If MouseDown(1)
Text MouseX(), MouseY(), o_string$
EndIf

If MouseDown(2)
Text MouseX(), MouseY(), x_String$
EndIf

Wend

End

Function PrintBoard()

Print " | | "
Print "--- --- --- "
Print " | | "
Print "--- --- --- "
Print " | | "

End Function

[This message has been edited by Commander_ACE (edited February 16, 2007).]

Mene-Mene

Member

Posts: 1398
From: Fort Wayne, IN, USA
Registered: 10-23-2006
Its because you're using print as your out put command, with the print command it adds a amount to a variable within it.

------------------
MM out-
Thought travels much faster than sound, it is better to think something twice, and say it once, than to think something once, and have to say it twice.
"Frogs and Fauns! The tournament!" - Professor Winneynoodle/HanClinto
I reserve the full right to change my views/theories at any time.

Commander_ACE
Junior Member

Posts: 7
From:
Registered: 02-14-2007
Any suggestions on how to fix it?
Mene-Mene

Member

Posts: 1398
From: Fort Wayne, IN, USA
Registered: 10-23-2006
Using double buffers, use the text command. Not sure how to ask for input.

Basically do something like this:


Graphics 800,600

SetBuffer BackBuffer()

Local O_String$ = "O" ;Why are you using these variables?
Local X_String$ = "X" ;See above comment

While Not KeyDown(1)

Cls

PrintBoard()

If KeyHit(57)

Cls

EndIf

If MouseDown(1)

Text MouseX(),MouseY(),O_String$

ElseIf MouseDown(2)

Text MouseX(),MouseY(),X_String$

EndIf

Flip

Wend

Function PrintBoard()

Text 100,100," | | " ;You add 13, the standard font height.
Text 100,113,"--- --- --- "
Text 100,126," | | "
Text 100,139,"--- --- --- "
Text 100,152," | | "

End Function

You'll notice that the x's and o's disappear right after you click. The problem is that it sets them there, then clears again. See if you can finish from here.

------------------
MM out-
Thought travels much faster than sound, it is better to think something twice, and say it once, than to think something once, and have to say it twice.
"Frogs and Fauns! The tournament!" - Professor Winneynoodle/HanClinto
I reserve the full right to change my views/theories at any time.

Commander_ACE
Junior Member

Posts: 7
From:
Registered: 02-14-2007
Thanks. I was using those variables because last time I tried using Text without variables, it wouldn't work ... I thought about using Buffers, but I wanted to try and make the program without them.

[This message has been edited by Commander_ACE (edited February 16, 2007).]

Mene-Mene

Member

Posts: 1398
From: Fort Wayne, IN, USA
Registered: 10-23-2006
Curious why you would want to not want to you multiple buffers?

------------------
MM out-
Thought travels much faster than sound, it is better to think something twice, and say it once, than to think something once, and have to say it twice.
"Frogs and Fauns! The tournament!" - Professor Winneynoodle/HanClinto
I reserve the full right to change my views/theories at any time.

Commander_ACE
Junior Member

Posts: 7
From:
Registered: 02-14-2007
I guess I just didn't want to...

I'll try it though.

[This message has been edited by Commander_ACE (edited February 16, 2007).]

Commander_ACE
Junior Member

Posts: 7
From:
Registered: 02-14-2007
Thanks for the code, all I had to do was take Cls out of the program and it worked.