#!/bin/sh

qonk_dir='/home/games/qonk'
cd "$qonk_dir" || exit

level_file="$qonk_dir/level"
qonk_cmd="$(cat "$level_file")"
test "$qonk_cmd" || qonk_cmd='./qonk'

while true; do
	qonk_cmd="$(echo $($qonk_cmd | grep '\./qonk [0-9]* [0-9]*'))"

	if test "$qonk_cmd"; then
		echo "$qonk_cmd" >|  "$level_file"
	else
		qonk_cmd='./qonk'
	fi

	if which Xdialog 2>&1 > /dev/null; then
		qonk_cmd=` \
			Xdialog --title "Qonk" --stdout --inputbox \
				"Play again?" \
				10 40 "$qonk_cmd" \
		`
		test "$?" == "0" || break
	else
		read -n 1 -p "$qonk_cmd  (y/n)?" answer
		test "$answer" == "y" || break
	fi

done


