- Hangman on TI-84+
- 06 Feb 2025 01:31:44 pm
- Last edited by Monado07 on 15 Feb 2025 08:35:09 pm; edited 1 time in total
I used to be really into TI-BASIC back in 2022/2023, but I took an extended break after I lost my physical calc and became pretty rusty. Hangman was a game I was always interested in making but never got around to due to strings not being my strong suit; so I figured it would be a good project to re-adjust to BASIC. I tried my best to use good coding practices and optimize (was able to get it down to about 1650 bytes); but I'd really appreciate any tips on how to improve since some parts are pretty hacky. 2P mode should work on the 83+, but I haven't tested the program on there at all. Shoutout to alex99 and learn.cemetech since without their algorithms to convert between strings and lists, I wouldn't have finished this.
Code:
Code:
"ABCDEFGHIJKLMNOPQRSTUVWXYZ "->Str3
DelVar Str4DelVar Str0DelVar CDelVar SDelVar WDelVar MDelVar L1DelVar U
2->J //Row
1->K // Column
17->G
30->dim(L1
ClrHome
Disp " HANGMAN
Disp " BY: JOHN CAMOU
Disp " PRESS TO START
Pause
ClrHome
Menu("OPTIONS","1 PLAYER",A,"2 PLAYER",B,"EXIT",C
Lbl A
{19,20,1,14,4,0,13,15,12,4,0,12,1,25,5,18,0,20,9,7,5,18,0,20,9,3,11,5,20,0,7,18,15,21,14,4,19,0,19,20,21,14,14,9,14,7,0,13,1,18,1,20,8,15,14,0,19,11,5,12,5,20,15,14,0,1,2,21,19,5,0,8,5,1,20,0,23,18,5,3,11,0,16,18,9,19,15,14,0,13,1,18,9,14,5,0,16,15,21,18,0,1,7,12,18,24,31,39,48,57,66,72,77,83,90,98}->|LDICTY
randInt(102,116->V
|LDICTY(V->V
"?->Str0
While U=0:
//Output(1,1,V
|LDICTY(V->H
If H!=0:Then
sub(Str3,H,1
Str0+Ans->Str0
V+1->V
End
If H=0
1->U
End
sub(Str0,2,length(Str0)-1->Str0
length(Str0->L
Goto E
Lbl B //Handles input when playing a 2 player round
Disp "PASS TO PLAYER 1
Disp "PRESS WHEN READY
Pause
Lbl D //Allows the program to give the user another chance to input the word
ClrHome
DelVar A
Disp " INPUT WORD
Disp "MIN 3,MAX 8 CHR
Input Str0
length(Str0->L
If L<3:Then
Output(5,4,"TOO SHORT!
Output(7,1,"PRESS TO CONT
1->A
Pause
End
If L>8:Then
Output(5,5,"TOO LONG!
Output(7,1,"PRESS TO CONT
1->A
Pause
End
If A=1
Goto D
// Need to implement character checking
ClrHome
Disp "PASS TO PLAYER 2
Disp "PRESS WHEN READY
Pause
Lbl E //The actual hangman game
While M<6
ClrHome
DelVar V
2->J //Row
1->K // Column
// Outputs the "hangman" image
If M<6
Output(2,8,"O
If M<5:Then
Output(3,8,"|":Output(4,8,"|
End
If M<4
Output(3,6,"--
If M<3
Output(3,9,"--
If M<2
Output(5,7,"/
If M=0
Output(5,9,"/
If S=1
Output(8,1,"WRONG!
If S=2
Output(8,1,"CORRECT!
If S=3:Then
Output(8,1,"ALREADY GUESSED!
0->S
End
// Outputs blank lines - "L" is the length of the word, "A" is used to control output( statements
For(A,1,L*2,2
Output(7,A,"-
End
// Outputs letters on top of the blanks if needed
For(A,2,16,2
If L1(A)=1:Then
L1(A-1->H
sub(Str3,H,1->Str4
Output(6,A-1,Str4
End
End
For(A,17,30
L1(A->H
If H=0
27->H
sub(Str3,H,1->Str4
Output(J,K,Str4
K+1->K
If K=5:Then
J+1->J
1->K
End
If J=5:Then
1->J
30->A
End
End
Input "INPUT GUESS: ",Str1
length(Str1->Z
If Z>1
Goto E
// Detects if the letter has already been guessed
inString(Str3,sub(Str1,1,1)->H
For(A,17,30
If H=L1(A):Then
3->S
End
End
//
If S!=3:Then
inString(Str3,sub(Str1,1,1)->L1((G) // G should increment once per guess, the letters are stored in L1 so the list of guesses can be created later
G+1->G
End
// Loops through the word and sees if there's a match, "B" is used to compare the substring with the guessed word, L1 is used to record the location and C is used to make sure the matches are placed in order -- Need to implement a way to place the letters on top of the blanks
//Str 0 is the word, str 1 is the guess, str 2 are letters that have been guessed
For(A,1,L,1
inString(Str0,Str1,A->B
//1 signals that a blank has been correctly guessed, with the instring command converting the guessed letter into a number so it can be placed above the correct blank on the next cycle, format is [letter,blank]
If B!=0:Then
1->L1(B*2)
inString(Str3,sub(Str1,1,1)->L1((B*2)-1)
B->A
If S=3:Then
3->S
Else:
2->S
C+1->C
End
1->V // signal that a correct letter was entered at some point
If C=L:Then
1->W
7->M
End
End
If B=0:Then
If A=L:Then
If V=0:Then
If S=3:Then
3->S
Else:
1->S // S tells the drawing portion of the program to display a message telling the user their guess was right or wrong. 1 means the previous answer was wrong, 2 means the previous answer was correct
M+1->M
End
End
End
End
End
End
ClrHome
If W=1
"WIN
If W=0
"LOSE
Output(2,5,"YOU "+Ans
Output(7,1," ENTER TO EXT
Pause
DelVar Str0DelVar Str1DelVar Str3DelVar Str4DelVar L1DelVar SDelVar WDelVar MDelVar U
Lbl C