with this code the problem is that in
1st loop guessed was e
display that -e----
2nd loop when guessed was d
display that --d---
and the desire sesult was -ed----
any idea???
This is nog my experience:
This is what happens when I run the code:
Quote:
---------- Post updated at 08:28 PM ---------- Previous update was at 08:18 PM ----------
can you explain me this 2 lines what are you doing?
using this code if [ -n "$char" ] any char press the lifes decrease we want to decrease when the guessed is wrong any idea
and why use this guessed="$guessed$char"
can i ignore this line guessed="$guessed$char"
and last line wrote this echo $word|sed "s/[^$char]/-/g"
Sure it is. I did not want to spoil your fun by writing all the code for you. I just tried to show a basic mechanism. The
means the if it is non-zero then decrease lives this is so that if a user enters enter by accident without a character lives does not decrease. You could replace that statement with a test to see if the character is part of $word and bob is your uncle.
Quote:
why use 2 (( here $((lives -1)) and why $ is out;
The $(( ... )) construct is used for calculations. Inside the double parentheses you can use variables without the $-sign (you can still use it if you wish. The $(( ... )) is a more modern construct. I hardly use the oldfashioned expr statement anymore.
Quote:
sorry for my question but i want to learn i think stupid to write somenthing don't understanding maybe i need to use many of commands in the future
Don't be sorry that is what this forum is for . It is excellent that you really want to understand the code..
Quote:
In Addition the decrease must doing when i press wrong guess
---------- Post updated at 10:31 PM ---------- Previous update was at 08:28 PM ----------
one though is to split the word to a table an with for i check if char is not included to table decrease the lifes
for example in c language i can write this
for (i=1;i<=sizeof(tablep);i++)
{
if (char != tablep[i])
lives--;
}
does anyone how to make it with bash
You can use a case ... esac statement to do that or use [[ ... ]] and pattern matching with asterisks or use the pattern matching operator ~= There are many ways... Good luck.
S.
Last edited by Scrutinizer; 12-17-2009 at 03:53 AM..
in this code it is necessary to create table for example
---------- Post updated at 07:24 AM ---------- Previous update was at 05:48 AM ----------
just found the solution i use one var as boolean false or true
if i found in table the character i make the var true and after finidh the loop decrease lifes
Hello everyone, im just having some problem forming a script for a hangman script. The question states:
The object this excercise is for u to write a script that emulate the classic game hangman. The object of this game is for a user to try and guess a word which has been generated by the... (1 Reply)