I just have a couple of quick questions.
I am having trouble with this cut. I am basically trying to cut the string so that i can insert the users guess at the appropriate point in the string.
$letters is the character count of the $word.
What it seems to do is cut the character into the string but then extend the original mask instead of replacing it entirely.
Will i have to add an extra piece that allows me to cut from the first character in the string if that is where the guessed letter is?
Or is there a slightly easier bit of code that I am overlooking.
Thanks in advance.
P.S. I am very new to coding so it probably isnt the simplest way to do it, but I dont want to redo the whole function with syntax im not entirely sure of.
function replaceLetter()
{
for ((x=0;x<="$letters"; x++))
do
wordLetter=$(echo $word | cut -c$x)
if [ "$guess" = "$wordLetter" ]
then
newMask=$maskWord
maskWordTemp1=$(echo $newMask | cut -c-$x)
maskWordTemp2=$guess
maskWordTemp3=$(echo $newMask | cut -c$x-)
maskWordTemp=$maskWordTemp1$maskWordTemp2$maskWordTemp3
maskWord=$maskWordTemp
echo "Correct $guess is in the word"
correct=true
fi
done
if [ ! correct ]
then
lives=$(($lives - 1))
correct=false
fi
alreadyGuessed+="$(echo $guess | sort -u)"