I created a connect 4 for the ti-84 c
Features:
*Movement
*Borders
Future plans:
*Gravity
*To get as close to the real game a possible
I would like if you could give me any suggestions as to what I should implement Into the game
Edit: As per Tifreak's suggestion, I got rid of the Lbl and Goto commands

Code:
ClrDraw
RecallGDB 1 //GDB 1 is blank
AxesOff
0->Xmin
7->Xmax
0->Ymin
7->Ymax
0->A
For(Z,0,7
Line(Z,0,Z,7
Line(0,Z,7,Z
End
0->Z
1->B
1->C
While B=1
14->X
5->Y
3(C=2->C
While C=1
Text(Y,X,"X
Repeat A
getkey ->A
End
If A!=105
Then
Text(Y,X,"    "//or just 4 spaces
If A=24
Then
X-38->X
X+38(X<14->X
End
If A=25
Then
Y-23->Y
Y+23(Y<5->Y
End
If A=26
Then
X+38->X
X-38(X>260->X
End
If A=34
Then
Y+23->Y
Y-23(Y>160->Y
End
0->A
End
If A=105
Then
0->A
2->C
14->X
5->Y
End
End
While C=3
Text(Y,X,"O
Repeat A
getkey ->A
End
If A!=105
Then
Text(Y,X,"    "//or just 4 spaces
If A=24
Then
X-38->X
X+38(X<14->X
End
If A=25
Then
Y-23->Y
Y+23(Y<5->Y
End
If A=26
Then
X+38->X
X-38(X>260->X
End
If A=34
Then
Y+23->Y
Y-23(Y>160->Y
End
0->A
End
If A=105
Then
0->A
14->X
5->Y
1->C
End
End
End

As of now if you, while moving, go over a piece it will erase that piece.
Just a note, you should never use a Goto statement inside of a loop created by Repeat or While, or inside an If Then End conditional. It causes a memory leak.

Edit: As requested, using While loops in place of Lbl Goto


Code:

1->W
While iPart(W)=1   \\This sets up your 'master' loop
conditional checking fPart(W)=0.#, change W to go to new code block
While W=#
Do things, change value of W
End   \\While W=#

If W=#2:Then
Do things, change value of W
End


Store 1.# to W, starts back at top
End   \\End for While 1


Very simple version of what I do to bypass Goto and Lbl. It can be somewhat complicated, you have to stay on top of your End statement placements. I like to do things like

End:"W=#

So I know if it's in the right location. I just remove the strings once the game/program is complete. Some may argue against it, but I've found it faster during program run time than dealing with Lbl and Goto. http://www.ticalc.org/archives/files/fileinfo/452/45244.html was programmed in this manner,so you can see what all I did, though it's a rather large program.
Thanks for telling me Smile
*Update*
Cut program size in half
Edit: Fixed a problem with the code

Code:
ClrDraw
RecallGDB 1 //GDB 1 is blank
AxesOff
0->Xmin
7->Xmax
0->Ymin
7->Ymax
0->A
For(Z,0,7
Line(Z,0,Z,7
Line(0,Z,7,Z
End
1->Z
1->B
While B=1
14->X
5->Y
1->C
If Z=1
"X"->Str 1
If Z=2
"O"->Str 1
While C=1
Text(Y,X,Str 1
Repeat A
getkey ->A
End
If A!=105
Then
Text(Y,X,"    "//or just 4 spaces
If A=24
Then
X-38->X
X+38(X<14->X
End
If A=25
Then
Y-23->Y
Y+23(Y<5->Y
End
If A=26
Then
X+38->X
X-38(X>260->X
End
If A=34
Then
Y+23->Y
Y-23(Y>160->Y
End
End
If A=105
Then
2->C
If Z=2
Then
1->Z
1->L
End
2(Z=1)-(L=1)->Z
0->L
End
End
End

Code:
If A=24
Then
X-38->X
X+38(X<14->X
End
If A=25
Then
Y-23->Y
Y+23(Y<5->Y
End
If A=26
Then
X+38->X
X-38(X>260->X
End
If A=34
Then
Y+23->Y
Y-23(Y>160->Y
End


Here's a little something that does just that:


Code:
X-38((A=24 and X>38)-(A=26 and X<228→X
Y-23((A=25 and Y>23)-(A=34 and Y<138→Y


Also, instead of 0→A, use DelVar A Very Happy

Good luck with gravity! You are making some great progress! Smile
Thanks I will implement that code into the next revision:D
As per MateoConLechuga suggestion here's a new revision Very Happy It cut the size down over a half of the previous revision.

Code:
ClrDraw
RecallGDB 1 //GDB 1 is blank
AxesOff
0->Xmin
7->Xmax
0->Ymin
7->Ymax
0->A
For(Z,0,7
Line(Z,0,Z,7
Line(0,Z,7,Z
End
1->Z
1->B
While B=1
14->X
5->Y
1->C
0->L
If Z=1
"X"->Str 1
If Z=2
"O"->Str 1
While C=1
Text(Y,X,Str 1
Repeat A
getkey ->A
End
If A!=105
Then
Text(Y,X,"    "//or just 4 spaces
X-38((A=24 and X>38)-(A=26 and X<226->X
Y-23((A=25 and Y>23)-(A=34 and X<136->Y
End
End
If A=105
Then
2->C
If Z=2
Then
1->Z
1->L
End
2(Z=1)-(L=1)->Z
End
End
End

Code:
1->B
While B=1


This is somewhat redundant, as B is never modified in the code. Perhaps something like:


Code:
Repeat A=45


Would be more efficient. Also, the variable Y is not really a good idea to use in practice, as it is sometimes used by other utilities during program execution, and thus is liable to mess up your program, making it difficult to nail down the problem.

In addition, strings and other variables when they are stored typically do not need end quotes or parentheses. Thus,


Code:
If Z=1
"X"->Str 1
If Z=2
"O"->Str 1


Could also be:

Code:

"O
If Z=1:"X
Ans→Str1


About a 6 byte save amount.

Furthermore, this line:

Code:
1->C
0->L

And this line:

Code:
7->Ymax
0->A
For(Z,0,7


Could be changed to save 2 bytes by doing this:

Code:
DelVarL1->C

DelVar A7->Ymax
For(Z,0,7


You do not need a line separation or colon after a DelVar.

Hopefully all of this helps in some way; it is getting better and better! Great job keeping it up! Very Happy
Thanks! I haven't been on in a couple of days so I didn't get to see your comment. I have the gravity almost complete. I should have it posted in less than 30 minutes.
Gravity's Done! Here it is! I also made it so that you can use the top row without erasing the value in the top row.
Edit- Code flaw changed

Code:
{7,7->dim([A]
Fill(0,[A]
ClrDraw
RecallGDB 1 //GDB 1 is blank
AxesOff
0->Xmin
7->Xmax
0->Ymin
8->Ymax
For(Z,0,7
Line(Z,0,Z,7
Line(0,Z,7,Z
End
1->Z
Repeat A=1
14->X
25->Y
1->C
0->L
0->F
1->D
"O
If Z=1:"X
Ans→Str1
While C=1
Text(1,1,Str1
Pt-On(D-.5,7.5
Repeat A
getkey ->A
End
Pt-Off(D-.5,7.5
If A!=105
Then
X-38((A=24 and X>38)-(A=26 and X<226->X
D-19(A=24 and D>1)-(A=26 and D<7->D
End
End
If A=105
Then
For(E,1,7
If [A](E,D)=1
F+1->F
End
25+20(7-(F+1->Y
1->[A](7-F,D
Text(Y,X,Str1
If Z=2
Then
If Z=2
Then
1->Z
1->L
End
2(Z=1)-(L=1)->Z
2->C
End
If A=21 // This is just to set the graph back to normal
Then
ClrDraw
AxesOn
-10->xmin
10->xmax
-10->ymin
10->ymax
ClrHome
Return
End
End
End
It is looking better and better! Might a reccomend a couple more optimizations? Here's some:

This:

Code:
-10->xmin 
10->xmax 
-10->ymin 
10->ymax


Could be simply:

Code:
ZStandard


Another note would be that the line

Code:
2->C


Could be:

Code:
DelVar C or 0->C

If this was changed:


Code:
While C=1
To:
While C



Code:

2(Z=1)-(L=1)->Z
Could be:
2(Z=1)-(L=1->Z

25+20(7-(F+1->Y
Could be:
145-20F->Y


Also, try to avoid using the Y variable. Keep up the great work!
Very Happy
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement