TI-83 Plus BASIC Programming Tutorial: A Beginners' Guide
|
CYLINDER AREA ANSWER:
: ClrHome:Prompt L,R
: LR2A
: Output(4,2,"AREA IS:":Output(5,2,A
: Pause
: ClrHome
The screen is cleared, and the user is asked for the values of L and R. These two values are automatically stored into the letters L and R. The value R is squared, and multiplied by pi and then by the value L (the order of operations is built into the calculator's code) and stored as the variable 'A'. A is then outputted in order to show the user the answer. After the user presses ENTER the screen is cleared.
COUNTING ANSWER:
Obviously a counting program involves some kind of FOR loop, so your program should look something like the following:
: ClrHome
: For(X,0,200)
: Output(2,7,X
: End
The program could also be coded using WHILE or LBL and GOTO, but they are both inefficient in this case.
The screen is cleared and the variable 'X' is assigned to the value 0. The value is increased by 1 (since there is no interval assigned, it is automatically set to 1) at the speed of the calculator's processor. This value keeps increasing and being displayed until the value of X hits 2000, and at that point the loop breaks, as signified by END.
SIMPLE MOVEMENT ANSWER:
Here's how it works: The user selects an action from the menu; lets say its 'MOVE UP'. The value 1 is subtracted from the pre-designated variable, X, which represents how high up the 'O' is. Then the character is redrawn with the new coordinates, and another character (" "), which is just a blank space, is placed where the character used to be. If the coordinates of the character are outside the range of the screen, they will be changed accordingly.
Your program should look something like this:
:ClrHome
:4X
:8Y
:Lbl A
:Output(X,Y," "
:Menu("---MENU---","MOVE UP",UP,"MOVE DOWN",DN,"MOVE LEFT",LT,"MOVE RIGHT",RT,"EXPLODE",EX,"QUIT",X)
:End
:Lbl X
:ClrHome
:Stop
:End
:Lbl UP
:X-1X
:Goto B
:End
:Lbl DN
:X+1X
:Goto B
:Lbl LT
:Y-1Y
:Goto B
:End
:Lbl RT
:Y+1Y
:Goto B
:End
:Lbl EX
:For(A,0,100
:Outout(X,Y,"*"
:End
:For(A,0,50)
:Output(X-1,Y-1,"*"
:Output(X+1,Y+1,"*"
:Output(X+1,Y-1,"*"
:Output(X-1,Y+1,"*"
:End
:Goto X
:Lbl B
:For(A,0,30)
:If X=0:1X
:If X=9:8X
:If Y=0:1Y
:If Y=17:16Y
:Output(X,Y,"O"
:End
:Goto A
ADVANCED MENU ANSWER:
This program works in a very simple way: when the user presses up or down, the value of 1 is subtracted from X, which represents the y-axis of the cursor. When the user presses Í, the calculator detects the value of X, in order to see which choice the user made. It then executes the appropriate code.
Your menu should look something like this:
:ClrHome
:3X
:Lbl A
:Output(1,1,"::::::MENU::::::"
:Output(3,4,"CHOICE 1"
:Output(4,4,"CHOICE 2"
:Output(5,4,"CHOICE 3"
:Output(6,4,"CHOICE 4"
:Output(7,4,"QUIT"
:Output(8,1,"................"
:Output(X,3,"["
:Output(X,12,"]"
:While 1
:getKeyA
:While A=0
:getKeyA
:End
:If A=25
:Goto UP
:If A=34
:Goto DN
:If A=105
:Goto EN
:If A25 or 34 or 105
:Goto A
:End
:Lbl UP
:Output(X,3," "
:Output(X,12," "
:X-1X
:If X=2
:7X
:Goto A
:Goto A
:End
:Lbl DN
:Output(X,3," "
:Output(X,12," "
:X+1X
:If X=8
:3X
:Goto A
:Goto A
:End
:Lbl EN
:If X=3
:Goto 1
:If X=4
:Goto 2
:If X=5
:Goto 3
:If X=6
:Goto 4
:If X=7
:Goto X
:End
:Lbl X
:ClrHome
:Stop
:End
:Lbl 1
:Disp "YOU SELECTED","CHOICE I"
:Pause
:ClrHome
:End
:Lbl 2
:Disp "YOU SELECTED","CHOICE II"
:Pause
:ClrHome
:End
:Lbl 3
:Disp "YOU SELECTED","CHOICE III"
:Pause
:ClrHome
:End
:Lbl 4
:Disp "YOU SELECTED","CHOICE IV"
:Pause
:ClrHome
:End
MOVE ANSWER:
How it works: every time the user presses an arrow key, 1 is either added or subtracted from the x or y axis of the character, and an empty space is put in place of the old coordinates of the character. If the x and y coordinates of the character is equal to the a and b coordinates of the bonus, or the (1,1) coordinates of the 'O', there is a special piece of code that tells the TI what to do. In this case, either the message 'YOU WIN' is displayed on the screen, or the message 'BONUS' flashes twice, and 10 points are added to LMOVT.
You move program should look something like this:
:ClrHome
:0K
:4X
:5Y
:randInt(1,8)A
:randInt(1,16)B
:Output(A,B,"S"
:1dim(L
MOVT)
:If A=1 and B=1
:Then
:randInt(1,8)A
:randInt(1,16)B
:Lbl A
:Output(1,1,"O"
:Output(X,Y,""
:While 1
:getKeyG
:While G=0
:getKeyG
:End
:If G=24
:Goto LT
:If G=25
:Goto UP
:If G=26
:Goto RT
:If G=34
:Goto DN
:If G24 or 25 or 26 or 34
:Goto A
:End
:Lbl RT
:Output(X,Y," "
:Y+1Y
:If Y=17
:1Y
:If X=A and Y=B
:Goto BN
:If X=1 and Y=1
:Goto B
:Goto A
:End
:Lbl LT
:Output(X,Y," "
:Y-1Y
:If Y=0
:16Y
:If X=A and Y=B
:Goto BN
:If X=1 and Y=1
:Goto B
:Goto A
:End
:Lbl DN
:Output(X,Y," "
:X+1X
:If X=9
:1X
:If X=A and Y=B
:Goto BN
:If X=1 and Y=1
:Goto B
:Goto A
:End
:Lbl UP
:Output(X,Y," "
:X-1X
:If X=0
:8X
:If X=A and Y=B
:Goto BN
:If X=1 and Y=1
:Goto B
:Goto A
:End
:Lbl B
:For(D,0,100
:Output(4,3,"-!YOU WIN!-"
:End
:Stop
:ClrHome
:End
:Lbl BN
:10LMOVT(1)
:Lbl N
:For(A,0,20
:Output(4,5,"BONUS"
:End
:For(A,0,20
:Output(4,5," "
:End
:K+1K
:If K=5
:Goto A
:Goto N
:End
NESTED LOOPS CHALLENGE:
You move program should look something like this:
:ClrDraw
:0R
:While R<50
:For(X,-R,R)
:(R2-X2)1/2Y
:Pt-On(X,Y)
:Pt-On(X,-Y)
:End
:R+1R
:End
|
|
|