Calculator Community > TI-BASIC

My first TI-BASIC game

(1/2) > >>

SopaXorzTaker:
Literally a week after getting my TI-82, I wrote this simple game for it.
The objective of the game is to stop the slider ("X") at the right time so that it matches up with the target ("V")
You have four lives (including when zero are remaining), and a hit will yield either 100 and additional 150 score points if you are lucky (3/4 and 1/4 probability).
If you get a score divisible by 1000, you get additional 250 points and one more life.
However, if you miss, 150 points get deduced from your score and you lose one life.
To win, you must score 15000 or more points.
You lose the game if either you lose all of your lives, or if you don't stop the slider in 26 steps (more than enough to stop it from any position).
The controls are simple: Enter to stop the slider and Clear to clean-up the screen and exit the game.
Please report all the bugs encountered so that I can fix them  ^-^

Screenshot:


Also published on GitHub Gist: https://gist.github.com/SopaXorzTaker/48f9dc824a907f35112fb940b6e21440.

Update 2016/08/28: Update the displayed score upon victory

--- Code: ---# Comment: -> is the STO command, >= is the greater than or equal sign (≥), <= is the less than or equal sign (≤), and != is the not equal sign (≠).
# SopaXorzTaker, 2016
# Good luck typing that in (or use the TI utility if you have a link cable).

