-
few questions..
hey everyone first post..i'm relatively new at c++ and i'm in my first semester of it. Anyways my teacher assigned us a program
to make the game battleship. I have two questions.
when a ship is hit, you have to display a stupid graphic such as
"HIT" or something like that...i know that "\a" makes a beep noise...but are there other noises you can make? and if so what are they?
also..when this "HIT" screen shows up, is there someway i can simply delay it? Say the person gets a hit, and it displays HIT, and simply clears the screen on its own in a say 2 second? Normally, i would use a system("pause"), and a system("cls"), but i don't want the user to have to hit enter after it EVERY time they get a hit...
so any help would be appreciated..thanks!
BODYBUILDNERD
-
Include dos.h.
There if a function called delay();
delay(numberofmilliseconds);
Also found in that file is a function called sleep();
sleep(numberofmilliseconds);
Another function found in dos.h is sound();
sound(frequencyinhertz);
To make the noise stop use nosound();
nosound(void);
so:
Code:
sound(150);//starts sound
delay(3000);//waits 3 seconds
nousound();//Stops sound
Hope this helps.
~BC17
P.S.
I use Borland Turbo C++ Ver 3.0 Dunno if it will work with others or not.
-
i tried it..brought up error man..am i doing it wrong??
put #include "dos.h" at the top..
then before or after my graphic do i put..
sound(150);//starts sound
delay(3000);//waits 3 seconds
nousound();//Stops sound
that basically will play sound for 3 seconds then stop correct?
We use Visual Studio.net so its lil different than yours i'm sure..
umm any other hints..??
-
Visual Studio neither builds nor has support for DOS-Applications. You are probably building a console application. Please have a look at the FAQ how to output Colors in a console. Consoles cannot output graphics, you will have to use colored text.
The DOS stuff above will not work for console applications.
The funtion that delays is called Sleep ( notice the capital S ) in Visual Studio.
-
thanks man, is there a library i need to include to you Sleep??
if so let me know...thanks...
also where do i find the FAQ about colors in consoles?
thanks!
BBNERD
-
>is there a library i need to include to you Sleep??
#include <windows.h>
>also where do i find the FAQ about colors in consoles?
This may help some.
-Prelude
-
i guess coloring text is over my head :-/
Dunno...guess i'll stick w/ the plain black and white...
BBNERD
-
BBNerd, let me guess are you in Fulton's 168 course:)
Van
-
-
Wassup Josh!! How goes the program? I haven't really started mine yet. Also what did I miss in class, I had to help my parents move into there new house. Also I am working on finding out how to do color in the console so that we can add color to our stuff when we make a hit.
Van
-
sound(150);//starts sound
delay(3000);//waits 3 seconds
nousound();//Stops sound
that is the code you wrote, look at the last line. You have an extra 'u' in there. That will give you an error if that is actually in your code and not just a little typo.