:Lbl M
:Text(4,4,"THE GUESSING GAME
:Circle(4,7,8
:Pause
:ClrHome
:Output(4,2,"GUESS A NUMBER, 1‾10
:Pause
:ClrHome
:randInt(1,10→A
:Input B
:ClrHome
:Output(4,4,"YOU GOT....
:Pause
:ClrHome
:Output(4,4,B
:Pause
:ClrHome
:Output(4,4,"THE ANSWER IS...
:Pause
:ClrHome
:Output(4,4,A
:Pause
:If A=B
:Then
:ClrHome
:Output(4,4,"WINNER!
:Pause
:Else
:ClrHome
:Output(4,4,"LOSER...
:Pause
:ClrHome
:Menu("AGAIN?","PLAY AGAIN",PA,"QUIT",QU
:Lbl PA
:Goto M
:Lbl QU
:ClrHome



New program I created, yes its a guessing game, and would like any type of friendly advice, criticism, ANY form of improvements. Thanxs



EDIT: Also I would like to know why both my calc and sourcecoder2.0 sees it as GUESSrandM(
Allow me to suggest some optimizations:

First pass:

Code:
:Lbl M
:Text(4,4,"THE GUESSING GAME
:Circle(4,7,8
:Pause
:ClrHome
:Output(4,2,"GUESS A NUMBER, 1‾10
:Pause
:ClrHome
:randInt(1,10→A
:Input B
:ClrHome
:Output(4,4,"YOU GOT....
:Pause
:ClrHome
:Output(4,4,B
:Pause
:ClrHome
:Output(4,4,"THE ANSWER IS...
:Pause
:ClrHome
:Output(4,4,A
:Pause
:ClrHome
:If A=B:Then
:Output(4,4,"WINNER!
:Else
:Output(4,4,"LOSER...
:End
:Pause
:ClrHome
:Menu("AGAIN?","PLAY AGAIN",M,"QUIT",Q
:Lbl Q
:ClrHome


Note that I moved the redundant ClrHome and Pause outside of the If/Then/Else/End block, and I changed the PA->M Label/Goto to a simple jump to M.
hmm never thought i could do that!!


Thanks Kerm.
Second pass:

TIBasic Code wrote:
Lbl M
:Text(4,4,"THE GUESSING GAME
:Circle(4,7,8,i //makes circle rendering faster
:Pause
:ClrHome
:Output(4,2,"GUESS A NUMBER, 1‾10
:Pause
:ClrHome
:randInt(1,10→A
:Input B
:ClrHome
:Output(4,4,"YOU GOT....
:Pause
:ClrHome
:Output(4,4,B
:Pause
:ClrHome
:Output(4,4,"THE ANSWER IS...
:Pause
:ClrHome
:Output(4,4,A
:Pause
:ClrHome
:If A=B
:"WINNER!
If A-B:
:"LOSER...
:Output(4,4,Ans

:Pause
:ClrHome
:Menu("AGAIN?","PLAY AGAIN",M,"QUIT",Q
:Lbl Q
//one less redundant ClrHome


Less attractive, simpler version


Code:
Lbl M
:ClrHome
:Disp "GUESS A NUMBER, 1‾10
:Prompt G
:randInt(1,10→A
:Disp "CORRECT ANSWER:",A
:1+6(G=A
:Pause sub("WINNERLOSER ",Ans,6
:ClrHome
:Menu("AGAIN?","PLAY AGAIN",M,"QUIT",Q
:Lbl Q
Looping variant and explanation written for beginners: Click
Here's the simple movement code you requested:


Code:
:8->X:Repeat K=21:Output(1,X,"X
:Repeat K:getKey->K:End
:Output(1,X,"[space]
:X+(X>1)(K=26)-(K<16)(K=24->X
:End


Here it is with vertical movement too:


Code:
:8->X:4->Y:Repeat K=21:Output(Y,X,"X
:Repeat K:getKey->K:End
:Output(Y,X,"[space]
:X+(X<16)(K=26)-(X>1)(K=24->X
:Y-(Y>1)(K=25)+(Y<8)(K=34->Y
:End
KermMartian wrote:
Here's the simple movement code you requested:


Code:
:8->X:Repeat K=21:Output(1,X,"X
:Repeat K:getKey->K:End
:Output(1,X,"[space]
:X+(X>1)(K=26)-(K<16)(K=24->X
:End


Here it is with vertical movement too:


Code:
:8->X:4->Y:Repeat K=21:Output(Y,X,"X
:Repeat K:getKey->K:End
:Output(Y,X,"[space]
:X+(X<16)(K=26)-(X>1)(K=24->X
:Y-(Y>1)(K=25)+(Y<8)(K=34->Y
:End


well, the code I was gonna post would've been less optimized, but easier to read
just a note for when you make it to the graphscreen, you do not want to use X and Y for moving things around the screen. Just so you know, would be better to not get in that habit now.
tifreak8x wrote:
just a note for when you make it to the graphscreen, you do not want to use X and Y for moving things around the screen. Just so you know, would be better to not get in that habit now.
Actually, I usually just have problems with Y, because TI has a bit of a bug in ClrDraw. A and B would work, or X and Z, or any other pair.

Code:
4->A:4->B
While K≠22
Output(A,B,"X
getKey->K
If K:Output(A,B," "
A-(K=25)(A>1)+(K=34)(A<8->A
B-(K=24)(B>1)+(K=26)(B<16->B
End


My preferred setup. Sort of. :p

W for While becomes many different values through my games and programs, I use while loops to move around in programs like Lbl and Goto.

Edit:

Made it smaller. Easier to do when I am not busy pullin an engine out of a truck XD
I want weregoose's opinion. I saw he had some crazy key detecting stuff the other day.

Code:
4→A:8→B
Repeat K=22
Output(A,B,"X
getKey→K
If Ans
Output(A,B,"
max(1,min(8,A+max(ΔList(Ans={25,34→A
max(1,min(16,B+max(ΔList(K={24,26→B
End

Faster? No. But what is faster is using the "and" operator instead of multiplying two tests together!
Ok im just gonna dump my friends rom and then ill give you guys what i did...

...


here ya go


:8→A
:8→B
:For(T,1,200000
:ClrHome
:Output(A,B,"X
:getKey→K
:If K=26
:Then
:B+1→B
:End
:If K=24
:Then
:B-1→B
:End
:If K=25
:Then
:A-1→A
:End
:If K=34
:Then
:A+1→A
:If A>8
:1→A
:End
:If A<1
:Then
:8→A
:End
:End
Did you really call that shorter than mine? It's simpler, but some of the least-optimized code I've ever seen.

And you're doing it in a FOR LOOP?! Do you WANT your program to leak memory??
huh?

i thought you said for loops are better than lables...........
qazz42 wrote:
huh?


IRC wrote:
<saxjax> (C) qazz42: kerms code sucked cause it was soo long and i could not understand it, no offense


qazz42 wrote:
i thought you said for loops are better than f***ing lables...........
Yes, While and Repeat loops, which can be broken out of. For( loops are not the right thing to use here.
if I could say something, I would rather you not curse on the forums, thanks. As for the code...it really is unoptimized, really use someone else's. If you don't like it because it is hard to read, or you don't understand it, ask how it works, it will make you a better programmer
KermMartian wrote:
qazz42 wrote:
huh?


IRC wrote:
<saxjax> (C) qazz42: kerms code sucked cause it was soo long and i could not understand it, no offense


qazz42 wrote:
i thought you said for loops are better than f***ing lables...........
Yes, While and Repeat loops, which can be broken out of. For( loops are not the right thing to use here.


well iv been hearing from you guys that lbls were suckish compared to for loops scince i git here

geez im stupid sometimes...........
omg.. We TRIED to explain that to you.

While and Repeat loops. not For( loops. =/
im stupid...........


you can now begin to ignore me
  
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 3
» 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