inital commit. Not all games work 100, or even 50 percent lol.

This commit is contained in:
Storm Dragon 2014-05-04 13:43:52 -04:00
parent cedd7a8ef5
commit d53c2eb074
71 changed files with 1753 additions and 0 deletions

218
critter-cannon/critter-cannon Executable file
View File

@ -0,0 +1,218 @@
#!/bin/bash
#Play sounds
play_sound()
{
#terrainSound=$(shuf -n 1 -e "sounds/$1"*.ogg)
play -mqV0 "$(shuf -n 1 -e "sounds/$1"*.ogg)" "$(shuf -n 1 -e "sounds/$amo/fire"*.ogg)"
}
#Initialize variables and screen
initializer()
{
#plot course on first load
if [ -z "$firstLoad" ] ; then
clear
#seed random number with /dev/random
RANDOM=$(od -An -N2 -i /dev/random)
echo -e "Welcome to Critter Cannon\n\nCreating course, please wait..."
i=0
while [ $i -le 1500 ] ; do
feet[$i]="$(shuf -n 1 -e "a stick of dynamite" "the ground" "a trampoline" "spikes" "the ground" "a venus flytrap" "the ground" "an electric fence" "the ground")"
let i++
done
fi
i=1
for x in sounds/* ; do
if [ -d "$x" ] ; then
amoList[$i]="$x"
if [ $i -lt 10 ] ; then
echo -n "0"
fi
echo "$i: $(echo "$x" | rev | cut -d / -f 1 | rev)"
let i++
fi
done
read -p "Select your amo: " amo
if ! [[ "$amo" =~ ^[0-9]+$ ]] ; then
amo=1
fi
if [ $amo -lt 1 -o $amo -gt $i ] ; then
amo=1
fi
amo="$(echo ${amoList[$amo]} | sed 's/sounds\///g')"
if [ -f "sounds/$amo/sex" ] ; then
sex="$(cat "sounds/$amo/sex" | tr -d "[:space:]")"
else
sex="it"
fi
echo "You $(shuf -n 1 -e "shove" "push" "jam") a $(shuf -n 1 -e "kick" "claw" "bit")ing and $(shuf -n 1 -e "scream" "snarl")ing $amo into the cannon and prepare to fire..."
read -p "Set the altitude of the cannon in degrees from 90 which is paralell to the ground, to 180 which is straight up. " aim
if ! [[ "$aim" =~ ^[0-9]+$ ]] ; then
aim=90
fi
if [ $aim -lt 90 -a $aim -gt 180 ] ; then
aim=90
fi
read -p "Enter the number of grains of black powder to use from 10 to 25. " amoDistance
if ! [[ "$amoDistance" =~ ^[0-9]+$ ]] ; then
amoDistance=10
fi
if [ $amoDistance -lt 10 -a $amoDistance -gt 25 ] ; then
amoDistance=10
fi
amoDistance=$(echo "$amoDistance / 3" | bc)
amoHeight=$(echo "$aim / 2" | bc)
#Distance bonus if cannon aim is less than 120
if [ $aim -lt 120 ] ; then
amoDistance=$(echo "$amoDistance + ($RANDOM % 15)" | bc)
else
amoHeight=$(echo "$amoHeight + ($RANDOM % 15)" | bc)
fi
distance=0
dynamite=0
ground=0
trampoline=0
points=0
firstLoad=true
}
high_score()
{
newHighScore=0
i=1
if [ ! -f ".scoreboard" ] ; then
newHighScore=1
while [ $i -le 10 ] ; do
score[$i]="0 anonymous"
let i++
done
else
while IFS=$'\n' read line ; do
score[$i]="$line"
oldScore=$(echo "${score[$i]}" | cut -d ' ' -f 1)
if [ $1 -gt $oldScore -a $newHighScore == 0 ] ; then
newHighScore=$i
fi
let i++
done < .scoreboard
fi
if [ $newHighScore -gt 0 ] ; then
continue="n"
echo "Congratulations! You beat the score at position $newHighScore!"
while [ "${continue^}" != "Y" ] ; do
read -p "Enter your name: " name
if [ -z "$name" ] ; then
name="Anonymous"
fi
read -n 1 -p "is $name correct? " continue
done
if [ $newHighScore -eq 1 ] ; then
read -n 1 -p "Post this score using TTYtter? " continue
if [ "${continue^}" == "Y" ] ; then
ttytter -readline=0 -silent -status="I just shot a $amo $distance feet and now hold the 1st place position on my local scoreboard! #CritterCannon" &> /dev/null&
echo "Score posted."
fi
fi
i=11
while [ $i -gt $newHighScore ] ; do
score[$i]="${score[$(echo "$i - 1" | bc)]}"
let i--
done
name="$(echo "${name^}" | tr " " "_")"
score[$newHighScore]="$1 $name"
i=1
scoreBoard=""
while [ $i -le 10 ] ; do
scoreBoard="${scoreBoard}${score[$i]}\n"
let i++
done
echo -e "${scoreBoard:0:-2}" > .scoreboard
fi
}
while [ "$continue" != "q" ] ; do
initializer
read -n 1 -p "press any key to fire the cannon." continue
clear
play_sound cannon
continue=true
while [ $continue ] ; do
while [ $amoHeight -gt 0 ] ; do
distance=$(echo "$distance + $amoDistance" | bc)
amoHeight=$(echo "$amoHeight - 5" | bc)
if [ $amoDistance -gt 1 ] ; then
let amoDistance--
fi
if [ $distance -gt 1500 ] ; then
distance=$(echo "$RANDOM % 1500 + 1400" | bc)
fi
done
points=$(echo "$points + $distance * 100" | bc)
echo "A $amo $(shuf -n 1 -e "thuds" "crashes" "smashes" "crunches") down on to ${feet[$distance]}."
lastTerrain="${feet[$distance]}"
play_sound "${feet[$distance]}"
case "${feet[$distance]}" in
"a stick of dynamite")
let dynamite++
amoDistance=$(echo "$amoDistance + ($RANDOM % 15)" | bc)
amoHeight=$(echo "$RANDOM % 90 + 30" | bc)
if [ "$lastTerrain" == "a stick of dynamite" ] ; then
amoHeight=$(echo "$amoHeight * 2" | bc)
amoDistance=$(echo "$amoDistance * 2" | bc)
fi
points=$(echo "$points + 1000" | bc)
;;
"a trampoline")
let trampoline++
amoDistance=$(echo "$amoDistance + ($RANDOM % 5)" | bc)
amoHeight=$(echo "$RANDOM % 100 + 50" | bc)
if [ "$lastTerrain" == "a trampoline" ] ; then
amoHeight=$(echo "$amoHeight * 2" | bc)
amoDistance=$(echo "$amoDistance * 2" | bc)
fi
points=$(echo "$points + 500" | bc)
;;
"the ground")
let ground++
let amoDistance++
amoHeight=$(echo "$RANDOM % 4 + 1" | bc)
points=$(echo "$points + 25" | bc)
;;
*)
break
esac
done
echo "You shot a $amo $distance feet. "
if [ $dynamite -ne 1 ] ; then
echo -n "The $amo hit $dynamite sticks of dynamite, "
else
echo -n "The $amo hit $dynamite stick of dynamite, "
fi
if [ $ground -ne 1 ] ; then
echo -n "landed on the ground $ground times, "
else
echo -n "landed on the ground $ground time, "
fi
echo -n "and "
if [ $trampoline -ne 1 ] ; then
echo "bounced on $trampoline trampolines."
else
echo "bounced on $trampoline trampoline."
fi
echo "The $amo was killed when $sex landed on $lastTerrain."
echo "Your score for this shot was $points points."
high_score $distance
echo -e "\nHigh Scores"
i=1
while [ $i -le 10 ] ; do
if [ $i -lt 10 ] ; then
echo -n "0"
fi
echo "$i .......... $(echo "${score[$i]}" | sed 's/ / feet .......... /' | sed 's/_/ /g')"
let i++
done
read -n 1 -p "Press q to quit or any other key to play again: " continue
echo ""
done
exit 0

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1 @@
he

Binary file not shown.

Binary file not shown.

Binary file not shown.

108
getkey.sh Executable file
View File

@ -0,0 +1,108 @@
#!/bin/bash
# Reset terminal to current state when we exit.
trap "stty $(stty -g)" EXIT
# Disable echo and special characters, set input timeout to 0.2 seconds.
stty -echo -icanon time 2 || exit $?
# String containing all keypresses.
KEYS=""
# Set field separator to BELL (should not occur in keypresses)
IFS=$'\a'
# Input loop.
while [ 1 ]; do
# Read more input from keyboard when necessary.
while read -t 0 ; do
read -s -r -d "" -N 1 -t 0.2 CHAR && KEYS="$KEYS$CHAR" || break
done
# If no keys to process, wait 0.05 seconds and retry.
if [ -z "$KEYS" ]; then
sleep 0.02
continue
fi
# Check the first (next) keypress in the buffer.
case "$KEYS" in
$'\x1B\x5B\x41'*) # Up arrow
KEYS="${KEYS##???}"
KEY="Arrow_U"
;;
$'\x1B\x5B\x42'*) # Down Arrow
KEYS="${KEYS##???}"
KEY="Arrow_D"
;;
$'\x1B\x5B\x44'*) # Left Arrow
KEYS="${KEYS##???}"
KEY="Arrow_L"
;;
$'\x1B\x5B\x43'*) # Right Arrow
KEYS="${KEYS##???}"
KEY="Arrow_R"
;;
$'\x1B\x4F\x48'*) # Home
KEYS="${KEYS##???}"
KEY="Home"
;;
$'\x1B\x5B\x31\x7E'*) # Home (Numpad)
KEYS="${KEYS##????}"
KEY="Home"
;;
$'\x1B\x4F\x46'*) # End
KEYS="${KEYS##???}"
KEY="End"
;;
$'\x1B\x5B\x34\x7E'*) # End (Numpad)
KEYS="${KEYS##????}"
KEY="End"
;;
$'\x1B\x5B\x45'*) # 5 (Numpad)
KEYS="${KEYS#???}"
KEY="Numpad_5"
;;
$'\x1B\x5B\x35\x7e'*) # PageUp
KEYS="${KEYS##????}"
KEY="Page_U"
;;
$'\x1B\x5B\x36\x7e'*) # PageDown
KEYS="${KEYS##????}"
KEY="Page_D"
;;
$'\x1B\x5B\x32\x7e'*) # Insert
KEYS="${KEYS##????}"
KEY="Insert"
;;
$'\x1B\x5B\x33\x7e'*) # Delete
KEYS="${KEYS##????}"
KEY="Delete"
;;
$'\n'*|$'\r'*) # Enter/Return
KEYS="${KEYS##?}"
KEY="Enter"
;;
$'\t'*) # Tab
KEYS="${KEYS##?}"
KEY="Tab"
;;
$'\x1B') # Esc (without anything following!)
KEYS="${KEYS##?}"
exit 0
;;
$'\x1B'*) # Unknown escape sequences
echo -n "Unknown escape sequence (${#KEYS} chars): \$'"
echo -n "$KEYS" | od --width=256 -t x1 | sed -e '2,99 d; s|^[0-9A-Fa-f]* ||; s| |\\x|g; s|$|'"'|"
KEYS=""
;;
[$'\x01'-$'\x1F'$'\x7F']*) # Consume control characters
KEYS="${KEYS##?}"
;;
*) # Printable characters.
KEY="${KEYS:0:1}"
KEYS="${KEYS#?}"
;;
esac
echo "$KEY"
done

32
godville-tracker/datachecker.sh Executable file
View File

@ -0,0 +1,32 @@
#!/bin/bash
#If there is more than one command line arg something is wrong
if [ $# -gt 1 ] ; then
echo "usage:
$0 godname"
exit 1
fi
#set godName variable if it was passed from the command line
if [ $# -eq 1 ] ; then
godName="$1"
fi
#read from file if it exists, and name wasn't passed in on command line
if [ -f .godville-trackerrc -a $# -eq 0 ] ; then
source .godville-trackerrc
fi
#if name is not set in file, prompt for it here
if [ -z "$godName" ] ; then
read -p "Please enter the god's name? " godName
fi
godvilleInfo="$(curl -Ss "http://godvillegame.com/gods/api/${godName}.json")"
clear
#remove most of the json stuff
godvilleInfo="$(echo "$godvilleInfo" | sed -e 's/":"/ /g' -e 's/","/\n/g')"
godvilleInfo="$(echo "$godvilleInfo" | sed -e 's/":/ /g' -e 's/,"/\n/g')"
godvilleInfo="$(echo "$godvilleInfo" | sed -e 's/{"//g' -e 's/"}//g')"
echo "$godvilleInfo"
exit 0

103
godville-tracker/godville-tracker Executable file
View File

@ -0,0 +1,103 @@
#!/bin/bash
#If there is more than one command line arg something is wrong
if [ $# -gt 1 ] ; then
echo "usage:
$0 godname"
exit 1
fi
#set godName variable if it was passed from the command line
if [ $# -eq 1 ] ; then
godName="$1"
fi
#read from file if it exists, and name wasn't passed in on command line
if [ -f .godville-trackerrc -a $# -eq 0 ] ; then
source .godville-trackerrc
fi
#if name is not set in file, prompt for it here
if [ -z "$godName" ] ; then
read -p "Please enter the god's name? " godName
fi
#Counter variable initialization
i=60
#main update loop
while [ "${continue^}" != "Q" ] ; do
#Update info every minute
if [ $i -ge 60 ] ; then
godvilleInfo="$(curl -Ss "http://godvillegame.com/gods/api/${godName}.json")"
#godvilleInfo="$(cat tmp.txt)"
clear
#remove most of the json stuff, and other formatting goodness
godvilleInfo="$(echo "$godvilleInfo" | sed -e 's/":"/ /g' -e 's/","/\n/g')"
godvilleInfo="$(echo "$godvilleInfo" | sed -e 's/":/ /g' -e 's/,"/\n/g')"
godvilleInfo="$(echo "$godvilleInfo" | sed -e 's/{"//g' -e 's/"}//g' -e 's/}}//g' -e 's/\\u201[c|d]/"/g')"
#load info into variables
alignment="$(echo "$godvilleInfo" | grep "^alignment" | cut -d ' ' -f2-)"
bricks_cnt="$(echo "$godvilleInfo" | grep "^bricks_cnt" | cut -d ' ' -f2-)"
bricks_cnt=$(echo "scale=1;$bricks_cnt * 0.1" | bc)
clan="$(echo "$godvilleInfo" | grep "^clan " | cut -d ' ' -f2-)"
clan_position="$(echo "$godvilleInfo" | grep "^clan_position" | cut -d ' ' -f2-)"
gender="$(echo "$godvilleInfo" | grep "^gender" | cut -d ' ' -f2-)"
gold_approx="$(echo "$godvilleInfo" | grep "^gold_approx" | cut -d ' ' -f2-)"
inventory="$(echo "$godvilleInfo" | grep "^inventory " | cut -d ' ' -f2-)"
inventory_max_num="$(echo "$godvilleInfo" | grep "^inventory_max_num" | cut -d ' ' -f2-)"
level="$(echo "$godvilleInfo" | grep "^level" | cut -d ' ' -f2-)"
name="$(echo "$godvilleInfo" | grep "^name" | cut -d ' ' -f2-)"
max_health="$(echo "$godvilleInfo" | grep "^max_health" | cut -d ' ' -f2-)"
motto="$(echo "$godvilleInfo" | grep "^motto" | cut -d ' ' -f2-)"
pet_class="$(echo "$godvilleInfo" | grep "^pet_class" | cut -d ' ' -f2-)"
pet_level="$(echo "$godvilleInfo" | grep "^pet_level" | cut -d ' ' -f2-)"
pet_name="$(echo "$godvilleInfo" | grep "^pet pet_name" | cut -d ' ' -f3-)"
quest="$(echo "$godvilleInfo" | grep "^quest" | cut -d ' ' -f2-)"
temple_completed_at="$(echo "$godvilleInfo" | grep "^temple_completed_at" | cut -d ' ' -f2-)"
if [ "$temple_completed_at" != "null" ] ; then
temple_completed_at="$(date --date="$temple_completed_at" +'%I:%M%p %A, %B %d, %Y')"
fi
#display Information
echo "God
Name: $godName
Hero
Name: $name ($gender)
Motto: $motto
Personality: $alignment"
#Not everyone is in a clan:
if [ -n "$clan" ] ; then
echo "Guild: $clan ($clan_position)"
fi
echo "Level: $level
Inventory: ### / $inventory_max_num
Health: ### / $max_health
Quest: $quest
Gold: $gold_approx
Bricks for Temple: $bricks_cnt%"
#Not everyone has completed their temple
if [ "$temple_completed_at" != "null" ] ; then
echo "Temple Completed: $temple_completed_at"
fi
#Not everyone has a pet
if [ -n "$pet_name" ] ; then
echo
echo "Pet
Name: $pet_name
Class $pet_class"
#Not all pets show a level
if [[ "$pet_level" =~ ^[0-9]+$ ]] ; then
echo "Level: $pet_level"
fi
fi
#reset counter variable
i=0
fi
#Wait for user input and sleep for 1 second
read -t1 -n1 continue
#Incriment counter
let i++
done
echo
exit 0

204
horseshoes/horseshoes Executable file
View File

@ -0,0 +1,204 @@
#!/bin/bash
show_instructions()
{
cat << EOF
When it is your turn to throw, press a key to start the round.
You will hear a tone that raises and lowers in pitch.
This tone is the strength bar, the higher the tone the harder you throw the horseshoe.
You don't want to throw it at max strength, because the you will throw the horseshoe too far.
After you have pressed a key to select your strength, you will get another bar, this one a tone that moves from left to right.
This tone is the direction indicator. You will want to throw the shoe when the tone is equal in both speakers, dead center.
Press a key to throw the horse shoe and if you did everything right, you will get a ringer. A ringer is worth 3 points.
If you did everything almost perfect, you will get 1 point. If you completely miss, you get no points.
To play with 2 players, launch the program with the number 2 as the only argument. Without the 2, you will play verses the CPU.
the first person to 15 points wins the game.
EOF
local continue
read -n 1 -p "Press any key to continue. " continue
}
get_cpu_name()
{
local playerName=$1
local getCpuNameVariable=$2
local continue="false"
while [ "$continue" == "false" ] ; do
local cpuName=$(shuf -n 1 -e "Alicia" "Alonzo" "Anthony" "Billy" "Cayden" "Dorothy" "Draken" "Dave" "Ember" "Jeremy" "Kendell" "Kyle" "Storm" "Tux")
if [ "${playerName^}" != "${cpuName^}" ] ; then
local continue="true"
fi
done
if [[ $getCpuNameVariable ]] ; then
eval $getCpuNameVariable="'$cpuName'"
else
echo "$cpuName"
fi
}
check_dependancies()
{
if [[ $(bash --version | head -n 1 | cut -f 1 -d "." | tr -d "[:alpha:]") < "4" ]] ; then
echo "This game requires bash version 4 or higher. Earlier versions may not be able to successfully run this code."
fi
if ! hash sox &> /dev/null ; then
echo "The program sox is required but does not appear to be installed on your system. Please install sox and try again."
exit 1
fi
for i in $@ ; do
if ! hash $i &> /dev/null ; then
echo "The program $i is required but does not appear to be installed on your system. Please install $i and try
again."
exit 1
fi
done
}
play_throw()
{
local distance=$1
local hit=$2
local i=0
local j=$(($distance / 7))
while [ $i -lt $j ] ; do
play -qV0 sounds/throw.ogg norm -$i
let i++
done
play -qV0 sounds/$hit.ogg
}
strength_bar()
{
local __strength_bar_result=$1
#strength indicator, 1 is weakest, 50 is max power.
local x=0
local continue=""
while [ -z "$continue" ] ; do
if [ $x -le 1 ] ; then
local stepper="++"
elif [ $x -ge 50 ] ; then
local stepper="--"
fi
let x$stepper
play -nq synth 0.03 tri $(($x *50))&
read -st 0.03 -n 1 continue
done
if [[ $__strength_bar_result ]] ; then
eval $__strength_bar_result="'$x'"
else
echo "$x"
fi
}
direction_bar()
{
local __direction_bar_result=$1
#Direction indicator, 5 is center, less than 5 is left, more than 5 is right.
local y=0
local continue=""
local lChan=10
local rChan=0
while [ -z "$continue" ] ; do
if [ $lChan -ge 9 ] ; then
local lStepper="--"
local rStepper="++"
elif [ $lChan -le 1 ] ; then
local lStepper="++"
local rStepper="--"
fi
let lChan$lStepper
let rChan$rStepper
play -nq synth 0.05 tri 300 remix v0.$lChan v0.$rChan&
read -st 0.05 -n 1 continue
done
if [ $lChan -ge 5 ] ; then
rChan=0
lChan=$((10 - $lChan))
fi
if [ $rChan -gt 5 ] ; then
lChan=0
fi
y=$(($lChan + $rChan))
if [[ $__direction_bar_result ]] ; then
eval $__direction_bar_result="'$y'"
else
echo "$y"
fi
}
check_dependancies rolldice
read -n 1 -p "Would you like instructions? " answer
echo
if [ "${answer^}" == "Y" ] ; then
show_instructions
fi
echo "Welcome to horseshoes."
read -p "Player 1, please enter your name: " player[1]
if [[ "$1" =~ 2 ]] ; then
read -p "Player 2, please enter your name: " player[2]
vsCpu="false"
else
player[2]="$(get_cpu_name)"
vsCpu="true"
fi
playerCounter=1
score[1]=0
score[2]=0
while [ ${score[1]} -lt 15 -a ${score[2]} -lt 15 ] ; do
msg=""
echo "${player[$playerCounter]} is up to throw. Press any key to continue."
if [ $playerCounter -eq 2 -a "$vsCpu" == "true" ] ; then
sleep 0.7
echo
distance=$(rolldice 2d10+30)
direction=$(rolldice 2d4)
else
read -sn 1 continue
strength_bar distance
direction_bar direction
fi
if [ $direction -ge 4 -a $direction -le 6 ] ; then
if [ $distance -ge 39 -a $distance -le 41 ] ; then
msg="${player[$playerCounter]} got a RINGER! 3 points!"
score[$playerCounter]=$((${score[$playerCounter]} + 3))
hitSound="ringer"
elif [ $distance -gt 35 -a $distance -lt 45 ] ; then
msg="${player[$playerCounter]} got 1 point."
score[$playerCounter]=$((${score[$playerCounter]} + 1))
hitSound="point"
fi
fi
if [ $direction -gt 6 ] ; then
msg="${player[$playerCounter]} threw off to the right. "
hitSound="miss"
fi
if [ $direction -lt 4 ] ; then
msg="${player[$playerCounter]} threw off to the left. "
hitSound="miss"
fi
if [ $distance -le 35 ] ; then
msg="${msg}${player[$playerCounter]} threw short."
hitSound="miss"
fi
if [ $distance -ge 45 ] ; then
msg="${msg}${player[$playerCounter]} threw long."
hitSound="miss"
fi
play_throw $distance $hitSound
echo "$msg"
echo "${player[$playerCounter]}'s score is ${score[$playerCounter]}."
echo
if [ $playerCounter -eq 1 ] ; then
playerCounter=2
else
playerCounter=1
fi
done
if [ ${score[1]} -ge 15 ] ; then
echo "${player[1]} wins with a score of ${score[1]} to ${score[2]}!"
else
echo "${player[2]} wins with a score of ${score[2]} to ${score[1]}!"
fi
play -qV0 sounds/win.ogg
exit 0

BIN
horseshoes/sounds/miss.ogg Normal file

Binary file not shown.

BIN
horseshoes/sounds/point.ogg Normal file

Binary file not shown.

Binary file not shown.

BIN
horseshoes/sounds/throw.ogg Normal file

Binary file not shown.

BIN
horseshoes/sounds/win.ogg Normal file

Binary file not shown.

11
numnastics/README Normal file
View File

@ -0,0 +1,11 @@
Numnastics
Written by Storm Dragon
released under the terms of the WTFPL http://wtfpl.net/
Requirements
sox
bash version 4 or greater
TTYtter (optional)
Playing
You are given a scrambled list of numbers from 1 to 9. Press the number you want to flip from, and that number, plus all the numbers after it will reverse. the object of the game is to get the numbers in the right order, 123456789, in as few tries as possible.

75
numnastics/numnastics Executable file
View File

@ -0,0 +1,75 @@
#!/bin/bash
check_dependancies()
{
if [ $# -eq 0 ] ; then
if [[ $(bash --version | head -n 1 | cut -f 1 -d "." | tr -d "[:alpha:]") < "4" ]] ; then
echo "This game requires bash version 4 or higher. Earlier versions may not be able to successfully run this code."
fi
if ! hash sox &> /dev/null ; then
echo "The program sox is required but does not appear to be installed on your system. Please install sox and try again."
exit 1
fi
fi
for i in $@ ; do
if ! hash $i &> /dev/null ; then
echo "The program $i is required but does not appear to be installed on your system. Please install $i and try again."
exit 1
fi
done
}
initializer()
{
tries=0
numberString="$(shuf -e 1 2 3 4 5 6 7 8 9 | tr -d "[:space:]")"
}
check_dependancies
initializer
while [ $numberString -ne 123456789 ] ; do
read -n 1 -p "$numberString " number
if [ "$number" == "Q" ] ; then
echo
exit 0
fi
if ! [[ "$number" =~ ^[0-9]+$ ]] ; then
unset number
fi
if [ "$number" == "0" ] ; then
unset number
fi
echo
if [ "$number" != "" ] ; then
i=0
while [ ${numberString:$i:1} -ne $number ] ; do
let i++
done
newNumberString=$(echo ${numberString:$i:9} | rev)
numberString=${numberString:0:$i}$newNumberString
let tries++
play -nqV0 synth .05 tri C2:C7 norm -7
else
play -qV0 "|sox -n -p synth saw E2 fade 0 0.25 0.05" "|sox -n -p synth saw E2 fade 0 0.25 0.05" norm -7
fi
done
if [ -f ".numnastics-score" ] ; then
oldHighScore=$(cat .numnastics-score | tr -d "[:alpha:][:cntrl:][:punct:][:space:]")
else
oldHighScore=0
fi
echo "Congratulations! You win with $tries moves."
if [ $oldHighScore -ne 0 ] ; then
echo " The record is $oldHighScore."
fi
if [ $tries -lt $oldHighScore -o $oldHighScore -eq 0 ] ; then
echo "$tries" > .numnastics-score
read -n 1 -p "You have set a new record! Would you like to post this score to Twitter using TTYtter? " answer
if [ "${answer^}" == "Y" ] ; then
check_dependancies ttytter
ttytter -readline=0 -silent -status="I just beat #numnastics in $tries moves! $(if [ $oldHighScore -ne 0 ] ; then echo "This is $(($oldHighScore - $tries)) fewer moves than my previous record!";fi)" &> /dev/null &
fi
fi
play -qV0 sounds/win.ogg
echo
exit 0

BIN
numnastics/sounds/win.ogg Normal file

Binary file not shown.

13
pig-dice/README Normal file
View File

@ -0,0 +1,13 @@
pig-dice
Written by Storm Dragon
Released under the terms of the WTFPL http://wtfpl.net/
Requirements
rolldice
sox
bash version 4 or greater
Playing
To play verses the CPU just run ./pig-dice
To play verses other people (not online) run ./pig-dice number where number is 2 or more.
The object is to get to 100 before anyone else. if you roll a 1 though, you lose your score for that turn.

112
pig-dice/pig-dice Executable file
View File

@ -0,0 +1,112 @@
#!/bin/bash
check_dependancies()
{
if [ $# -eq 0 ] ; then
if [[ $(bash --version | head -n 1 | cut -f 1 -d "." | tr -d "[:alpha:]") < "4" ]] ; then
echo "This game requires bash version 4 or higher. Earlier versions may not be able to successfully run this code."
fi
if ! hash sox &> /dev/null ; then
echo "The program sox is required but does not appear to be installed on your system. Please install sox and try
again."
exit 1
fi
fi
for i in $@ ; do
if ! hash $i &> /dev/null ; then
echo "The program $i is required but does not appear to be installed on your system. Please install $i and try
again."
exit 1
fi
done
}
initialize_players()
{
i=1
while [ $i -le $1 ] ; do
player[$i]=0
let i++
done
}
score_keeper()
{
#Initialize currentScore for the player to 0
currentScore=0
#clear the continue variable
unset continue
#Show current player
i=1
while [ $i -lt $columns ] ; do
echo -n "-"
let i++
done
echo "-"
echo "It is player $1's turn. Player $1 has ${player[$1]} total points."
#while the die roll is not 1 keep rolling and keep track of the score
while [ "${continue^}" != "Q" ] ; do
dieRoll=$(rolldice 1)
play -qV0 "sounds/die.ogg" remix v0.$(rolldice 1d4+4) v0.$(rolldice 1d4+4)
echo -n "player $1 rolled a $dieRoll "
if [ $dieRoll -ne 1 ] ; then
currentScore=$(echo "$currentScore + $dieRoll" | bc)
echo "for a score of $currentScore."
if [ $1 -eq 2 -a "$cpu" == "true" ] ; then
continue="$(shuf -n 1 -e "q" "a" "b" "c" "d")"
else
read -n 1 -p "Press any key to roll again or q to stop and bank your current score." continue
fi
echo
else
echo "and loses their score of $currentScore."
play -qV0 sounds/lose.ogg
currentScore=0
continue="q"
fi
if [ "${continue^}" == "Q" -o $currentScore -eq 0 ] ; then
player[$1]=$(echo "${player[$1]} + $currentScore" | bc)
echo "player $1's turn is over. Player $1's new score is ${player[$1]}."
fi
if [ ${player[$1]} -ge 100 ] ; then
echo "Player $1 WINS!!!"
play -qV0 sounds/win.ogg
exit 0
fi
done
}
check_dependancies
check_dependancies rolldice
#get terminal width
columns=$(tput cols)
#find out how many players there are
if [ $# -gt 1 ] ; then
echo "Usage: $0 or $0 number of players."
exit 1
fi
if [ $# -eq 1 ] ; then
if ! [[ "$1" =~ ^[0-9]+$ ]] ; then
echo "The number of players must be a number, 2 or greater."
exit 1
fi
if [ $1 -lt 2 ] ; then
echo "The number of players must be a number, 2 or greater."
exit 1
fi
totalPlayers=$1
else
totalPlayers=2
cpu=true
fi
initialize_players $totalPlayers
#determine who goes first.
playerIndex=$(rolldice 1d${#player[@]})
while [ $playerIndex -gt 0 ] ; do
score_keeper $playerIndex
let playerIndex++
if [ $playerIndex -gt ${#player[@]} ] ; then
playerIndex=1
fi
done
exit 0

BIN
pig-dice/sounds/die.ogg Normal file

Binary file not shown.

BIN
pig-dice/sounds/lose.ogg Normal file

Binary file not shown.

BIN
pig-dice/sounds/win.ogg Normal file

Binary file not shown.

33
sex/sex Executable file
View File

@ -0,0 +1,33 @@
#!/bin/bash
#simplest way to convert the sex program to bash
#The C version is available from: http://spatula.net/software/sex/
#This version is released under the terms of the WTFPL http://www.wtfpl.net/
#set up random parts of the sentence
faster="$(shuf -n 1 -e "\"Let the games begin!\"" "\"Sweet Jesus!\"" "\"Not that!\"" "\"At last!\"" "\"Land o' Goshen!\"" "\"Is that all?\"" "\"Cheese it, the cops!\"" "\"I never dreamed it could be\"" "\"If I do, you won't respect me!\"" "\"Now!\"" "\"Open sesame!\"" "\"EMR!\"" "\"Again!\"" "\"Faster!\"" "\"Harder!\"" "\"Help!\"" "\"Fuck me harder!\"" "\"Is it in yet?\"" "\"You aren't my father!\"" "\"Doctor, that's not *my* shou\"" "\"No, no, do the goldfish!\"" "\"Holy Batmobile, Batman!\"" "\"He's dead, he's dead!\"" "\"Take me, Robert!\"" "\"I'm a Republican!\"" "\"Put four fingers in!\"" "\"What a lover!\"" "\"Talk dirty, you pig!\"" "\"The ceiling needs painting,\"" "\"Suck harder!\"" "\"The animals will hear!\"" "\"Not in public!\"")"
said="$( shuf -n 1 -e "bellowed" "yelped" "croaked" "growled" "panted" "moaned" "grunted" "laughed" "warbled" "sighed" "ejaculated" "choked" "stammered" "wheezed" "squealed" "whimpered" "salivated" "tongued" "cried" "screamed" "yelled" "said")"
fadj="$(shuf -n 1 -e "saucy" "wanton" "unfortunate" "lust-crazed" "nine-year-old" "bull-dyke" "bisexual" "gorgeous" "sweet" "nymphomaniacal" "large-hipped" "freckled" "forty-five year old" "white-haired" "large-boned" "saintly" "blind" "bearded" "blue-eyed" "large tongued" "friendly" "piano playing" "ear licking" "doe eyed" "sock sniffing" "lesbian" "hairy")"
female="$(shuf -n 1 -e "baggage" "hussy" "woman" "Duchess" "female impersonator" "nymphomaniac" "virgin" "leather freak" "home-coming queen" "defrocked nun" "bisexual budgie" "cheerleader" "office secretary" "sexual deviate" "DARPA contract monitor" "little matchgirl" "ceremonial penguin" "femme fatale" "bosses' daughter" "construction worker" "sausage abuser" "secretary" "Congressman's page" "grandmother" "penguin" "German shepherd" "stewardess" "waitress" "prostitute" "computer science group" "housewife")"
madjec="$(shuf -n 1 -e "thrashing" "slurping" "insatiable" "rabid" "satanic" "corpulent" "nose-grooming" "tripe-fondling" "dribbling" "spread-eagled" "orally fixated" "vile" "awesomely endowed" "handsome" "mush-brained" "tremendously hung" "three-legged" "pile-driving" "cross-dressing" "gerbil buggering" "bung-hole stuffing" "sphincter licking" "hair-pie chewing" "muff-diving" "clam shucking" "egg-sucking" "bicycle seat sniffing")"
male="$(shuf -n 1 -e "rakehell" "hunchback" "lecherous lickspittle" "archduke" "midget" "hired hand" "great Dane" "stallion" "donkey" "electric eel" "paraplegic pothead" "dirty old man" "faggot butler" "friar" "black-power advocate" "follicle fetishist" "handsome priest" "chicken flicker" "homosexual flamingo" "ex-celibate" "drug sucker" "ex-woman" "construction worker" "hair dresser" "dentist" "judge" "social worker")"
diddled="$(shuf -n 1 -e "diddled" "devoured" "fondled" "mouthed" "tongued" "lashed" "tweaked" "violated" "defiled" "irrigated" "penetrated" "ravished" "hammered" "bit" "tongue slashed" "sucked" "fucked" "rubbed" "grudge fucked" "masturbated with" "slurped")"
titadj="$(shuf -n 1 -e "alabaster" "pink-tipped" "creamy" "rosebud" "moist" "throbbing" "juicy" "heaving" "straining" "mammoth" "succulent" "quivering" "rosey" "globular" "varicose" "jiggling" "bloody" "tilted" "dribbling" "oozing" "firm" "pendulous" "muscular" "bovine")"
knockers="$(shuf -n 1 -e "globes" "melons" "mounds" "buds" "paps" "chubbies" "protuberances" "treasures" "buns" "bung" "vestibule" "armpits" "tits" "knockers" "elbows" "eyes" "hooters" "jugs" "lungs" "headlights" "disk drives" "bumpers" "knees" "fried eggs" "buttocks" "charlies" "ear lobes" "bazooms" "mammaries")"
thrust="$(shuf -n 1 -e "plunged" "thrust" "squeezed" "pounded" "drove" "eased" "slid" "hammered" "squished" "crammed" "slammed" "reamed" "rammed" "dipped" "inserted" "plugged" "augured" "pushed" "ripped" "forced" "wrenched")"
dongadj="$(shuf -n 1 -e "bursting" "jutting" "glistening" "Brobdingnagian" "prodigious" "purple" "searing" "swollen" "rigid" "rampaging" "warty" "steaming" "gorged" "trunklike" "foaming" "spouting" "swinish" "prosthetic" "blue veined" "engorged" "horse like" "throbbing" "humongous" "hole splitting" "serpentine" "curved" "steel encased" "glass encrusted" "knobby" "surgically altered" "metal tipped" "open sored" "rapidly dwindling" "swelling" "miniscule" "boney")"
dong="$(shuf -n 1 -e "intruder" "prong" "stump" "member" "meat loaf" "majesty" "bowsprit" "earthmover" "jackhammer" "ramrod" "cod" "jabber" "gusher" "poker" "engine" "brownie" "joy stick" "plunger" "piston" "tool" "manhood" "lollipop" "kidney prodder" "candlestick" "John Thomas" "arm" "testicles" "balls" "finger" "foot" "tongue" "dick" "one-eyed wonder worm" "canyon yodeler" "middle leg" "neck wrapper" "stick shift" "dong" "Linda Lovelace choker")"
twatadj="$(shuf -n 1 -e "pulsing" "hungry" "hymeneal" "palpitating" "gaping" "slavering" "welcoming" "glutted" "gobbling" "cobwebby" "ravenous" "slurping" "glistening" "dripping" "scabiferous" "porous" "soft-spoken" "pink" "dusty" "tight" "odiferous" "moist" "loose" "scarred" "weapon-less" "banana stuffed" "tire tracked" "mouse nibbled" "tightly tensed" "oft traveled" "grateful" "festering")"
twat="$(shuf -n 1 -e "swamp." "honeypot." "jam jar." "butterbox." "furburger." "cherry pie." "cush." "slot." "slit." "cockpit." "damp." "furrow." "sanctum sanctorum." "bearded clam." "continental divide." "paradise valley." "red river valley." "slot machine." "quim." "palace." "ass." "rose bud." "throat." "eye socket." "tenderness." "inner ear." "orifice." "appendix scar." "wound." "navel." "mouth." "nose." "cunt.")"
#set default wordwrap to 80
if [[ "$1" == "-w" && "$2" =~ ^[0-9]+$ && $2 -gt 0 && $2 -le 500 ]] ; then
lineLength=$2
fi
#generate the sentence with wordwrap
if [ -n "$lineLength" ] ; then
echo "$faster $said the $fadj $female as the $madjec $male $diddled her $titadj $knockers and $thrust his $dongadj $dong into her $twatadj $twat" | fold -sw $lineLength
else
echo "$faster $said the $fadj $female as the $madjec $male $diddled her $titadj $knockers and $thrust his $dongadj $dong into her $twatadj $twat"
fi
exit 0

19
soundboard/soundboard Executable file
View File

@ -0,0 +1,19 @@
#!/bin/bash
if [ $# -ne 1 ] ; then
echo "Usage: soundboard name, where name is the name of a soundboard you want to load."
exit 1
fi
if ! [ -d sounds/$1 ] ; then
echo "soundboard $1 not found."
exit 1
fi
while [ 1 -gt 0 ] ; do
read -sn1 key
if [ -f sounds/$1/$key.ogg ] ; then
play -qV0 sounds/$1/$key.ogg&
fi
done
exit 0

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
soxsynth.tar.gz Normal file

Binary file not shown.

10
soxsynth/README Normal file
View File

@ -0,0 +1,10 @@
soxsynth by Storm Dragon
Released under the terms of the WTFPL http://wtfpl.net/
Usage
./soxsynth
Provides 3 octaves of notes, z-,, a-k, and q-i. To play the sharp of a note, press and hold shift while playing the note.
1-6 changes instrument, the default is guitar.
! disables all effects, this is the default.
@-$ changes effects. Each effect key toggles the effect on and off.
To close, press control+c

266
soxsynth/soxsynth Executable file
View File

@ -0,0 +1,266 @@
#!/bin/bash
#This project inspired by a tweet from @climagic
#The original text of the tweet is:
#n=CDEFGAB;l=asdfghj;while read -n1 k;do x=$(tr $l $n<<<$k);play -qn synth pl ${x}3 fade 0 .7 & >/dev/null;done # Polyphonic by .@sentibryan
# https://twitter.com/climagic/statuses/149581073263771649
#Keyboard synthesizer by @stormdragon2976
#License WTFPL https://en.wikipedia.org/wiki/WTFPL
#Sunday, October 21, 2012
#Initial variable settings
effect=""
instrument="pl"
octave="2"
volume="0.8"
noteLength="0.75"
while read -sn1 key ; do
case $key in
"z")
note="C"
octave=2
;;
"x")
note="D"
octave=2
;;
"c")
note="E"
octave=2
;;
"v")
note="F"
octave=2
;;
"b")
note="G"
octave=2
;;
"n")
note="A"
octave=2
;;
"m")
note="B"
octave=2
;;
",")
note="C"
octave=3
;;
"Z")
note="C#"
octave=2
;;
"X")
note="D#"
octave=2
;;
"C")
note="E#"
octave=2
;;
"V")
note="F#"
octave=2
;;
"B")
note="G#"
octave=2
;;
"N")
note="A#"
octave=2
;;
"M")
note="B#"
octave=2
;;
"a")
note="C"
octave=3
;;
"s")
note="D"
octave=3
;;
"d")
note="E"
octave=3
;;
"f")
note="F"
octave=3
;;
"g")
note="G"
octave=3
;;
"h")
note="A"
octave=3
;;
"j")
note="B"
octave=3
;;
"k")
note="C"
octave=4
;;
"A")
note="C#"
octave=3
;;
"S")
note="D#"
octave=3
;;
"D")
note="E#"
octave=3
;;
"F")
note="F#"
octave=3
;;
"G")
note="G#"
octave=3
;;
"H")
note="A#"
octave=3
;;
"J")
note="B#"
octave=3
;;
"q")
note="C"
octave=4
;;
"w")
note="D"
octave=4
;;
"e")
note="E"
octave=4
;;
"r")
note="F"
octave=4
;;
"t")
note="G"
octave=4
;;
"y")
note="A"
octave=4
;;
"u")
note="B"
octave=4
;;
"i")
note="C"
octave=5
;;
"Q")
note="C#"
octave=4
;;
"W")
note="D#"
octave=4
;;
"E")
note="E#"
octave=4
;;
"R")
note="F#"
octave=4
;;
"T")
note="G#"
octave=4
;;
"Y")
note="A#"
octave=4
;;
"U")
note="B#"
octave=4
;;
"1")
instrument="pl"
volume="0.8"
;;
"2")
instrument="sin"
volume="0.6"
;;
"3")
instrument="sq"
volume="0.2"
;;
"4")
instrument="exp"
volume="0.6"
;;
"5")
instrument="tri"
volume="0.6"
;;
"6")
instrument="12"
volume="0.8"
;;
"!")
effect=""
;;
"@")
if [[ $(echo "$effect" | grep -i "flanger") ]] ; then
effect="$(echo "$effect" | sed 's/flanger //g')"
else
effect="${effect}flanger "
fi
;;
"#")
if [[ $(echo "$effect" | grep -i "phaser") ]] ; then
effect="$(echo "$effect" | sed 's/phaser //g')"
else
effect="${effect}phaser "
fi
;;
"$")
if [[ $(echo "$effect" | grep -i "overdrive") ]] ; then
effect="$(echo "$effect" | sed 's/overdrive 100 20 //g')"
else
effect="${effect}overdrive 100 20 "
fi
;;
"/")
noteLength="0.25"
;;
"'")
noteLength="0.50"
;;
"]")
noteLength="0.75"
;;
"=")
noteLength="1.00"
esac
if [ "$instrument" == "12" ] ; then
play -qn -V0 synth pl ${note}$(($octave + 1)) pl ${note}${octave} delay 0 0.02 remix - $effect fade 0 $noteLength vol $volume &> /dev/null &
else
play -qn -V0 synth $instrument ${note}${octave} $effect fade 0 $noteLength vol $volume &> /dev/null &
fi
echo -n "$note"
done
exit 0

BIN
spellit/sounds/cheer1.ogg Normal file

Binary file not shown.

85
spellit/spellit Executable file
View File

@ -0,0 +1,85 @@
#!/bin/bash
speak_msg()
{
#Default voice en-us
espeak -v en-us "$@" &> /dev/null
}
while [ "$continue" != "n" ] ; do
#get file to use.
if [ -n "$1" ] ; then
fileName="words/$1.txt"
shift
else
clear
echo "Please select a word list to use:"
x=1
for i in words/*.txt ; do
echo "$x: $(basename "$i" | sed 's/.txt//g')"
fileList[$x]="$(basename "$i" | sed 's/.txt//g')"
let x++
done
echo "$x: Exit"
fileList[$x]="Exit"
read continue
if [ "${fileList[$continue]}" == "Exit" ] ; then
exit 0
fi
fileName="words/${fileList[$continue]}.txt"
echo "$fileName selected. Press any key to begin."
read x
fi
i=0
missed=0
correct=0
points=0
totalPoints=0
x=0
while read line ; do
words[$x]="$line"
let x++
done < $fileName
while [ $i -lt $x ] ; do
if [ "$continue" == "q" ] ; then
break
fi
clear
word="$(echo "${words[$i]}" | cut -d : -f 1)"
sentence="$(echo "${words[$i]}" | cut -d : -f 2- | cut -d \n -f 1-)"
speak_msg "Can you spell the word $word?"
totalPoints="$(echo "$points + 10 * ${#word}" | bc)"
read continue
while [ "${#continue}" == 1 ] ; do
case $continue in
"s")
speak_msg "$sentence"
read continue
break
;;
*)
break
esac
done
if [ "$continue" == "$word" ] ; then
speak_msg "$(shuf -n 1 -e "Excellent" "Great" "Awesome")! you got it right!"
play -qV0 "$(shuf -n 1 -e sounds/cheer*.ogg)"
let correct++
points="$(echo "$points + 10 * ${#word}" | bc)"
else
if [ "$continue" != "n" ] ; then
speak_msg "Sorry, you got it wrong."
let missed++
fi
fi
let i++
done
speak_msg "Out of $i words you got $correct right and missed $missed. Your score is $points points out of $totalPoints possible points for this list."
if [ $missed -eq 0 -a "$continue" != "q" ] ; then
speak_msg "Great job!"
fi
speak_msg "Play again?"
read -n 1 continue
done
clear
exit 0

3
spellit/words/simple.txt Normal file
View File

@ -0,0 +1,3 @@
cat:the cat says meow.
car:I got a new car yesterday.
dog:If that dog doesn't stop barking, I'm gonna put it in the microwave!

BIN
yahtzee.tar.gz Normal file

Binary file not shown.

5
yahtzee/README Normal file
View File

@ -0,0 +1,5 @@
Yahtzee by Storm Dragon
Released under the terms of the WTFPL: http://wtfpl.net/
Playing
Each player gets up to 3 rolls of the dice. To select the dice to reroll, enter the number shown. For example, if you roll 1, 2, 4, 5 and 6, you can choose to reroll 1 and 6 by typing 16 or 61 or 1 6 or 6 1. To select no dice, just press enter. To select a slot on the score sheet, press the letter of the slot you want, s for small straight, l for large straight, 3 for 3s etc. To select 3 of a kind press #. To select four of a kind press $. Yahtzee is currently PVP only. You can play with one player, in solataire mode.

BIN
yahtzee/sounds/die1.ogg Normal file

Binary file not shown.

BIN
yahtzee/sounds/die2.ogg Normal file

Binary file not shown.

383
yahtzee/yahtzee Executable file
View File

@ -0,0 +1,383 @@
#!/bin/bash
initializer()
{
#Make sure number of players is a number.
if ! [[ $1 =~ ^[1-9]+$ ]] ; then
echo "Usage: yahtzee or yahtzee number of players."
fi
#creates the initial player variables for all the players
genIndex=1
while [ $genIndex -le $1 ] ; do
player[$genIndex]="false"
i=0
while [ $i -lt 12 ] ; do
player[$genIndex]="${player[$genIndex]}:false"
let i++
done
let genIndex++
done
#Randomly pick which player goes first.
if [ $1 -gt 1 ] ; then
playerIndex=$(rolldice 1d$1 | tr -d "[:space:]")
else
playerIndex=1
fi
}
roll()
{
clear
unset diceSoundString
#Only play the number of dice rolls we are actually rolling.
i=0
while [ $i -lt $1 ] ; do
diceSoundString="$diceSoundString sounds/die$(rolldice 1d2 | tr -d "[:space:]").ogg"
let i++
done
#if there is only one die the -m (mix) option is not needed.
if [ $i -eq 1 ] ; then
play -qV0 $diceSoundString remix v0.$(rolldice 1d4+4) v0.$(rolldice 1d4+4)
else
play -mqV0 $diceSoundString remix v0.$(rolldice 1d4+4) v0.$(rolldice 1d4+4)
fi
echo "Player $playerIndex rolls $1 $(if [ $1 -gt 1 ] ; then echo "dice";else echo "die";fi)."
#if 5 dice are needed then replace the whole dice variable, if not, only replace the rolled dice.
if [ $1 -lt 5 ] ;then
dice="$dice $(rolldice ${1}x6 | tr -s " ")"
else
dice="$(rolldice 5x6 | tr -s " ")"
fi
#remove extra spaces from the dice string.
dice="$(echo "$dice" | tr -s "[:space:]")"
#Only show the rolled dice.
echo "${dice:$((${#dice} - $1 * 2)):${#dice}}." | rev | sed -e 's/^. /./' -e 's/ / ,/g' -e 's/ ,/ dna /' | rev
}
score_sheet()
{
display="true"
double="false"
tripple="false"
#Initialize the score sheet to all 0s.
i=1
while [ $i -le 13 ] ; do
score[$i]=0
let i++
done
#Draw upper line of score sheet.
line=1
echo -n "|"
while [ $line -lt 29 ] ; do
echo -n "-"
let line++
done
echo "|"
#dice total is needed for scoring chance, small straight and large straight.
diceTotal="$(echo "$dice" | sed -e 's/^ //' -e 's/ $//' | tr " " "+")"
diceTotal=$(($diceTotal))
#set the chance section.
score[9]=$diceTotal
#Check for straights.
straight=$(echo "$dice" | tr " " "\n" | sort | tr -d "\n" | tr -s "[:digit:]")
if [ $straight -eq 1234 -o $straight -eq 2345 -o $straight -eq 3456 ] ; then
#We have a small straight.
score[12]=30
fi
if [ $straight -eq 12345 -o $straight -eq 23456 ] ; then
#We have a large straight, which automatically means we have a small straight as well.
score[11]=40
score[12]=30
fi
#check how many of each die there is.
i=1
while [ $i -le 13 ] ; do
x="$(echo "$dice" | grep $i | tr -Cd "$i " | tr -s " " | sed -e 's/^ //' -e 's/ $//' | tr " " "+")"
#Check for yahtzee
if [ "$x" = "${i}+${i}+${i}+${i}+${i}" ] ; then
if [[ "$(echo "${player[$1]}" | cut -d ":" -f 13)" == "50" ]] ; then
#More than 1 yahtzee is 100 points.
score[13]=100
else
#First yahtzee is 50 points.
score[13]=50
fi
fi
#set the dice score for each set of pips.
if [ "$x" != "" ] ; then
score[$i]=$(($x))
fi
#First part of check for full house, 2 of a kind + 3 of a kind.
if [ $((2 * $i)) -eq ${score[$i]} ] ; then
double="true"
if [ "$tripple" == "true" ] ; then
score[10]=25
fi
fi
#check for 3 of a kind as well as the second check for full house.
if [ $((3 * $i)) -eq ${score[$i]} ] ; then
tripple="true"
if [ "$double" == "true" ] ; then
score[10]=25
fi
score[7]=$diceTotal
fi
#Check for 4 of a kind, which automatically means there is 3 of a kind too.
if [ $((4 * $i)) -eq ${score[$i]} ] ; then
score[7]=$diceTotal
score[8]=$diceTotal
fi
case $i in
7)
#Draw section seperation line in score sheet.
line=1
echo -n "|"
while [ $line -lt 29 ] ; do
echo -n "-"
let line++
done
echo "|"
#Only display the option if it has not already been scored.
if [[ "$(echo "${player[$1]}" | cut -f $i -d ":")" == "false" ]] ; then
echo -n "| 3 of a kind "
display="true"
else
display="false"
fi
;;
8)
if [[ "$(echo "${player[$1]}" | cut -f $i -d ":")" == "false" ]] ; then
echo -n "| 4 of a kind "
display="true"
else
display="false"
fi
;;
9)
if [[ "$(echo "${player[$1]}" | cut -f $i -d ":")" == "false" ]] ; then
echo -n "| Chance "
display="true"
else
display="false"
fi
;;
10)
if [[ "$(echo "${player[$1]}" | cut -f $i -d ":")" == "false" ]] ; then
echo -n "| Full house "
display="true"
else
display="false"
fi
;;
11)
if [[ "$(echo "${player[$1]}" | cut -f $i -d ":")" == "false" ]] ; then
echo -n "| Large straight "
display="true"
else
display="false"
fi
;;
12)
if [[ "$(echo "${player[$1]}" | cut -f $i -d ":")" == "false" ]] ; then
echo -n "| Small straight "
display="true"
else
display="false"
fi
;;
13)
if [[ "$(echo "${player[$1]}" | cut -f $i -d ":")" != "0" ]] ; then
echo -n "| Yahtzee "
display="true"
else
display="false"
fi
;;
*)
if [[ "$(echo "${player[$1]}" | cut -f $i -d ":")" == "false" ]] ; then
echo -n "| ${i}s "
display="true"
else
display="false"
fi
esac
#Only display the score if the first half is displayed.
if [ "$display" == "true" ] ; then
#Format the score so the right side of the box lines up.
if [ ${score[$i]} -lt 10 ] ; then
echo "${score[$i]} |"
elif [ ${score[$i]} -ge 100 ] ; then
echo "${score[$i]} |"
else
echo "${score[$i]} |"
fi
fi
let i++
done
#Draw the bottom of the score sheet.
line=1
echo -n "|"
while [ $line -lt 29 ] ; do
echo -n "_"
let line++
done
echo "|"
}
dice_parser()
{
error="true"
while [ "$error" == "true" ] ; do
#Remove spaces from the reroll string.
continue="$(echo "$continue" | tr -d "[:space:]")"
#Make sure the reroll string contains valid dice options.
if ! [[ "$continue" =~ ^[1-6]+$ ]] ; then
error="true"
echo -n "Dice must be numbers 1-6 only. "
else
error="false"
fi
#Make sure the requested dice are actually available to reroll.
if [[ $(echo "$dice" | tr -d "$continue") == "$dice" ]] ; then
if [ "$error" == "false" ] ; then
error="true"
unset continue
echo -n "That is not one of the available dice to reroll. "
fi
else
error="false"
fi
#Only oporate on the dice string if there are no errors.
if [ "$error" == "false" ] ; then
i=0
while [ $i -lt ${#continue} ] ; do
#Remove all the selected dice from the dice string.
dice=$(echo "$dice" | sed "s/${continue:$i:1} //")
let i++
done
else
#Play error sound.
play -qV0 "|sox -n -p synth saw E2 fade 0 0.25 0.05" "|sox -n -p synth saw E2 fade 0 0.25 0.05" norm -7
fi
#Set the number of dice that need to be rerolled.
dieCounter=$((5 - ${#dice} / 2))
if [ "$error" == "true" ] ; then
read continue
fi
done
}
score_dice()
{
error="true"
while [ "$error" == "true" ] ; do
read -n 1 -p "Select score slot. " continue
case "${continue^}" in
[1-6])
#scoring for slots 1-6.
fieldIndex=$continue
;;
#3 of a kind.
"#")
fieldIndex=7
;;
#4 of a kind.
"$")
fieldIndex=8
;;
#Chance.
"C")
fieldIndex=9
;;
#Full house.
"F")
fieldIndex=10
;;
#Large straight.
"L")
fieldIndex=11
;;
#Small straight.
"S")
fieldIndex=12
;;
#Yahtzee
"Y")
fieldIndex=13
;;
*)
unset fieldIndex
esac
#Make sure the key press was valid.
if [ "$fieldIndex" != "" ] ; then
#make sure the selected slot hasn't already been scored.
if [[ $(echo "${player[$1]}" | cut -d ":" -f $fieldIndex) != "false" ]] ; then
play -qV0 "|sox -n -p synth saw E2 fade 0 0.25 0.05" "|sox -n -p synth saw E2 fade 0 0.25 0.05" norm -7
error="true"
echo -e "\nThat is not a valid scoring option."
else
error="false"
fi
else
error="true"
fi
done
#Set the score in the player variable.
player[$1]="$(echo "${player[$1]}" | sed 's/:/\n/g' | sed -e $fieldIndex"s/false/${score[$fieldIndex]}/" | tr "\n" ":" | sed 's/:$//')"
playerScore="$(echo "${player[$1]}" | tr -d "[:alpha:]" | tr -s ":" | tr ":" "+" | sed -e 's/^\+//' -e 's/\+$//')"
echo
read -t 3 -n 1 -p "Player $1's score is $(($playerScore))." continue
}
if [ $# -eq 1 ] ; then
initializer $1
totalPlayers="$1"
else
initializer 1
totalPlayers=1
fi
#If the word false is in any player varaible the game is not over.
while [[ $(echo "${player[@]}" | grep "false") ]] ; do
rollCounter=0
dieCounter=5
continue="true"
#Each player gets up to 3 rolls.
while [ $rollCounter -lt 3 ] ; do
if [ "$continue" != "" ] ; then
roll $dieCounter
else
break
fi
#show the score sheet after each roll.
score_sheet $playerIndex
let rollCounter++
if [ $rollCounter -lt 3 ] ; then
read -p "Enter the dice you would like to reroll or enter to keep all the dice." continue
if [ "$continue" != "" ] ; then
dice_parser $playerIndex
fi
fi
done
score_dice $playerIndex
if [ $playerIndex -ge $totalPlayers ] ; then
playerIndex=1
else
let playerIndex++
fi
done
#show who won the game.
i=1
winningScore=0
winner=1
while [ $i -le $totalPlayers ] ; do
playerScore="$(echo "${player[$i]}" | tr -d "[:alpha:]" | tr -s ":" | tr ":" "+" | sed -e 's/^\+//' -e 's/\+$//')"
playerScore=$(($playerScore))
if [ $playerScore -gt $winningScore ] ; then
winningScore=$playerScore
winner=$i
fi
let i++
done
echo
echo "Player $winner wins!!!"
exit 0

Binary file not shown.

Binary file not shown.

BIN
zombie-dice/sounds/die.ogg Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

72
zombie-dice/zombie-dice Executable file
View File

@ -0,0 +1,72 @@
#!/bin/bash
check_dependancies()
{
if [ $# -eq 0 ] ; then
if [[ $(bash --version | head -n 1 | cut -f 1 -d "." | tr -d "[:alpha:]") < "4" ]] ; then
echo "This game requires bash version 4 or higher. Earlier versions may not be able to successfully run this code."
fi
if ! hash sox &> /dev/null ; then
echo "The program sox is required but does not appear to be installed on your system. Please install sox and try
again."
exit 1
fi
fi
for i in $@ ; do
if ! hash $i &> /dev/null ; then
echo "The program $i is required but does not appear to be installed on your system. Please install $i and try
again."
exit 1
fi
done
}
initialize_players()
{
i=1
while [ $i -le $1 ] ; do
player[$i]=0
let i++
done
}
play_sound()
{
play -qV0 sounds/$@
}
check_dependancies
check_dependancies rolldice
#get terminal width
columns=$(tput cols)
play_sound intro.ogg
#find out how many players there are
if [ $# -gt 1 ] ; then
echo "Usage: $0 or $0 number of players."
exit 1
fi
if [ $# -eq 1 ] ; then
if ! [[ "$1" =~ ^[0-9]+$ ]] ; then
echo "The number of players must be a number, 2 or greater."
exit 1
fi
if [ $1 -lt 2 ] ; then
echo "The number of players must be a number, 2 or greater."
exit 1
fi
totalPlayers=$1
else
totalPlayers=2
cpu=true
fi
initialize_players $totalPlayers
#determine who goes first.
playerIndex=$(rolldice 1d${#player[@]})
while [ $playerIndex -gt 0 ] ; do
score_keeper $playerIndex
let playerIndex++
if [ $playerIndex -gt ${#player[@]} ] ; then
playerIndex=1
fi
done
exit 0