alonso284

terminal_bopit.sh

Feb 10th, 2024
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.72 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Function to say a given command
  4. say_command() {
  5.     espeak -ven+f3 "$1"
  6. }
  7.  
  8. score=0
  9. while true; do
  10.     # Generate a random command
  11.     command=$((RANDOM % 3))
  12.     case $command in
  13.         0) say_command "Bop It"; key="B" ;;
  14.         1) say_command "Twist It"; key="T" ;;
  15.         2) say_command "Pull It"; key="P" ;;
  16.     esac
  17.  
  18.     # Read user input
  19.     read -n 1 -t 3 input
  20.  
  21.     # Convert input to uppercase
  22.     input=$(echo "$input" | tr '[:lower:]' '[:upper:]')
  23.  
  24.     # Check if input matches the command
  25.     if [ "$input" == "$key" ]; then
  26.         score=$((score + 1))
  27.         echo "Correct! Score: $score"
  28.     else
  29.         echo "Wrong! Game Over. Final Score: $score"
  30.         break
  31.     fi
  32. done
  33.  
Advertisement
Add Comment
Please, Sign In to add comment