package battleship;
public class BattleShip {
public static void main(String[] args)
{
Addons a = new Addons();
Board b = new Board();
Computer c = new Computer();
Human h = new Human();
LinkedList list = new LinkedList();
while(a.intro())
{
a.sleep(1);
a.countDown(5);
b.prepareBoard();
do
{
h.play(b.getBoard());
a.checkWinner(b.getBoard());
System.out.println("How the Board stands.");
a.printBoard(b.getBoard());
a.sleep(3);
c.play(b.getBoard());
a.checkWinner(b.getBoard());
System.out.println("How the Board stands.");
a.printBoard(b.getBoard());
}while(b.nextRound() && a.checkWinner(b.getBoard()));
list.printLinkedList();
}
}
}
public boolean intro()
{
Sound s = new Sound();
String input= " ";
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"
+" \n"
+" Welcome \n"
+" to \n"
+" BattleShip \n"
+" \n"
+"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
System.out.println("This game is a turn based strategy game that\n"
+"the basic need is to sink the enemy ships before\n"
+"the enemy sinks yours, you have to input x and\n"
+"y coordinates within the range. On the enemy side\n"
+"~ means misses and * means hits. Happy Hunting!\n\n");
s.playIntro();
do
{
input = JOptionPane.showInputDialog("Do you want to play? Y or N?").toUpperCase();
switch(input)
{
case "Y":
return true;
case "N":
return false;
default:
break;
}
}while(input != "N" || input != "Y");
return false;
}
public void playIntro()
{
AudioStream bGM;
try{
bGM = new AudioStream(new FileInputStream("intro.wav"));
AudioPlayer.player.start(bGM);
} catch (IOException error)
{
System.out.println("File not Found: " + error);
}
}
Ok I put sound in my program, everything is working fine, but if I exit the program by placing N in the dialog box in intro(); the music continues playing and the program does not exit. Any suggestions?