I am at my ends wit now and truley utterly lost, so any help would go a long way to stop my pulling my wife's hair out ( i ran out of my own hair a long time ago :)
The game has to have the option for 1 player or 2 player, which needs to be stated at the started, when the script is run. This is what i have done to remedy this option:
Expand|Select|Wrap|Line Numbers
- #!/bin/bash
- echo "Choose number of Players:"
- read players
- if [ $players -eq 1 ]
- then
- echo "The script for thsi hasnt been written."
- elif [ $players -eq 2 ]
- then
- echo "choose a word for player two to guess:"
- read player2word
- else
- echo "incorrect option.. choose again"
- fi
If a 1 player option is choosen, then the following which i havent even coded should happen:
1- A random word from a different file needs to be chosen.
2- The player should be told the word has been chosen and the display should be - - - - (number of dashes should be = to length of word.
3- player is prompted to guess a letter. If a correct letter is chosen then display the message: You have chosen <letter>, then echo the letter and place the chosen letter in correct field.
now 2 player is same as above except that player 1 has to input the word for player 2 to guess. So far i have done this:
Expand|Select|Wrap|Line Numbers
- life=10
- blank="......................"
- word=$player2word
- letters=$(echo $word | wc -c)
- letters=$(( $letters - 1 ))
- template="$(echo $blank | cut -c1-$letters)"
- remaining=$letters
- guessed=""
- guesses=0
- badguesses=0
- echo " ************** The word you are trying to guess has $letters letters **************"
- echo ""
- echo ""
- while [ $remaining != $word ] ; do
- echo -n "Word is: $template Please choose a Letter: " ;
- read guess
- guesses=$(( $guesses + 1 ))
- echo " you have chosen $guess"
- if echo $guessed | grep -i $guess > .temp1 ; then
- echo "You've already guessed that letter. Try again!"
- elif ! echo $word | grep -i $guess > .temp1 ; then
- echo "Sorry, the letter \"$guess\" is not in the word."
- guessed="$guessed$guess"
- badguess=$(( $badguess + 1))
- life=$(( $life -1 ))
- echo " you have $life left"
- else
- echo "Good going! The letter $guess is in the word!"
- echo $letter
- fi
- done
- echo -n "Congratulations! You guessed $word in $guesses guesses"
- echo " with $badguesses bad guesses"
1- Not finished
2- when a letter is chosen the script excepts the fact its a correct or an incorrect letter but dosent insert it into ..... location.
3- i am sure there is more, best thing i can suggest if you can run it and see the result then you will have a better understading of it.
I know this is a tall order, but any help would be greatly appriciated and in my part main thing is to learn and understand from all you guys out there who have far more knowledge than me in shell scripting.
thank you
K