0->A
1->B
3->C
1->D
0->E
0->F
25->G
0->K
ClrHome
Output(1,2,"SCORE
Output(2,2,0
Output(3,2,"LIVES
Output(4,2,3
Output(7,9,"V
Repeat K=45 or C<0 or A>=15000 or G<0
If A!=E
Then
Output(2,2,"               "
Output(2,2,A
End
If C!=F
Then
Output(4,2,"               "
Output(4,2,C
End
Output(8,1,"................
Output(8,B,"X
A->E
C->F
getKey->K
If K=105
Then
25->G
If B=9
Then
A+100->A
If rand>.75
A+150->A
If fPart (A/1000)=0
Then
A+250->A
C+1->C
Output(2,7,"1 UP!
For(I,1,50
End
Output(2,7,"     "
Output(1,7,"1 UP!
For(I,1,50
End
Output(1,7,"     "
End
Else
A-150->A
C-1->C
Output(5,2,"MISS!
For(I,1,50
End
Output(5,2,"     "
Output(6,2,"MISS!
For(I,1,50
End
Output(6,2,"     "
End
For(I,1,10
End
B+D->B
If B>16
Then
16->B
0-D->D
End
If B<1
Then
1->B
0-D->D
End
G-1->G
End
If C<0 or G<0
Then
Output(7,1,"                "
Output(8,1,"YOU LOSE!       "
Pause
End
If A>=15000
Then
Output(2,2,A
Output(7,1,"                "
Output(8,1,"YOU WIN!        "
Pause
End
ClrHome

--- End code ---

Sorunome:
Is there any chance of the program or a screenshot? (IDK how possible such things for the 82 are...)
Anyhow, i'd recommend leaving away the trailing quotes on your output lines, this way you save bytes!
Also, any reason why there are so many spaces after "YOU LOSE!" and "YOU WIN!" ?

SopaXorzTaker:

--- Quote from: Sorunome on August 28, 2016, 07:21:54 am ---Is there any chance of the program or a screenshot? (IDK how possible such things for the 82 are...)
Anyhow, i'd recommend leaving away the trailing quotes on your output lines, this way you save bytes!
Also, any reason why there are so many spaces after "YOU LOSE!" and "YOU WIN!" ?

--- End quote ---

The quotes at the end of some lines are not required, but are used to show that there should be spaces.
The spacing of the last two strings is needed to clear the rest  of the lines they are printed to, making the screen look tidier.

p2:
* long post incoming *

For further programs: you may want to add comments what the Vars stand for since we can only guess here xD
So here is what your vars are used for:

A = Score *btw your code says gou got to score at least 150001 since it's > not >=
B = X-Position of the "cursor"
C = Lives
D = Speed (and direction) of Cursor's movements (by default 1)
E = Score of last round (to check if changed)
F = Lives of last round (to check if changed)
G = Counter for the slider (hom many "tries" left)
I = Just for the delay, its value doesn't matter
K = GetKey *you should always declare Variables BEFORE using them ;)
But since the default value for a var is 0, in this case "Repeat K=45" won't make any problems:)



Now let's take the code apart :)


--- Code: ---0->A
1->B
3->C
1->D
0->E
0->F
25->G
ClrHome
Output(1,2,"SCORE
Output(2,2,0
Output(3,2,"LIVES
Output(4,2,3
Output(7,9,"V
--- End code ---
Just declarations and display stuff (stuff that won't change during the program)


--- Code: ---Repeat K=45 or C<0 or A>15000 or G<0
--- End code ---
Main loopthat got 3 possible criterias to stop:
A) No lives left (lives=-1)
B) Score>15000 (You might want to change that to >14999 or >=15000)
C) NO more tries (wasted all 25)
It would make things easier for you if you made all your future programs end at 0 not at -1 ;)


--- Code: ---If A!=E
Then
  Output(2,2,"               "
  Output(2,2,A
End
If C!=F
Then
  Output(4,2,"               "
  Output(4,2,C
End
--- End code ---
Checks for changes in both lives and score. That's fine but is it really necessary? ^^ You could also just update this every round ^^ (but that might make the screen flicker a bit so just leave it like that)
By the way: since you use "                " a couple of times, why dont you just store it as Str1 and display that? ;) (or maybe Str0 since nothing (zero) is displayed? ^^)


--- Code: ---Output(8,1,"................
Output(8,B,"X
A->E
C->F
--- End code ---
Display the ground and the "cursor", fine.
But you might want to add at last the " at the end of a string (so we know there's no more spaces behind coming)


--- Code: ---getKey->K
If K=105
Then
--- End code ---
The kay was pressed, will now check if you missed or not


--- Code: ---25->G
--- End code ---
Set number of tries to 25, ok


--- Code: ---If B=9
Then
  A+100->A
--- End code ---
A perfect hit I guess...


--- Code: ---If rand>.75
A+150->A
--- End code ---
Additional points depending on luck


--- Code: ---If fPart (A/1000)=0
Then
  A+250->A
  C+1->C
  Output(2,7,"1 UP!
  For(I,1,50
  End
  Output(2,7,"     "
  Output(1,7,"1 UP!
  For(I,1,50
  End
  Output(1,7,"     "
End
--- End code ---
Score divisible by 1000: 1up
I like it how you used two lines to make the text move to the top ;D
Also that For( is a good way to add a little delay :)


--- Code: ---Else
  A-150->A
  C-1->C
  Output(5,2,"MISS!
  For(I,1,50
  End
  Output(5,2,"     "
  Output(6,2,"MISS!
  For(I,1,50
    Output(6,2,"     "
  End
End
--- End code ---
Code part if you didnt perfectly hit it
Why do you put the Output(6,2,"     " into the for-loop  ??? It will only cause a much longer delay and maybe make the screen flicker...


--- Code: ---For(I,1,10
End
--- End code ---
Another little delay
You may put this in one line, you know...? like ":For(I,1,10):End" that's good for readability of your source (as ling as the for-loop i only for delay)


--- Code: ---B+D->B
--- End code ---
Move the target again (speed and direction=D)


--- Code: ---If B>16
Then
  16->B
  0-D->D
End
--- End code ---
Mustn't leace screen on the left side
Just do -D->D here (the negative-sign, not the subtract) ;)


--- Code: ---If B<1
Then
  1->B
  0-D->D
End
--- End code ---
Mustn't leace screen on the right side
same as above :)


--- Code: ---G-1->G
--- End code ---
You should put G-1->G into the two conditions above (leaving screen) instead of putting it here :) Else You won't have 25 chanzes - it's more like the target is gonna move a total of 25 times... (here the counter for left tries (G) gets reduced by 1 EVERY round no matter if it touched the borders or not, that's what you could call a bug) :)


--- Code: ---End
--- End code ---
End the conditioned block for Key is pressed


--- Code: ---If C<0 or G<0
Then
  Output(7,1,"                "
  Output(8,1,"YOU LOSE!       "
  Pause
End
--- End code ---
I lost... :(
ok ^^


--- Code: ---If A>15000
Then
  Output(2,2,A
  Output(7,1,"                "
  Output(8,1,"YOU WIN!        "
  Pause
End
--- End code ---
Same as before: This is triggered at 15001 instead of 15000, use >= here or simply use 14999 instead :)


--- Code: ---ClrHome
--- End code ---
ok, program is going to end

I'm not sure, but isn't an End missing here for the Repeat K=45 or C<0 or A>15000 or G<0  ??? If you didnt put it because the program is running like this, too: Never do that! it's ik to leave out stuff like " and ) (still should avoid the first) but NEVER leave out a For - it's terrible for readability and it's gonna be a problem once you want to modify the program but can't remember you left out that End...
If It's just me and I made a mistake somewhere, just ignore it ;D

Dont know if you're planning to add this later, but you set a parameter for the speed without ever changing it ;)
And what you most likely didn't think about:
That speed parameter might be a problem since it' imposible to score a "9" at any speed paramater D where iPart(8/D)==(8/D) is not met since B is gonna change like that:
Speed    how B changes11-2-3-4-5-6-7-8-9-10-11-12-13-14-15-16-16-15-14-13-12-11-10-9-8-7-6-5-4-3-2-1-1-2-...21-3-5-7-9-11-13-15-16-14-12-10-8-6-4-2-1-3-...31-4-7-10-13-16-16-13-10-7-4-1-1-4-...so at D=2 you can only do it in 13 out of 25 tries...
and for D=3 it's completely impossible ^^

*I didn't try any of the code out myself so I got no idea if it's working... ;D

SopaXorzTaker:
Thank you!
The Output in a delay For certainly was a bug, and I replaced >15000 to >=15000 just to clarify it. Let me update the post.

Navigation

[0] Message Index

[#] Next page

Go to full version