start=0
printmenu(){
#bucle principal
while true
do
	#fijar un límite del menu
if [ $menuselect -gt $maxmenu ];then
	let menuselect=1
elif [ $menuselect -lt 1 ]; then
	let menuselect=$maxmenu
fi
#printmenu
clear
echo "$title"
for (( menuprint=1; menuprint<=$maxmenu; menuprint++ ))
do
	if [ $menuprint = $menuselect ]; then
		echo -n "-->"
	fi
	case $menuprint in
		1)
			echo "	$opt1"
			;;
		2)
			echo "	$opt2"
			;;
		3)
			echo "	$opt3"
			;;
		4)
			echo "	$opt4"
			;;
		5)
			echo "	$opt5"
			;;
		6)
			echo "	$opt6"
			;;
		7)
			echo "	$opt7"
	esac
done
read -n 3 -p "Use arrows to move through the menu " menuMovement
case $menuMovement in
	*A)
		((menuselect--))
		;;
	*B)
		((menuselect++))
		;;
	"")
		echo "Selected: $menuselect"
		break
		;;
	*)
		;;
esac
done
}
while true
do
clear
echo -e "\e[32mA Gutegamer's game\e[39m"
if [ $start = 0 ]; then
sleep 1
echo "Inspired by \"Where's Waldo\""
sleep 1
#Titulo
echo "Where's My Letter (Pocket Edition)"
sleep 0.5
read -p "Pulsa INTRO para comenzar"
fi
title="Select Difficulty"
opt1="Ultra Easy"
opt2="Easy"
opt3="Medium"
opt4="Original (Hard)"
opt5="Ultra Hard"
opt6="¿How to Play?"
opt7="Exit"
menuselect=4
maxmenu=7
start=1
printmenu
case $menuselect in
	1)
	    until [ "$retry" != "n" ]; do
			#code
			x=1
			a=$(expr $RANDOM % 15839)
			while [ $x -le 15840 ]
			do
				if [ $x = $a ]; then
					echo -ne "\e[31mA\e[39m"
				else
				echo -n "X"
				fi
				let x=$x+1
			done
			read -p "Retry?" retry
		done
		;;
	2)
		until [ "$retry" != "n" ]; do
			#code
			x=1
			a=$(expr $RANDOM % 15839)
			while [ $x -le 15840 ]
			do
				if [ $x = $a ]; then
					echo -ne "X"
				else
				echo -n "."
				fi
				let x=$x+1
			done
			read -p "Retry?" retry
		done
		;;
	3)
		until [ "$retry" != "n" ]; do
			#code
			x=1
			a=$(expr $RANDOM % 15839)
			while [ $x -le 15840 ]
			do
				if [ $x = $a ]; then
					echo -n "x"
				else
					echo -n "X"
				fi
			let x=$x+1
			done
			read -p "Retry?" retry
		done
		;;
	4)
		until [ "$retry" != "n" ]; do
			#code
			x=1
			a=$(expr $RANDOM % 15839)
			while [ $x -le 15840 ]
			do
				if [ $x = $a ]; then
					echo -n "A"
				else
				echo -n "X"
				fi
				let x=$x+1
			done
			read -p "Retry?" retry
		done
		;;
	5)
		until [ "$retry" != "n" ]; do
			#code
			x=1
			a=$(expr $RANDOM % 15839)
			while [ $x -le 15840 ]
			do		
				b=$(expr $RANDOM % 7)
				if [ $x = $a ]; then
					echo -ne "\e[3$b;1mA\e"
				else
					echo -ne "\e[3$b;1mX"
				fi
				let x=$x+1
			done
			echo -ne "\e[39m"
			read -p "Retry?" retry
		done
		;;
	6)
		clear
		echo "Welcome to \"Wher's My Letter (PE)"
		echo 'The game is simple'
		echo 'You must find the discrepancy (the different letter)'
		echo 'within de pattern displayed on your screen.'
		echo 'When you find it, press "y" (yes) for retry or change'
		echo 'the difficulty with "n" (no) to go back to Main Menu'
		echo ""
		echo 'Difficulties and Objetives'
		echo '1) UltraEasy --> find the RED A'
		echo '2) Easy --> find X'
		echo '3) Medium --> find the lowercase x'
		echo '4) Original (Hard) --> find A'
		echo '5) UltraHard --> Find A within clown vomit'
		echo ""
		echo '(C) Gutegamer 2024'
		read -p "Press INTRO to return"
		;;
	7)
		echo Exiting...
		sleep 0.5
		exit
		;;
	esac
done
