Bug fix and improve 2020/ferguson1/play.sh

It did not work if one did not choose to reconfigure colours and the alt
prog was not already compiled.

It now allows you to continue play after you end a game if you so
choose.

Shellcheck fixes.
This commit is contained in:
Cody Boone Ferguson committed 2023-04-15 10:11:40 -07:00
1 parent 66a7970881
commit ef140ddb7e
1 file changed
+82 -63
+82 -63
View File
@@ -84,7 +84,7 @@ function configure_colours()
for i in "WALL" "WALL (BACKGROUND)" "HEAD" "HEAD (BACKGROUND)" "BODY" "BODY (BACKGROUND)" "BUG" "BUG (BACKGROUND)"; do for i in "WALL" "WALL (BACKGROUND)" "HEAD" "HEAD (BACKGROUND)" "BODY" "BODY (BACKGROUND)" "BUG" "BUG (BACKGROUND)"; do
show_colours "${i}" show_colours "${i}"
x="${?}" x="${?}"
if [ "${x}" != 255 ]; then if [[ "${x}" != 255 ]]; then
COLOURS[$j]="${COLOURS[$j]}${COLOUR[$x]}" COLOURS[$j]="${COLOURS[$j]}${COLOUR[$x]}"
else else
COLOURS[$j]=${DFLT[$j]} COLOURS[$j]=${DFLT[$j]}
@@ -92,24 +92,34 @@ function configure_colours()
j=$j+1 j=$j+1
done done
echo cc -o prog.alt prog.alt.c -D'f(a,b)'='((a)<(b)?(a):(b))' ${COLOURS[0]} ${COLOURS[1]} \ echo cc -o prog.alt prog.alt.c -D'f(a,b)'='((a)<(b)?(a):(b))' "${COLOURS[0]}" "${COLOURS[1]}" \
${COLOURS[2]} ${COLOURS[3]} ${COLOURS[4]} ${COLOURS[5]} ${COLOURS[6]} ${COLOURS[7]} -lncurses "${COLOURS[2]}" "${COLOURS[3]}" "${COLOURS[4]}" "${COLOURS[5]}" "${COLOURS[6]}" "${COLOURS[7]}" -lncurses
cc -o prog.alt prog.alt.c -D'f(a,b)'='((a)<(b)?(a):(b))' ${COLOURS[0]} ${COLOURS[1]} \ cc -o prog.alt prog.alt.c -D'f(a,b)'='((a)<(b)?(a):(b))' "${COLOURS[0]}" "${COLOURS[1]}" \
${COLOURS[2]} ${COLOURS[3]} ${COLOURS[4]} ${COLOURS[5]} ${COLOURS[6]} ${COLOURS[7]} -lncurses || exit 1 "${COLOURS[2]}" "${COLOURS[3]}" "${COLOURS[4]}" "${COLOURS[5]}" "${COLOURS[6]}" "${COLOURS[7]}" -lncurses || exit 1
}
function just_compile()
{
echo cc -o prog.alt prog.alt.c -D'f(a,b)'='((a)<(b)?(a):(b))' "${DFLT[0]}" "${DFLT[1]}" \
"${DFLT[2]}" "${DFLT[3]}" "${DFLT[4]}" "${DFLT[5]}" "${DFLT[6]}" "${DFLT[7]}" -lncurses
cc -o prog.alt prog.alt.c -D'f(a,b)'='((a)<(b)?(a):(b))' "${DFLT[0]}" "${DFLT[1]}" \
"${DFLT[2]}" "${DFLT[3]}" "${DFLT[4]}" "${DFLT[5]}" "${DFLT[6]}" "${DFLT[7]}" -lncurses || exit 1
} }
function testcaps() function testcaps()
{ {
make || exit 1 make || exit 1
./termcaps ./termcaps
T="${?}" T="${?}"
if [ "${T}" -ne 0 ]; then if [[ "${T}" -ne 0 ]]; then
read -rp "Terminal issues detected; do you wish to continue anyway (Y/N) ? " ans read -rp "Terminal issues detected; do you wish to continue anyway (Y/N) ? " ans
[[ "${ans}" != "y" ]] && [[ "${ans}" != "Y" ]] && exit 1 [[ "${ans}" != "y" ]] && [[ "${ans}" != "Y" ]] && exit 1
fi fi
} }
function menu() function menu()
{ {
echo
printf "** GAME MODE SELECTION MENU **\n\n" printf "** GAME MODE SELECTION MENU **\n\n"
echo "(0) Drawing mode" echo "(0) Drawing mode"
@@ -211,66 +221,75 @@ function play()
configure_colours configure_colours
;; ;;
*) *)
just_compile
;; ;;
esac esac
menu
read -rp "Make your selection (0 - 7 or any other key to exit): " mode
case "${mode}" in while true; do
0) # Drawing mode 0 menu
draw0 read -rp "Make your selection (0 - 7 or any other key to exit): " mode
;;
1) # Drawing mode 1 case "${mode}" in
draw1 0) # Drawing mode 0
;; draw0
2) # Automatic mode (computer plays by itself) (photosensitive epilepsy/stimulation overload trigger) ;;
auto0 1) # Drawing mode 1
;; draw1
3) # Automatic mode variation 0 (photosensitive epilepsy/stimulation overload trigger) ;;
auto1 2) # Automatic mode (computer plays by itself) (photosensitive epilepsy/stimulation overload trigger)
;; auto0
4) # grow shrink mode ;;
growshrink0 3) # Automatic mode variation 0 (photosensitive epilepsy/stimulation overload trigger)
;; auto1
5) # grow shrink mode variation 0 ;;
growshrink1 4) # grow shrink mode
;; growshrink0
6) # hypnotic mode (photosensitive epilepsy/stimulation overload trigger) ;;
hypno 5) # grow shrink mode variation 0
;; growshrink1
7) # stimulation / calming mode ;;
stim 6) # hypnotic mode (photosensitive epilepsy/stimulation overload trigger)
;; hypno
8) # normal mode (aka Judges' Normal) ;;
norm 7) # stimulation / calming mode
;; stim
9) # 100ms w/o cheat modes (Judges' Zeroth) ;;
judges0 8) # normal mode (aka Judges' Normal)
;; norm
10) # 75ms w/both cheat modes (Judges' First) ;;
judges1 9) # 100ms w/o cheat modes (Judges' Zeroth)
;; judges0
11) # Immediately win (Judges' Second) ;;
judges2 10) # 75ms w/both cheat modes (Judges' First)
;; judges1
12) # 50ms w/both cheat modes, evade at 200 moves (Judges' Third) ;;
judges3 11) # Immediately win (Judges' Second)
;; judges2
13) # 75ms w/both cheat modes, shrink mode (win with six bugs) (Judges' Fourth) ;;
judges4 12) # 50ms w/both cheat modes, evade at 200 moves (Judges' Third)
;; judges3
14) # Let computer win by itself very quickly (Judges' Fifth) ;;
judges5 13) # 75ms w/both cheat modes, shrink mode (win with six bugs) (Judges' Fourth)
;; judges4
15) # Start at 400, shrink by 5 every 100 moves, cannibalism and max size possible ;;
growshrink3 14) # Let computer win by itself very quickly (Judges' Fifth)
;; judges5
16) # Start at 400, shrink by 5 every 100 moves and max size possible ;;
growshrink4 15) # Start at 400, shrink by 5 every 100 moves, cannibalism and max size possible
;; growshrink3
*) ;;
exit 0 16) # Start at 400, shrink by 5 every 100 moves and max size possible
esac growshrink4
;;
*)
exit 0
esac
read -rp "Do you want to continue? " ans
if [[ "$ans" != "y" && "$ans" != "Y" ]]; then
break;
fi
done
} }
play play