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
May 21 '07
17 1664
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
Recognized Expert Contributor
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
Recognized Expert Contributor
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
Recognized Expert Contributor -
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
Recognized Expert Contributor
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
things like:
find all elements of type "<table" that contain as subelements (elements of
type "row" that have attributes of type "lookup" which have value
|
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 short i want to provide input to
a program using some (or all) of the functionality found in bash.
It's mainly the format of the file I'm having trouble with. I wanted to be
able to write something like this:
#!/bin/bash
for x in xs
|
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 easily, and
was wondering if anyone know of a guide to mapping simple uses of
command line programs to python.
For an example, the kind of thing I am thinking of are things like
(yes, this is horrible code).
# These are a run of a program I...
|
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 the normal bash
commands (e.g. print instead of echo). My main reason for asking is that
I like using Python for everything, and if I don't need to learn the
bash 'language', then I won't just yet.
Thanks.
|
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 software is available.....
Thanks for the maintaining the C- Gorup.
| |
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 occurrences of the current user who is executing the script. On finding an occurrence of the username take that line and append it to a file and display a line number and a bracket against the saved line
efforts sofar
#!/bin/bash
echo "filename"
|
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. Unfortunately
it is very slow process so I would like to increase performance and
open one bash/cmd session on the begin of my script and execute
the commands such as in normal system opened bash/cmd window and close
it
|
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 /) and outputs the computed value.
Example:
$ ./perl_calc.pl 12 -13 *
-156
$
However, I don`t know how to turn that operation variable (+, -, * or /) back to an operation only, since when I put in $ARGV $ARGV $ARGV they are all treated either...
|
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
I need to write a program that creates real application/FTP accounts
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |