1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
| #!/bin/bash
function Secret (){
#rewrite the secretword's display during playing
lesstmp=""
msk="-"
while [ $i -le {#2} ]
do
lettertest=$(cut -c$i $1)
#to verify if there already is a known letter
if [[ $lettertest = $msk && $2 != $i ]]
then
lesstmp=$($lesstmp + $msk)
elif [ $lettertest != $msk ]
then
lesstmp=$($lesstmp + $lettertest)
else
lesstmp=$($lesstmp + $1)
fi
i=$(($i + 1))
done
$1=$lesstmp
}
function ChooseWord(){
#here the program randomly get a word in a delimited file
num=$((($RANDOM%4)+1))
$1=$(cut -d';' -f$num $2)
}
function Core(){
#this is the core of this wonderfull game of my own ;)
life=10
#number of chances
nba=0
#amount of attends
lesssecret=""
#the secret word which is displayed with known letters
given=""
#the list of given letters
letter=""
#the suggested letter
secretword=""
#this is the word you must find
dictpath="./dictionnary.txt"
#path to the words file
ChooseWord $secretword, $dictpath
while [[ $life > 0 || $lesssecret != $secretword ]]
do
clear
if [ $life -gt 1 ]
then
lifeword="Lifes"
else
lifeword="Life"
fi
if [ $nba -gt 1 ]
then
attendword="Attends"
else
attendword="Attend"
fi
echo "####################################
You have $life $lifeword $attendword = $nba
<< $lesssecret >>
Given letters : $given
You can suggest a new letter : "
echo "####################################"
read $letter
exist=1
p=1
until [ $p > {#secretword} ]
do
if [ $letter = cut -c$p $secretword ]
then
Secret $letter, $p, $lesssecret, $secretword
exist=0
else
pg=1
until [ $pg > {#given} ]
do
if [ $letter = cut -c$gp $given ]
then
echo "Sorry, you already have enter this letter."
exist=0
fi
pg=$(($pg + 1))
done
fi
done
if ! exist
then
echo "Sorry, but this letter is not in the secret word. You lose 1 life"
nba=$(($nba + 1))
life=$(($life - 1))
given=$($given + $letter)
sleep 5
fi
done
if [ $lesssecret = $secretword ]
then
clear
echo "CONGRATULATION !!! The word was > $secretword <"
echo "You done it in $nba $attendword and you still have $life $lifeword."
sleep 10
else
clear
echo "Oooooh... No chance, you suddenly have troubles to swallow... G-gaaargl..."
echo " A strong ageless voice from the sky say you that the word was > $secretword <"
sleep 13
fi
}
clear
cat << display
################################
# Welcome to this Hangman Game #
################################
Would you start a new party (Y/N) ?
display
read ans
for ans in y Y
do
Core
cat << display
################################
# Welcome to this Hangman Game #
################################
Would you play again (Y/N) ?
display
read ans
done
exit |
Partager