#!/bin/bash -i # petals.sh ######################################################################### # Petals Around the Rose # # # # Version 0.1 Created by Serghey Rodin # # Version 0.2 Modded by ABS Guide Author # # # # License: GPL3 # # Used in ABS Guide with permission. # # ##################################################################### # hits=0 # Correct guesses. WIN=6 # Mastered the game. ALMOST=5 # One short of mastery. EXIT=exit # Give up early? RANDOM=$$ # Seeds the random number generator from PID of script. # Bones (ASCII graphics for dice) bone1[1]="| |" bone1[2]="| o |" bone1[3]="| o |" bone1[4]="| o o |" bone1[5]="| o o |" bone1[6]="| o o |" bone2[1]="| o |" bone2[2]="| |" bone2[3]="| o |" bone2[4]="| |" bone2[5]="| o |" bone2[6]="| o o |" bone3[1]="| |" bone3[2]="| o |" bone3[3]="| o |" bone3[4]="| o o |" bone3[5]="| o o |" bone3[6]="| o o |" bone="+---------+" # Functions instructions () { clear echo -n "Do you need instructions? (y/n) "; read ans if [ "$ans" = "y" -o "$ans" = "Y" ]; then clear echo -e '\E[34;47m' # Blue type. # "cat document" cat </dev/null # Filter response for digit. # Otherwise just roll dice again. if [ "$?" -eq 0 ] # If-loop #1. then if [ "$petal" == "$answer" ]; then # If-loop #2. echo -e "\nCorrect. There are $petal petals around the rose.\n" (( hits++ )) if [ "$hits" -eq "$WIN" ]; then # If-loop #3. echo -e '\E[31;47m' # Red type. echo -e "\033[1m" # Bold. echo "You have unraveled the mystery of the Rose Petals!" echo "Welcome to the Fellowship of the Rose!!!" echo "(You are herewith sworn to secrecy.)"; echo echo -e "\033[0m" # Turn off red & bold. break # Exit! else echo "You have $hits correct so far."; echo if [ "$hits" -eq "$ALMOST" ]; then echo "Just one more gets you to the heart of the mystery!"; echo fi fi # Close if-loop #3. else echo -e "\nWrong. There are $answer petals around the rose.\n" hits=0 # Reset number of correct guesses. fi # Close if-loop #2. echo -n "Hit ENTER for the next roll, or type \"exit\" to end. " read if [ "$REPLY" = "$EXIT" ]; then exit fi fi # Close if-loop #1. clear done # End of main (while) loop. ### exit $? # Resources: # --------- # 1) http://en.wikipedia.org/wiki/Petals_Around_the_Rose # (Wikipedia entry.) # 2) http://www.borrett.id.au/computing/petals-bg.htm # (How Bill Gates coped with the Petals Around the Rose challenge.)