| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
hits=0 |
| 15 |
WIN=6 |
| 16 |
ALMOST=5 |
| 17 |
EXIT=exit |
| 18 |
|
| 19 |
RANDOM=$$ |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
bone1[1]="| |" |
| 24 |
bone1[2]="| o |" |
| 25 |
bone1[3]="| o |" |
| 26 |
bone1[4]="| o o |" |
| 27 |
bone1[5]="| o o |" |
| 28 |
bone1[6]="| o o |" |
| 29 |
bone2[1]="| o |" |
| 30 |
bone2[2]="| |" |
| 31 |
bone2[3]="| o |" |
| 32 |
bone2[4]="| |" |
| 33 |
bone2[5]="| o |" |
| 34 |
bone2[6]="| o o |" |
| 35 |
bone3[1]="| |" |
| 36 |
bone3[2]="| o |" |
| 37 |
bone3[3]="| o |" |
| 38 |
bone3[4]="| o o |" |
| 39 |
bone3[5]="| o o |" |
| 40 |
bone3[6]="| o o |" |
| 41 |
bone="+---------+" |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
instructions () { |
| 48 |
|
| 49 |
clear |
| 50 |
echo -n "Do you need instructions? (y/n) "; read ans |
| 51 |
if [ "$ans" = "y" -o "$ans" = "Y" ]; then |
| 52 |
clear |
| 53 |
echo -e '\E[34;47m' |
| 54 |
|
| 55 |
|
| 56 |
cat <<INSTRUCTIONSZZZ |
| 57 |
The name of the game is Petals Around the Rose, |
| 58 |
and that name is significant. |
| 59 |
Five dice will roll and you must guess the "answer" for each roll. |
| 60 |
It will be zero or an even number. |
| 61 |
After your guess, you will be told the answer for the roll, but . . . |
| 62 |
that's ALL the information you will get. |
| 63 |
|
| 64 |
Six consecutive correct guesses admits you to the |
| 65 |
Fellowship of the Rose. |
| 66 |
INSTRUCTIONSZZZ |
| 67 |
|
| 68 |
echo -e "\033[0m" # Turn off blue. |
| 69 |
else clear |
| 70 |
fi |
| 71 |
|
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
fortune () |
| 76 |
{ |
| 77 |
RANGE=7 |
| 78 |
FLOOR=0 |
| 79 |
number=0 |
| 80 |
while [ "$number" -le $FLOOR ] |
| 81 |
do |
| 82 |
number=$RANDOM |
| 83 |
let "number %= $RANGE" # 1 - 6. |
| 84 |
done |
| 85 |
|
| 86 |
return $number |
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
throw () { # Calculate each individual die. |
| 92 |
fortune; B1=$? |
| 93 |
fortune; B2=$? |
| 94 |
fortune; B3=$? |
| 95 |
fortune; B4=$? |
| 96 |
fortune; B5=$? |
| 97 |
|
| 98 |
calc () { # Function embedded within a function! |
| 99 |
case "$1" in |
| 100 |
3 ) rose=2;; |
| 101 |
5 ) rose=4;; |
| 102 |
* ) rose=0;; |
| 103 |
esac # Simplified algorithm. |
| 104 |
# Doesn't really get to the heart of the matter. |
| 105 |
return $rose |
| 106 |
} |
| 107 |
|
| 108 |
answer=0 |
| 109 |
calc "$B1"; answer=$(expr $answer + $(echo $?)) |
| 110 |
calc "$B2"; answer=$(expr $answer + $(echo $?)) |
| 111 |
calc "$B3"; answer=$(expr $answer + $(echo $?)) |
| 112 |
calc "$B4"; answer=$(expr $answer + $(echo $?)) |
| 113 |
calc "$B5"; answer=$(expr $answer + $(echo $?)) |
| 114 |
} |
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
game () |
| 119 |
{ |
| 120 |
throw |
| 121 |
echo -e "\033[1m" |
| 122 |
echo -e "\n" |
| 123 |
echo -e "$bone\t$bone\t$bone\t$bone\t$bone" |
| 124 |
echo -e \ |
| 125 |
"${bone1[$B1]}\t${bone1[$B2]}\t${bone1[$B3]}\t${bone1[$B4]}\t${bone1[$B5]}" |
| 126 |
echo -e \ |
| 127 |
"${bone2[$B1]}\t${bone2[$B2]}\t${bone2[$B3]}\t${bone2[$B4]}\t${bone2[$B5]}" |
| 128 |
echo -e \ |
| 129 |
"${bone3[$B1]}\t${bone3[$B2]}\t${bone3[$B3]}\t${bone3[$B4]}\t${bone3[$B5]}" |
| 130 |
echo -e "$bone\t$bone\t$bone\t$bone\t$bone" |
| 131 |
echo -e "\n\n\t\t" |
| 132 |
echo -e "\033[0m" |
| 133 |
echo -n "There are how many petals around the rose? " |
| 134 |
} |
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
instructions |
| 141 |
|
| 142 |
while [ "$petal" != "$EXIT" ] |
| 143 |
do |
| 144 |
game |
| 145 |
read petal |
| 146 |
echo "$petal" | grep [0-9] >/dev/null |
| 147 |
|
| 148 |
if [ "$?" -eq 0 ] |
| 149 |
then |
| 150 |
if [ "$petal" == "$answer" ]; then |
| 151 |
echo -e "\nCorrect. There are $petal petals around the rose.\n" |
| 152 |
(( hits++ )) |
| 153 |
|
| 154 |
if [ "$hits" -eq "$WIN" ]; then |
| 155 |
echo -e '\E[31;47m' |
| 156 |
echo -e "\033[1m" |
| 157 |
echo "You have unraveled the mystery of the Rose Petals!" |
| 158 |
echo "Welcome to the Fellowship of the Rose!!!" |
| 159 |
echo "(You are herewith sworn to secrecy.)"; echo |
| 160 |
echo -e "\033[0m" |
| 161 |
break |
| 162 |
else echo "You have $hits correct so far."; echo |
| 163 |
|
| 164 |
if [ "$hits" -eq "$ALMOST" ]; then |
| 165 |
echo "Just one more gets you to the heart of the mystery!"; echo |
| 166 |
fi |
| 167 |
|
| 168 |
fi |
| 169 |
|
| 170 |
else |
| 171 |
echo -e "\nWrong. There are $answer petals around the rose.\n" |
| 172 |
hits=0 |
| 173 |
fi |
| 174 |
|
| 175 |
echo -n "Hit ENTER for the next roll, or type \"exit\" to end. " |
| 176 |
read |
| 177 |
if [ "$REPLY" = "$EXIT" ]; then exit |
| 178 |
fi |
| 179 |
|
| 180 |
fi |
| 181 |
|
| 182 |
clear |
| 183 |
done |
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
exit $? |
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|