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 1662 arne 315
Recognized Expert Contributor
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
Recognized Expert Contributor
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
Recognized Expert Contributor
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
Recognized Expert Contributor
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
Recognized Expert Contributor
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
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: 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: 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: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |