Paste code to text file .sh extension and run script in the directory where jc141 are present, also install dialog

#!/bin/bash

# navigate to the directory containing the .sh files
cd "$(dirname "$(readlink -f "$0")")" || exit

# directory containing the game directories
games_dir="$PWD/"

# check if the games directory exists
if [ ! -d "$games_dir" ]; then
echo "error: The 'games' directory does not exist."
exit 1
fi

# initialize the dialog menu options
menu_options=()

# loop through subdirectories in the games directory
for game_dir in "$games_dir"/*/; do
if [ -d "$game_dir" ]; then
# extract the parent directory name as the game name
game_name=$(basename "$game_dir")
        
# check if any of the specified .sh files exist
if [ -f "$game_dir/start.w.sh" ] || [ -f "$game_dir/start.e-w.sh" ] || [ -f "$game_dir/start.sh" ] || [ -f "$game_dir/start.n.sh" ]; then
# add the game name to the menu options
menu_options+=("$game_name" "Run $game_name")
fi
fi
done

# use dialog to display the menu
choice=$(dialog --title "Select a game:" --menu "Games:" 30 30 15 "${menu_options[@]}" 2>&1 >/dev/tty)

# check if the user selected a game and execute it
if [ -n "$choice" ]; then
selected_game="${choice#* }" # extract the selected game name from the choice
selected_game_dir="$games_dir/$selected_game"

# determine which script exists and set the selected_game_script accordingly
if [ -f "$selected_game_dir/start.w.sh" ]; then
selected_game_script="$selected_game_dir/start.w.sh"
elif [ -f "$selected_game_dir/start.e-w.sh" ]; then
selected_game_script="$selected_game_dir/start.e-w.sh"
elif [ -f "$selected_game_dir/start.n.sh" ]; then
selected_game_script="$selected_game_dir/start.n.sh"
elif [ -f "$selected_game_dir/start.sh" ]; then
selected_game_script="$selected_game_dir/start.sh"
else
echo "error: this script must run with in the directory of jc141 downloads"
exit 1
fi
    
# execute the selected game's script
chmod +x "$selected_game_script" # make the script executable
"$selected_game_script"
fi