Hello there guys,
i think i am at the end of this, which i have to edmit has been a huge learning curve for me, but i still have couple of problems, which i was hoping you can help me. I think tbh its a very simple thing which i am over looking and just require a pair of fresh eyes to look at. I greatly appriciate if you could have a look at the script and let me know what you think. if you have any solution, or advise just email me or pm here..
player 1 option scripts:
The problem is when asked if you want to play again, when you say yes, it kicks out of the script after printing the followig line: -
echo " A Random word has been chosen... Enjoy the Game"
-
player 2 option scripts: -
startup
-
-
life=10
-
word=$player2word
-
Thats the only line which is different everything else is the same . The script again kicks out after it has asked you choose a word for player 2 to guess, during replay.
I created 3 function:
1- stored_words: words used for 1-player game.
2- Replay
3- Startup
so to sumerise and stop boring a hell out of you, the problems are:
1- the looping so the players can continue if they decide to play again.
2- combine both scripts into one
K
17 1626 arne 315
Expert 100+
so to sumerise and stop boring a hell out of you, the problems are:
1- the looping so the players can continue if they decide to play again.
The problem is that there is no loop. You just ask for a replay,
if 'y' then you call startup, but all 'startup' does is to print the
line you see :-)
Try to put a loop around your game which exits when the
answer is not 'y'. This should help.
HTH,
arne
The problem is that there is no loop. You just ask for a replay,
if 'y' then you call startup, but all 'startup' does is to print the
line you see :-)
Try to put a loop around your game which exits when the
answer is not 'y'. This should help.
HTH,
arne
tbh i am not sure i understand what you mean.. i thought as startup is a function, it will get called up when its mentioned and should run... and if there is a loop which exist when the answer is not 'y', surely that will just end the game??
am i being really thick here?
K
arne 315
Expert 100+
tbh i am not sure i understand what you mean.. i thought as startup is a function, it will get called up when its mentioned and should run... and if there is a loop which exist when the answer is not 'y', surely that will just end the game??
am i being really thick here?
K
Sorry, if I wasn't clear.
If you call replay in line 101, it will call startup, which will print and return. The program will exit afterwards (which is probably not what you want). Depending on the return code of startup, you should jump back to line 43 in order to repeat the game. This is usually done by a loop.
arne
Sorry, if I wasn't clear.
If you call replay in line 101, it will call startup, which will print and return. The program will exit afterwards (which is probably not what you want). Depending on the return code of startup, you should jump back to line 43 in order to repeat the game. This is usually done by a loop.
arne
I am not sure about how i can find the return code of startup.. but am i correct this is what you mean, instead of having replay at the end of the scrip have: -
-
echo " to play again press 'y' or 'n' to exit"
-
read choice
-
-
while [ $choice == y ] ; do
-
startup
-
else
-
exit 0
-
done
-
-
I am sure my while statement is incorrect, but is that what you meant?
K
arne 315
Expert 100+
I am not sure about how i can find the return code of startup.. but am i correct this is what you mean, instead of having replay at the end of the scrip have: -
-
echo " to play again press 'y' or 'n' to exit"
-
read choice
-
-
while [ $choice == y ] ; do
-
startup
-
else
-
exit 0
-
done
-
-
I am sure my while statement is incorrect, but is that what you meant?
K
No, what I meant was:
Note my changes in lines 57, 70+72 and 192+194. The game is now surrounded by a big loop, which will be left if the player says not 'y'.
arne
Note my changes in lines 57, 70+72 and 192+194. The game is now surrounded by a big loop, which will be left if the player says not 'y'.
arne
wow.. you have tested it? beacuse it only loops around the choose number of players for me?
K
arne 315
Expert 100+
wow.. you have tested it? beacuse it only loops around the choose number of players for me?
K
Yes, I have. Works fine for me. You only have to refine your "random" word (it's always the same right now :) )
Yes, I have. Works fine for me. You only have to refine your "random" word (it's always the same right now :) )
code now is a bit tider i think, but i am having a sever trouble with the line: -
-
if [ $life -eq 0 ]; then
-
echo "THE WORD YOU WERE TRYING TO GUESS WAS \"$word\""
-
choice= replay
-
#startup
-
#replay
-
exit 0
-
fi
-
i have tried all the combination to get it to replay again, but i have no idea why it dosent.. when life become 0 it kicks me out of the game?
Any Idea?
K arne 315
Expert 100+
code now is a bit tider i think, but i am having a sever trouble with the line: -
-
if [ $life -eq 0 ]; then
-
echo "THE WORD YOU WERE TRYING TO GUESS WAS \"$word\""
-
choice= replay
-
#startup
-
#replay
-
exit 0
-
fi
-
I'm not sure I understand: if you call "exit 0;" somehwere in the program it will exit immediately. Instead of calling exit, you should jump back to the beginning of the loop if choce is 'y'. Use the "continue" command, for instance.
HTH,
arne
I'm not sure I understand: if you call "exit 0;" somehwere in the program it will exit immediately. Instead of calling exit, you should jump back to the beginning of the loop if choce is 'y'. Use the "continue" command, for instance.
HTH,
arne
I used continue, what it will do is contiune the script even when life is = 0
I am not even sure what i need to do next, as i have tried everything i know now.
K
arne 315
Expert 100+
I used continue, what it will do is contiune the script even when life is = 0
I am not even sure what i need to do next, as i have tried everything i know now.
K
-
if [ $life -eq 0 ]; then
-
echo "THE WORD YOU WERE TRYING TO GUESS WAS \"$word\""
-
replay
-
continue
-
fi
-
will continue the loop. Make sure to reset 'life' to 10, to clear the template and to choose another word.
HTH,
arne
-
if [ $life -eq 0 ]; then
-
echo "THE WORD YOU WERE TRYING TO GUESS WAS \"$word\""
-
replay
-
continue
-
fi
-
will continue the loop. Make sure to reset 'life' to 10, to clear the template and to choose another word.
HTH,
arne
I have managed to set the life counter to 10, by creating a function and calling it when i need to. The only problem now is that not sure why it keeps on calling the same word over and over again when 1 player option is chosen. is there a way to clear the template?
K
arne 315
Expert 100+
I have managed to set the life counter to 10, by creating a function and calling it when i need to. The only problem now is that not sure why it keeps on calling the same word over and over again when 1 player option is chosen. is there a way to clear the template?
K
What about defining a function that will select a new word randomly and set the template accordingly?
arne
What about defining a function that will select a new word randomly and set the template accordingly?
arne
-
stored_word()
-
{
-
case $(( $$ % 10 )) in
-
0 ) echo "energy" ;; 1 ) echo "touch" ;;
-
2 ) echo "climbing" ;; 3 ) echo "declare" ;;
-
4 ) echo "marry" ;; 5 ) echo "relax" ;;
-
6 ) echo "bugs" ;; 7 ) echo "inaccessible" ;;
-
8 ) echo "country" ;; 9 ) echo "folder"
-
esac
-
}
-
-
thats what the first funtion dose. I think the main problem is that once the $word is set, it remains the same through out the cycle of the program and only once you exit the game it resets to zero.
have i misunderstood you?
K
arne 315
Expert 100+ -
stored_word()
-
{
-
case $(( $$ % 10 )) in
-
0 ) echo "energy" ;; 1 ) echo "touch" ;;
-
2 ) echo "climbing" ;; 3 ) echo "declare" ;;
-
4 ) echo "marry" ;; 5 ) echo "relax" ;;
-
6 ) echo "bugs" ;; 7 ) echo "inaccessible" ;;
-
8 ) echo "country" ;; 9 ) echo "folder"
-
esac
-
}
-
-
thats what the first funtion dose. I think the main problem is that once the $word is set, it remains the same through out the cycle of the program and only once you exit the game it resets to zero.
have i misunderstood you?
K
Yes, but this function (or another one) may also set the template, since if you run out of lifes and you want to play again, your program will reuse the template with the already guessed letters in it ...
arne
Yes, but this function (or another one) may also set the template, since if you run out of lifes and you want to play again, your program will reuse the template with the already guessed letters in it ...
arne
Ok i am officially raising my hand and putting a sign up saying i am too stupid and thick.. sorry :( i dont understand
K
arne 315
Expert 100+
Ok i am officially raising my hand and putting a sign up saying i am too stupid and thick.. sorry :( i dont understand
K
Ok, the problem is that the continue jumps to the beginning of the inner loop. What we want is to jump to the beginning of the outer loop. So, try -
flag=0
-
if [ $life -eq 0 ]; then
-
-
echo "THE WORD YOU WERE TRYING TO GUESS WAS \"$word\""
-
-
replay
-
flag=1
-
break
-
fi
-
and -
if [ $flag -eq 1 ]; then
-
continue;
-
fi
-
-
echo -n "Congratulations! You guessed \"$word\" in \"$guesses\" guesses"
-
I added some context so that you can see where to insert the changes.
BTW, try this stored_word function. If you use $$, i.e. the process PID, you will always choose the ssame word for a second game -
stored_word()
-
{
-
number=$RANDOM
-
let "number %= 10"
-
case $number in
-
0 ) echo "energy" ;; 1 ) echo "touch" ;;
-
2 ) echo "climbing" ;; 3 ) echo "declare" ;;
-
4 ) echo "marry" ;; 5 ) echo "relax" ;;
-
6 ) echo "bugs" ;; 7 ) echo "inaccessible" ;;
-
8 ) echo "country" ;; 9 ) echo "folder"
-
esac
-
}
-
HTH,
arne
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Jeff Kish |
last post by:
Greetings.
I can't invest a large amount of time into this, but it would be very helpful
if I could do this.
I have a directory full of xml files I'd like to be able to query to find out...
|
by: Magnus Jonneryd |
last post by:
Hi, I'm planning on writing a program that interactively is fed input via a
shell (bash). I also want to be able to write a shell script that executes
various commands related to my program. In...
|
by: 4zumanga |
last post by:
I have a bunch of really horrible hacked-up bash scripts which I would
really like to convert to python, so I can extend and neaten them.
However, I'm having some trouble mapping some constructs...
|
by: John Salerno |
last post by:
Hi all. I just installed Ubuntu and I'm learning how to use the bash
shell. Aside from the normal commands you can use, I was wondering if
it's possible to use Python from the terminal instead of...
|
by: sri |
last post by:
Hi
I am new to C language. Still I am using Turbo C++ 3 Compiler. Any
New version is available for Windows XP platforms. Borland releases C++
5.5 Command line tools.
Is There any New C Compiler...
|
by: gham |
last post by:
I am a complete noob to linux and shell scripting please help
this is what I am trying to do
1. Create a script that takes 1 argument being a file, read the inputted file, and look for...
|
by: melmack3 |
last post by:
Hello
My PHP script executes many bash/cmd commands.
Functions like "exec()" or "system()" cause that new bash/cmd session
is started,
the command is executed and the session is closed....
|
by: hgdien |
last post by:
I am a complete newbie at Perl. I have just started getting from bash to Perl language. I am trying to do a simple perl scripting that takes three arguments: two integers and an operation (+, -, * or...
|
by: Frantisek Malina |
last post by:
What is the best way to do the regular bash commands in native python?
- create directory
- create file
- make a symlink
- copy a file to another directory
- move a file
- set permissions
...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |