The premise of this game is that you’re a stock trader, and all you have to do is buy stock when it’s low and sell it when it gets high for a profit. If the stock hits 200, you’ll double the number of stock you own; however, if the stock crashes, you lose ALL your stocks. Once the game starts, you just hit + to buy stock, – to sell stock, and the enter key to exit the program.
This is not a tutorial, so I won’t really be explaining the code in very much depth. Because this is not a tutorial, I will not be explaining the very simple things like how to create a new program. The only advice I will giv is if you can’t find a function on your keypad, hit 2nd – Catalog (the zero key) to find the function. Also, when you see L5(some number) I’m just using a single list as a variable rather than using letters. To type in L5, hit 2nd – 5.
The Code
:Disp “By Sean Kane”
:Pause
:Horiz
:AxesOff
:ClrDraw
:0->Ymin
:50->Ymax
:-10->Xmin
:10->Xmax
:-10->L5(1)
:100->L5(2)
:1000->L5(4)
:0->L5(5)
:Repeat 1=0
:Text(1,24,”Stock Roulette”)
:randInt(-15,15)->L5(6)
:L5(2)+L5(6)->L5(2)
:Line(L5(1),L5(2),L5(1)-.5,L5(3))
:L5(2)->L5(3)
:ClrHome
:Disp L5(2)
:Disp L5(5)
:Disp L5(4)
:L5(1)+.5->L5(1)
:If L5(2)>Ymax
:Then
:L5(2)+10->Ymax
:End
:If L5(2)<0
:Then
:100->L5(2)
:0->L5(5)
:End
:If L5(2)>200
:Then
:100->L5(2)
:L5(5)*2->L5(5)
:End
:If L5(1)=10
:Then
:-10->L5(1)
:ClrDraw
:End
:GetKey->L5(7)
:If L5(7)=85 and L5(5)>0
:Then
:L5(5)-1->L5(5)
:L5(4)+L5(2)->L5(4)
:End
:If L5(7)=95 and L5(4)>L5(2)
:Then
:L5(5)+1->L5(5)
:L5(4)-L5(2)->L5(4)
:End
:If L5(7)=105
:Then
:Full
:Stop
:End
:End
Explanation of Variables
The advantage to using list variables (L5(#)) is that you won’t mess with the calculator’s letter variables (sometimes people store important stuff in them). Unfortunately, the disadvantage to using lists is that it’s really hard to debug and figure out what variable each list index is holding…so here’s a brief description of what the list indexes represent:
L5(2) – The current y-position (stock worth) of the graph
L5(3) – The old L5(2) — this is used to draw the stock graph
L5(4) – The player’s bank amount
L5(5) – The number of shares the player owns
L5(6) – Holds the (randomized) change in the stock amount
L5(7) – Holds the getkey returned value