I'm wondering how I can make my snake to be a certain length.
I now have an infinite snake which keeps growing.
This is my code and I also have a domain error in it, which came when I added the box:

Code:
For(D,0,94)
Pxl-On(0,D)
Pxl-On(62,D)
For(E,0,62)
Pxl-On(E,0)
Pxl-On(E,94)

and the error is on this line:

Code:
If pxl-Test(Y,X)

This is the whole code.

Code:
ClrDraw
AxesOff
0→Xmin
0→Ymin
62→Ymax
94→Xmax
47→X
10→Y
1→D
1→A
0→B
0→C
For(D,0,94)
Pxl-On(0,D)
Pxl-On(62,D)
For(E,0,62)
Pxl-On(E,0)
Pxl-On(E,94)
While 1
If A=0
Then
Disp B
Stop
End
If C=0
Then
randInt(1,93)→S
randInt(1,61)→T
1→C
End
Pxl-On(T,S)
Pxl-On(Y,X)
getKey→K
If K=25
Then
If D≠2
Then
0→D
End
End
If K=26
Then
If D≠3
Then
1→D
End
End
If K=34
Then
If D≠0
Then
2→D
End
End
If K=24
Then
If D≠1
Then
3→D
End
End
If D=0
Then
Y-1→Y
End
If D=1
Then
X+1→X
End
If D=2
Then
Y+1→Y
End
If D=3
Then
X-1→X
End
If S=X and T=Y
Then
B+1→B
0→C
Else
If pxl-Test(Y,X)
Then
0→A
End
End
End
I recommend reading up on circular queues in Appendix D of "Programming the Ti-83 Plus/TI-84 Plus", which describes engineering a Snake game. Helpfully, it's available for free (although you should consider buying a copy of the book anyway, in my extremely biased opinion Very Happy ).

https://manning-content.s3.amazonaws.com/download/3/856f508-567e-4448-b40b-d91656fb2786/PTI_App.D.pdf
KermMartian wrote:
I recommend reading up on circular queues in Appendix D of "Programming the Ti-83 Plus/TI-84 Plus", which describes engineering a Snake game. Helpfully, it's available for free (although you should consider buying a copy of the book anyway, in my extremely biased opinion Very Happy ).

https://manning-content.s3.amazonaws.com/download/3/856f508-567e-4448-b40b-d91656fb2786/PTI_App.D.pdf


Thank you, I'll read it and add the needed parts.
Quote:

Code:

If K=25
Then
If D≠2
Then
0→D
End
End


Just thought it would be helpful, instead of using two If-then statements for this you could just us an And:


Code:

If K=25 and D≠2
0→D


There are many places within your code that can be refined. Other than that i think your programs pretty cool, thanks for sharing.

Also, if you only have one statement after an if, like:

Code:

If D=2
then
Y+1→Y
end

It works the same way without the Then or End, like:

Code:

If D=2
Y+1→Y


The if statement only extends one line farther unless you add a then, but it is not necessary if your only stating one thing.
Stardust49 wrote:
Quote:

Code:

If K=25
Then
If D≠2
Then
0→D
End
End


Just thought it would be helpful, instead of using two If-then statements for this you could just us an And:


Code:

If K=25 and D≠2
0→D


There are many places within your code that can be refined. Other than that i think your programs pretty cool, thanks for sharing.

Also, if you only have one statement after an if, like:

Code:

If D=2
then
Y+1→Y
end

It works the same way without the Then or End, like:

Code:

If D=2
Y+1→Y


The if statement only extends one line farther unless you add a then, but it is not necessary if your only stating one thing.


Thank you very very much for pointing things like this out. I really want to learn and get write better TI-BASIC code. I'll fix that right away. Thank you for your opinion also, I appreciate it.
  
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