Compare commits

..
Author SHA1 Message Date
adam 39265c3c9d resume on correct row after save during row reveal 2025-05-04 12:33:56 +01:00
adam 3487adf34c exit save_result if not in online mode
Deploy game to server / deploy (push) Successful in 30s
2025-04-23 21:22:03 +00:00
adam 2194d495e6 extra file for current board
Deploy game to server / deploy (push) Successful in 42s
2025-03-03 12:07:43 +00:00
adam 005a129919 change help message format
Deploy game to server / deploy (push) Successful in 6s
2025-02-22 20:00:30 +00:00
adam bdb3d4e4d1 Move signal trap initialization after game mode questions - Prevent progress files after incorrect username 2025-02-22 19:41:46 +00:00
adam 6bbcc5229b save progress at start of a game 2025-02-22 19:38:06 +00:00
adam 4029c00edc remove $ where not needed 2025-02-22 19:22:45 +00:00
adam 8327678209 only show board on daily win
Deploy game to server / deploy (push) Successful in 6s
2025-02-21 13:21:04 +00:00
adam d496319361 Add guess count out of 6 on win
Deploy game to server / deploy (push) Successful in 7s
2025-02-21 13:12:19 +00:00
adam 107fd30b00 print spoiler free board after a game 2025-02-21 13:07:03 +00:00
+29 -9
View File
@@ -33,6 +33,7 @@ function main() {
declare -g ANSWER
declare -g POOL='QWERTYUIOPASDFGHJKLZXCVBNM'
declare -Ag YELLOWS
declare -g REVEALING=0
ANSWER=$(select_random_word)
set_options "$@"
@@ -50,6 +51,8 @@ function main() {
init_board
fi
[[ "${ONLINE}" == 1 ]] && save_game "NO_EXIT"
render_board
for (( ROW; ROW<HEIGHT; ROW++ )); do
@@ -59,11 +62,16 @@ function main() {
check_guess "${GUESS}" "${ROW}" ; WIN=$?
reveal_row "${ROW}"
REVEALING=0
if [[ $WIN == 5 ]]; then
save_result
echo -e "${CLEAR_DOWN}YOU WIN"
[[ "${ONLINE}" == 1 && "${DAILY_DONE}" != 1 ]] && echo "Share/view your game with -> curl \"${URL_BASE}/${RESULT_FILE}\""
if [[ "${ONLINE}" == 1 && "${DAILY_DONE}" != 1 ]]; then
echo "Share/view your game with -> curl \"${URL_BASE}/${RESULT_FILE}\""
while read -r board_line; do echo "${board_line//[A-Z]/ }"; done < "${RESULT_FILE}"
fi
echo "Guess - $(( ROW+1 ))/6"
exit 0
fi
done
@@ -76,7 +84,10 @@ function main() {
echo -en "${NEWLINE}${RESET}"
save_result
[[ "${ONLINE}" == 1 && "${DAILY_DONE}" != 1 ]] && echo "Share/view your game with -> curl \"${URL_BASE}/${RESULT_FILE}\""
if [[ "${ONLINE}" == 1 && "${DAILY_DONE}" != 1 ]]; then
echo "Share/view your game with -> curl \"${URL_BASE}/${RESULT_FILE}\""
while read -r board_line; do echo "${board_line//[A-Z]/ }"; done < "${RESULT_FILE}"
fi
exit 0
}
@@ -130,18 +141,18 @@ function set_options() {
USER="${USER,,}"
declare -g DAY
DAY=$(( $EPOCHSECONDS / 86400 ))
DAY=$(( EPOCHSECONDS / 86400 ))
declare -gr PROGRESS_FILE=".${USER}-${DAY}.progress"
declare -gr RESULT_FILE="${USER}-${DAY}.board"
declare -gr CUR_RESULT_FILE="${USER}.board"
declare -gr STATS_SOURCE=".${USER}.stats"
declare -gr STATS_FILE="${USER}.stats"
trap save_game SIGINT
if [[ -f "${PROGRESS_FILE}" ]] && [[ -s "${PROGRESS_FILE}" ]]; then
load_game
RESUME=1
@@ -161,13 +172,17 @@ function set_options() {
[[ "${HM}" =~ ^[Yy]$ ]] && STRICT_HARD_MODE=1
fi
fi
trap save_game SIGINT
;;
d)
DELAY=0
;;
h)
echo -e "Usage: <program_name> [OPTIONS]
echo -e \
"Usage: <program_name> [OPTIONS]
Play a game for Wordle
Options:
-b Toggle borderless mode
-w Set target word
@@ -335,6 +350,7 @@ function check_guess() {
}
function reveal_row() {
REVEALING=1
echo -en "${UP1}${SAVE}"
echo -en "${HIDE_CURSOR}"
# Must increment by 1 Row as 0 == 1 for escape code
@@ -367,7 +383,7 @@ function save_game() {
done
{
echo "ROW=${ROW}"
echo "ROW=$(( ROW + REVEALING ))"
echo "POOL=${POOL}"
echo "HARD_MODE=${HARD_MODE}"
echo "STRICT_HARD_MODE=${STRICT_HARD_MODE}"
@@ -378,20 +394,24 @@ function save_game() {
} >> "${PROGRESS_FILE}"
echo -en "${RESET}"
exit 0
[[ -z $1 ]] && exit 0
}
function save_result() {
[[ "${ONLINE}" == 0 ]] && return 0
[[ "${ONLINE}" == 1 ]] && update_stats
if [[ "${ONLINE}" == 1 ]] && [[ "${DAILY_DONE}" != 1 ]]; then
render_board > "${RESULT_FILE}"
render_board > "${CUR_RESULT_FILE}"
if [[ $WIN != 5 ]]; then
[[ "${BORDER}" == 1 ]] && echo -en "${CLEAR_DOWN}${INDENT}${INDENT}" >> "${RESULT_FILE}"
echo -en "${CLEAR_LINE}${BOLD}" >> "${RESULT_FILE}"
for (( i=0; i<WIDTH; i++ )); do
echo -en " ${ANSWER:$i:1} " >> "${RESULT_FILE}"
echo -en " ${ANSWER:$i:1} " >> "${CUR_RESULT_FILE}"
done
echo -en "${NEWLINE}${RESET}" >> "${RESULT_FILE}"
echo -en "${NEWLINE}${RESET}" >> "${CUR_RESULT_FILE}"
fi
fi
echo 'PLAYED=1' > "${PROGRESS_FILE}"
@@ -413,7 +433,7 @@ function update_stats() {
[[ $WIN == 5 ]] && SCORE="${GAME_HIST[$ROW]}"
[[ $WIN == 5 ]] && SCORE=$(( SCORE+1 ))
[[ $WIN == 5 ]] && GAME_HIST[$ROW]="${SCORE}"
[[ $WIN == 5 ]] && GAME_HIST[ROW]="${SCORE}"
[[ $WIN == 5 ]] && STREAK=$(( STREAK+1 ))
[[ $WIN != 5 ]] && STREAK=0