for loop spacing

This commit is contained in:
adam committed 2025-01-21 21:54:53 +00:00
1 parent 5c8a63ef76
commit f3d2d8d0b8
1 file changed
+8 -8
+8 -8
View File
@@ -24,8 +24,8 @@ function reveal_row() {
echo -en "${SAVE}" echo -en "${SAVE}"
echo -en "${HIDE_CURSOR}" echo -en "${HIDE_CURSOR}"
# Must increment by 1 Row as 0 == 1 for escape code # Must increment by 1 Row as 0 == 1 for escape code
declare RNUM=$(( $1+1+$BORDER )) declare RNUM=$(( $1+1+BORDER ))
declare OFFSET='3' ; [[ "${BORDER}" == 0 ]] && OFFSET=0 declare OFFSET=$(( BORDER * 3 ))
echo -en "\e[${RNUM};${OFFSET}H" echo -en "\e[${RNUM};${OFFSET}H"
for (( C=0; C<WIDTH; C++ )); do for (( C=0; C<WIDTH; C++ )); do
@@ -43,7 +43,7 @@ function check_guess() {
declare green_count=0 declare green_count=0
declare chars="" declare chars=""
for ((i=0; i<WIDTH; i++)); do for (( i=0; i<WIDTH; i++ )); do
[[ "${_answer:i:1}" != "${_guess:i:1}" ]] && chars+=${_answer:i:1} [[ "${_answer:i:1}" != "${_guess:i:1}" ]] && chars+=${_answer:i:1}
done done
@@ -53,7 +53,7 @@ function check_guess() {
declare _char=${_guess:$c:1} declare _char=${_guess:$c:1}
if [[ "${_char}" == "${_answer:$c:1}" ]]; then if [[ "${_char}" == "${_answer:$c:1}" ]]; then
green_count=$((green_count+1)) green_count=$(( green_count+1 ))
BOARD[$_row,$c]="${BOLD}${LETTER}${GREEN} ${_char} " BOARD[$_row,$c]="${BOLD}${LETTER}${GREEN} ${_char} "
[[ $green_count == 5 ]] && return 5 [[ $green_count == 5 ]] && return 5
continue continue
@@ -102,7 +102,7 @@ function retrive_guess() {
function select_random_word() { function select_random_word() {
IFS=' ' read -r -a answers <<< "${POSSIBLE_ANSWERS}" IFS=' ' read -r -a answers <<< "${POSSIBLE_ANSWERS}"
declare -r random_index=$((RANDOM % ${#answers[@]})) declare -r random_index=$(( RANDOM % ${#answers[@]} ))
echo "${answers[random_index]^^}" echo "${answers[random_index]^^}"
} }
@@ -146,7 +146,7 @@ function set_options() {
validate_guess "${ANSWER}" validate_guess "${ANSWER}"
if [[ $? == 1 ]]; then if [[ $? == 1 ]]; then
echo "Not a valid word" echo "Not a valid word"
exit $? exit 1
fi fi
;; ;;
h) h)
@@ -179,8 +179,8 @@ function main() {
reveal_row "${row}" reveal_row "${row}"
[[ $win == 5 ]] && echo -e "\n${CLEAR_LINE}YOU WIN" && exit 0 [[ $win == 5 ]] && echo -e "\n${CLEAR_LINE}YOU WIN" && exit 0
done done
IFS=
result="${ANSWER//?/ & }" result="${ANSWER//?/& }"
result=${result%} result=${result%}
echo -e "\n${CLEAR_LINE}YOU LOSE\n${result} ${RESET}" && exit 0 echo -e "\n${CLEAR_LINE}YOU LOSE\n${result} ${RESET}" && exit 0
} }