border and word option

This commit is contained in:
adam committed 2025-01-21 21:12:00 +00:00
1 parent f1c214ddd4
commit 5c8a63ef76
1 file changed
+36 -7
+36 -7
View File
@@ -24,8 +24,10 @@ function reveal_row() {
echo -en "${SAVE}"
echo -en "${HIDE_CURSOR}"
# Must increment by 1 Row as 0 == 1 for escape code
declare RNUM=$(( $1+2 ))
echo -en "\e[$RNUM;2H"
declare RNUM=$(( $1+1+$BORDER ))
declare OFFSET='3' ; [[ "${BORDER}" == 0 ]] && OFFSET=0
echo -en "\e[${RNUM};${OFFSET}H"
for (( C=0; C<WIDTH; C++ )); do
echo -n "${BOARD[$1,$C]}"
read -r -s -t 0.5
@@ -109,16 +111,17 @@ function render_board() {
declare row
declare char
echo '┌───────────────┐'
[[ "${BORDER}" == 1 ]] && echo -e "┌─────────────────┐"
for (( row=0; row<HEIGHT; row++ )); do
echo -n '│'
[[ "${BORDER}" == 1 ]] && echo -en "│ "
for (( char=0; char<WIDTH; char++ )); do
echo -n "${BOARD[${row},${char}]}${RESET}"
done
echo -n '│'
[[ "${BORDER}" == 1 ]] && echo -en " │ "
echo -en "${DOWN1}"
done
echo '└───────────────┘'
[[ "${BORDER}" == 1 ]] && echo -e "└─────────────────┘"
}
function init_board() {
@@ -130,11 +133,37 @@ function init_board() {
done
}
function set_options() {
declare -g BORDER=1
while getopts "bw:h" OPT; do
case "${OPT}" in
b)
BORDER=0
;;
w)
ANSWER="${OPTARG^^}"
validate_guess "${ANSWER}"
if [[ $? == 1 ]]; then
echo "Not a valid word"
exit $?
fi
;;
h)
exit # add help message
;;
*)
;;
esac
done
}
function main() {
echo -en "${CLEAR_SCREEN}"
declare -g ANSWER
ANSWER=$(select_random_word)
[[ -n $1 ]] && ANSWER=${1^^}
set_options "$@"
init_board