/*
MP5  Hunt the Wumpus

*
 *Wump.java and Wumpus.java are copyright 2018 SoftWarr
 *24887Tenn Oaks Road
 *Hockley, TX 77447
*/
	
import javax.swing.*;					
import java.util.*;								
import static java.lang.System.*;
import static java.lang.Math.*;
import java.applet.*;
import java.net.*;
import java.awt.*;								
import java.awt.event.*;								
import java.io.*;   //for files						
public class Wump 
{
	public static void main(String args[])
	{
        new Wumpus();  //Anonymous object to execute the game
    }
  
}

class Wumpus extends Frame   implements KeyListener, MouseListener, ActionListener
{
        //declare variables global
//private final static int SCHEIGHT=1000,SCWIDTH=1400;
// direction constants
	final static int N = 0,NE = 1,E = 2,SE = 3, S = 4, SW = 5, W = 6, NW =7,STILL = 8;
// movement change constants
	final  int X = 0,Y = 1,Z = 2;
	final int TITLE = 30, STATUS = 40;
	final static int size = 2;
   //instance variables
    private Button btnEast = new Button("E");
    private Button btnWest = new Button("W");
    private Button btnNorth = new Button("North");
    private Button btnSouth = new Button("South");
    private Button btnList = new Button("Rooms visited");
    private boolean gameNotOver = true;
    private Image myScreen,arrowNorth,arrowEast, arrowSouth,arrowWest,spellPic,spellPicNS,spellPicNum;
    private int aDirection = -1,sDirection = -1;
    private int currentRoom = 0;
    private ArrayList <CaveRoom> cave;
    private ArrayList <CaveRoom> visited = new ArrayList<CaveRoom>();
    private int doorChoice = -1;
    private boolean keyPressed = false;
    private boolean killedHazard = false,shotNorth=false,shotEast=false,shotSouth=false,shotWest=false;
    private int whichScreen = 0,numScreen = 0,lastRoom = 0;
    private int scWidth, scHeight; 
	private AudioClip steps,swoosh;
	private Player player;
	private String arrowDirection=" ";
	public Wumpus()
	{       
	    try {
	           steps = Applet.newAudioClip(new URL("file:CLAP.WAV"));
	           swoosh = Applet.newAudioClip(new URL("file:LOWTWNG8.WAV"));
	        }    
	    catch (MalformedURLException e) 
	        {
	    	      System.out.println("error" + e);
	        }
	    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
	    arrowNorth = Toolkit.getDefaultToolkit().getImage("ArrowNorth.png");
	    arrowEast = Toolkit.getDefaultToolkit().getImage("ArrowEast.png");
	    arrowSouth = Toolkit.getDefaultToolkit().getImage("ArrowSouth.png");
	    arrowWest = Toolkit.getDefaultToolkit().getImage("ArrowWest.png");
	    spellPic = Toolkit.getDefaultToolkit().getImage("SpellPic.png");
	    spellPicNS = Toolkit.getDefaultToolkit().getImage("SpellPicNS.png");
	    spellPicNum = Toolkit.getDefaultToolkit().getImage("SpellPicNum.png");
	    scWidth = (int)screenSize.getWidth();
	    scHeight = (int)screenSize.getHeight()-40;
	    setBounds(0,0,scWidth,scHeight);
	    addWindowListener(new WindowAdapter()
	          {
	              public void windowClosing(WindowEvent e)
	                {
	                  System.exit(0);
	                }
	           });
       // Opening screen
	   player = new Player(0, 1000, 6, 4, 100,"Steve","p1.PNG");
       String name = player.getName();
//       JOptionPane.showInputDialog("Welcome to \"Hunt the Wumpus\"\n" +
//                                                   "         Enter your name.");
       String imageName = player.getPictureName();
//       JOptionPane.showInputDialog(
//       "Enter file name for a picture Or press enter.");
	   setTitle("Hunt the Wumpus  -- " + name + ".     Please wait for images to load"); 
//       player = new Player(name,imageName);
	   setLayout(new BorderLayout()); 
	   add (btnList,BorderLayout.NORTH);
	   add (btnNorth,BorderLayout.NORTH);
	   add (btnSouth,BorderLayout.SOUTH);
	   add (btnEast,BorderLayout.EAST);
	   add (btnWest,BorderLayout.WEST);
	   btnNorth.addKeyListener(this);    
	   btnSouth.addKeyListener(this);    
	   btnList.addKeyListener(this);    
	   btnEast.addKeyListener(this);    
	   btnWest.addKeyListener(this);    
	   btnList.addActionListener(this);    
	   btnNorth.addActionListener(this);    
	   btnSouth.addActionListener(this);    
	   btnEast.addActionListener(this);    
	   btnWest.addActionListener(this);    
	   cave = new ArrayList<CaveRoom>(); 
	  // cave.add(new CaveRoom());       
	   cave.add (new CaveRoom(" 0  Entrance -- This is a huge black opening.",-1,1,6,-1,"RoomB24.jpg")); //0
	   cave.add (new CaveRoom(" 1  Eerie passagway",4,2,14,7,"RoomC01.jpg")); //1
	   
	   cave.add (new CaveRoom(new Monster("PIT",3,"","pitSound")," 2  I don't know.",-1,3,8,1,"RoomC02.jpg"));  //2
	   cave.add (new CaveRoom(" 3  dark",-1,4,9,-1,"RoomC03.jpg"));    //3
	   cave.add (new CaveRoom(" 4  Empty",1,5,9,3,"RoomC04.jpg"));  //4
	   cave.add (new CaveRoom(" 5  You can see very little.",4,-1,-1,-1,"RoomC05.jpg"));  //5
	   cave.add (new CaveRoom(" 6  Much fun here!",-1,7,12,0,"RoomK11.jpg"));  //6
	   cave.add (new CaveRoom(" 7  What's hiding here?",-1,8,13,6,"RoomC07.jpg"));  //7
	   cave.add (new CaveRoom(" 8  pathway",-1,9,-1,7,"RoomC08.jpg"));  //8
	   cave.add (new CaveRoom(new Monster("BAT",1,"Stuff.jpg","Sound.wav")," 9  guano Room",8,-1,15,-1,"RoomC09.jpg")); //9
	   cave.add (new CaveRoom("10  Forest ",-1,11,-1,9,"RoomC10.jpg"));  //10
	   cave.add (new CaveRoom(new Monster ("Wumpus",2,"TheBoss.png","HEEHEE.WAV"),"11  A grassy plain",5,6,17,10,"RoomB11.jpg"));  //11
	   cave.add (new CaveRoom(new Monster("batty",1,"Stuff.jpg","Sound.wav"),"12  Zetumba Lair. Be careful.",-1,1,18,6,"RoomB12.jpg")); //12
	   cave.add (new CaveRoom("13  Eerie passagway",7,-1,19,12,"RoomC13.jpg")); //13
	   
	   cave.add (new CaveRoom("14  Oh yeah!",8,15,12,-1,"RoomK02.jpg"));  //14
	   cave.add (new CaveRoom("15  dark",9,16,-1,14,"RoomB15.jpg"));    //15
	   cave.add (new CaveRoom("16  Empty",11,17,21,-1,"RoomB16.jpg"));  //16
	   cave.add (new CaveRoom("17  The way out?",11,0,22,16,"RoomB17.jpg"));  //17
	   cave.add (new CaveRoom(new Monster("bat",1,"Stuff.jpg","Sound.wav"),"18  Unknown area",-1,-1,20,-1,"RoomB18.jpg"));  //18
	   cave.add (new CaveRoom("19  Watch out!",12,20,20,-1,"RoomB19.jpg"));  //19
	   cave.add (new CaveRoom("20  Nothing good.",14,21,19,18,"RoomB20.jpg"));  //20
	   cave.add (new CaveRoom("21  Where's the toolshed",20,15,22,-1,"RoomB21.jpg"));  //21
	   cave.add (new CaveRoom(new Monster("PIT",3,"","pitSound"),"22  School?",17,23,5,0,"RoomB22.jpg"));  //22
	   cave.add (new CaveRoom("23  Where am I?",0,-1,-1,-1,"RoomB23.jpg"));  //23
	   this.addKeyListener(this);
	   this.setVisible(true);
	   gameLoop();
	}
	public void gameLoop()
	{   
	   do   
	
	     {
	        //if a key is pressed assign current room the value of the door chosen (N = 0
	        //cave is an ArrayList of rooms
	        //door is an ArrayList of doors in a room 
	        //doorChoice is 0..4 
	        //out.println(keyPressed + " current " + currentRoom +" door: " + doorChoice);
	        if (keyPressed)
	           {
	             //out.println(keyPressed + " choice " + doorChoice + " current: " + currentRoom );//+ "  heading: " + cave.get(currentRoom).getDoorHeading(doorChoice));
	             //pause(100);
	             sDirection = -1;
	             aDirection = -1;
	             if (doorChoice >=0 && doorChoice < 4)
	                  {
	                      visited.add(cave.get(currentRoom));
	                      if (cave.get(currentRoom).getDoorHeading(doorChoice) >= 0)
	                         {
	                      		lastRoom = currentRoom;
	                      		currentRoom = cave.get(currentRoom).getDoorHeading(doorChoice);
	                      	 }	
	                  }    
	             else      	      
	                 if (doorChoice == 4 && player.getSpells()>0)  //Cast  a spell
	                       {
	       	                      int a = 0;
	       	                      String arrow = "You can cast:";  
	       	                      for (Integer i:cave.get(currentRoom).getDoors())
	       	                           {
	       	                           	   if (a==0 && i >=0)
	       	                           	       arrow += "\nNorth";
	       	                           	   if (a==1 && i >=0)
	       	                           	       arrow += "\nEast";
	       	                           	   if (a==2 && i >=0)
	       	                           	       arrow += "\nSouth";
	       	                           	   if (a==3 && i >=0)
	       	                           	       arrow += "\nWest";
	       	                           	   a++;    
	       	                           }
	       	                        Object []nesw = {"N","E","S","W"};   	   
                                    sDirection = JOptionPane.showOptionDialog(this,
	       	                      	          (Object)(arrow +"\nWhich do you choose?"),
	       	                      	          "Which Direction?",0,0,
	       	                      	          new ImageIcon("SpellPicNum.png")
	       	                      	          ,nesw,
	       	                      	          nesw[0]);
	       	                      	if (sDirection==0)
	       	                      	     shotNorth = true;        
	       	                      	if (sDirection==1)
	       	                      	     shotEast = true;        
	       	                      	if (sDirection==2)
	       	                      	     shotSouth = true;        
	       	                      	if (sDirection==3)
	       	                      	     shotWest = true; 
	       	                      	arrowDirection = " ";
				                    if (sDirection >= 0)
				                        swoosh.play();
					                 player.setSpells(player.getSpells()-1); 
	       	             }            
	             else      	      
	                 if (doorChoice == 5 && player.getArrows()>0)  //Shoot an arrow
	                       {
	       	                      int a = 0;
	       	                      String arrow = "You can shoot:";  
	       	                      for (Integer i:cave.get(currentRoom).getDoors())
	       	                           {
	       	                           	   if (a==0 && i >=0)
	       	                           	       arrow += "\nNorth";
	       	                           	   if (a==1 && i >=0)
	       	                           	       arrow += "\nEast";
	       	                           	   if (a==2 && i >=0)
	       	                           	       arrow += "\nSouth";
	       	                           	   if (a==3 && i >=0)
	       	                           	       arrow += "\nWest";
	       	                           	   a++;    
	       	                           }
	       	                        Object []nesw = {"N","E","S","W"};   	   
// Icon icon, Object[] selectionValues, Object initialSelectionValue)
                                      	       	                        
                                    aDirection = JOptionPane.showOptionDialog(this,
	       	                      	          (Object)(arrow +"\nWhich do you choose?"),
	       	                      	          "Which Direction?",0,0,
	       	                      	          new ImageIcon("arrowNorth.png")
	       	                      	          ,nesw,
	       	                      	          nesw[0]);
	       	                      	if (aDirection==0)
	       	                      	     shotNorth = true;        
	       	                      	if (aDirection==1)
	       	                      	     shotEast = true;        
	       	                      	if (aDirection==2)
	       	                      	     shotSouth = true;        
	       	                      	if (aDirection==3)
	       	                      	     shotWest = true; 
	       	                      	arrowDirection = " ";
				                    if (aDirection >= 0)
				                        swoosh.play();
					                 player.setArrows(player.getArrows()-1); 
	       	             }            
	             //out.println(doorChoice + " current " + currentRoom);
			   	 if (player.getHealth() < 0)
			   	     gameNotOver = false;
	             
	             this.repaint();
	             keyPressed = false;
	           }  
	        pause(30);
	     }
	   while (gameNotOver);
	   this.repaint();     
	}
	public void paint(Graphics pen)
	 {    
	        if (whichScreen <2 )               
	           {
	              pen.drawImage(cave.get(currentRoom).getRoomPic(),0,0,scWidth,scHeight,this);
		          pen.setColor(Color.yellow);
		          pen.setColor(Color.black);
	              for(int x = 0; x < cave.size(); x++)
	                 {
	                     pen.drawImage(cave.get(currentRoom).getRoomPic(),0,0,scWidth,scHeight,this);
	                     pen.drawImage(cave.get(x).getRoomPic(),-2000,0,scWidth,scHeight,this);
			             // pen.fillRect(0,0,scWidth,scHeight);
	                    
	//              pause (5000);
						  pen.setColor(Color.blue);
			              pen.fillRect(500,290,600,300);
					      pen.setFont(new Font("Timesroman",Font.ITALIC,50));
				          pen.setColor(Color.yellow);
					      pen.drawString("Hunt the Wumpus ",600,350);
					      pen.drawString("Opening Screen",600,450);
					      pen.drawString("Please Wait",650,550);
		                  pen.drawImage(player.getPicture(),-500,100,this);
			             pause(100);
		              }    
	              pause (1000);
	              numScreen ++;
	              if (numScreen > 0)
	                 {
	                     whichScreen ++;
	                 }
	              pen.drawImage(cave.get(currentRoom).getRoomPic(),0,0,scWidth,scHeight,this);
	           }
	        else
	        if (gameNotOver)
	           {
			        setTitle("Hunt the Wumpus  -- COL Warr.");
	               // pen.drawImage(cave.get(lastRoom).getRoomPic(),0,0,scWidth,scHeight,this);
		           // out.println(sDirection + "spell");
		            int targetRoom = -1;
		            if(sDirection >=0)
				         targetRoom = cave.get(currentRoom).getDoors().get(sDirection);
		            if(aDirection >=0)
				         targetRoom = cave.get(currentRoom).getDoors().get(aDirection);
                    for (int c = 0; c<15;c++)
                        {
		out.println("targetRoom " + targetRoom + " c " +c + " aD "+ aDirection);
			             if (targetRoom >= 0 && sDirection >= 0)
			               	  {       
		                            if(sDirection == 0)
					                    pen.drawImage(spellPicNS,scWidth/2 -50,scHeight/2 - c*30 -25,this);
		                            if(sDirection == 1)
					                    pen.drawImage(spellPic,scWidth/2 +c*50,300,this);
		                            if(sDirection == 2)
					                    pen.drawImage(spellPicNS,scWidth/2 -50 ,scHeight/2 + c*25,this);
		                            if(sDirection == 3)
					                    pen.drawImage(spellPic,scWidth/2 -100 -c*50,300,this);
					                if( cave.get(targetRoom).getMonster().getType()==1)//bat
					                   {
					                   	 cave.get(targetRoom).getMonster().setType(0);
					                   	 if(random() <.7)
					                   	    {
							                   	 cave.get((int)(random()*cave.size())).setMonster(
							                   	 	   new Monster("bat",1,"Stuff.jpg","Sound.wav"));
							                   	 JOptionPane.showMessageDialog(null,
							                   	 	   "Your spell chased the bat to another room.  10 points");
							                     player.addScore(10);
					                        }
					                      else
					                        {
							                   	 JOptionPane.showMessageDialog(null,
							                   	 	   "Your spell eliminated the bat.  20 points");
							                     player.addScore(20);
							                }     
					                   }  
					                if( cave.get(targetRoom).getMonster().getType()==2)//Wumpus

					                   {
					                   	 cave.get(targetRoom).getMonster().setType(0);
					                   	 if(random() <.3)
					                   	    {
							                   	 cave.get((int)(random()*cave.size())).setMonster(
							                   	 	   new Monster("Wumpus",2,"Stuff.jpg","Sound.wav"));
							                   	 JOptionPane.showMessageDialog(null,
							                   	 	   "Your spell scared the Wumpus to another room.  30 points");
							                     player.addScore(30);
					                        }
					                      else
					                        {
							                   	 JOptionPane.showMessageDialog(null,
							                   	 	   "Your spell eliminated the Wumpus.  50 points");
							                     player.addScore(50);
							                }     
							                     
					                   } 
					                 out.println("spells " + player.getSpells());
					                 pause (200);   
                                     pen.drawImage(cave.get(currentRoom).getRoomPic(),0,0,scWidth,scHeight,this);
				               }
				          else          
			             if (targetRoom >= 0 && aDirection >= 0)
			               	  {       
		                            if(aDirection == 0)
					                    pen.drawImage(arrowNorth,scWidth/2 -50,scHeight/2 - c*30 -25,this);
		                            if(aDirection == 1)
					                    pen.drawImage(arrowEast,scWidth/2 +c*50,300,this);
		                            if(aDirection == 2)
					                    pen.drawImage(arrowSouth,scWidth/2 -50 ,scHeight/2 + c*25,this);
		                            if(aDirection == 3)
					                    pen.drawImage(arrowWest,scWidth/2 -100 -c*50,300,this);
					               // int targetRoom = cave.get(currentRoom).getDoors().get(aDirection);
					                out.println("shot arrow " + targetRoom + " aDirection " + aDirection + " " +
					                        cave.get(targetRoom).getMonster().getType() );
					                if( cave.get(targetRoom).getMonster().getType()==1)//bat
					                   {
					                   	 if(random() <.7)
					                   	    {
							                   	 cave.get((int)(random()*cave.size())).setMonster(
							                   	 	   new Monster(cave.get(targetRoom).getMonster()));//uses copy constructor
							                   	 JOptionPane.showMessageDialog(null,
							                   	 	   "Your arrow chased the bat to another room.  10 points");
							                     player.addScore(10);
					                        }
					                      else
					                        {
							                   	 JOptionPane.showMessageDialog(null,
							                   	 	   "Your arrow eliminated the bat.  20 points");
							                     player.addScore(20);
							                }     
					                   	 cave.get(targetRoom).getMonster().setType(0);
					                   }  
					                if( cave.get(targetRoom).getMonster().getType()==2)//Wumpus

					                   {
					                   	 if(random() <.3)
					                   	    {
							                   	 cave.get((int)(random()*cave.size())).setMonster(
							                   	 	   new Monster(cave.get(targetRoom).getMonster()));//uses copy constructor
							                   	 JOptionPane.showMessageDialog(null,
							                   	 	   "Your arrow chased the Wumpus to another room.  30 points");
							                     player.addScore(30);
					                        }
					                      else
					                        {
							                   	 JOptionPane.showMessageDialog(null,
							                   	 	   "Your arrow eliminated the Wumpus.  50 points");
							                     player.addScore(50);
							                }     
					                   	  cave.get(targetRoom).getMonster().setType(0);
					                   } 
					         //        out.println("Arrows " + player.getArrows() +" " + c);
					                 pause (200);   
                                     pen.drawImage(cave.get(currentRoom).getRoomPic(),0,0,scWidth,scHeight,this);
				               }
				          else          
                          if (doorChoice != -1)
                             {	
								steps.play();
	                            if(doorChoice == 0)
	                              {
				                    pen.fillOval(scWidth/2 -50,scHeight/3 - (c*25),100,100);
				                    pen.drawImage(player.getPicture(),scWidth/2 -50,scHeight/3 - c*30 -25,this);
				                   } 
	                            if(doorChoice == 1)
	                               {
				                    pen.fillOval(scWidth/3*2 +c*50,300+30,100,100);
				                    pen.drawImage(player.getPicture(),scWidth/3*2 +c*50,300,this);
				                   } 
	                            if(doorChoice == 2)
	                               {
				                    pen.fillOval(scWidth/2 -50 ,scHeight/3*2 + c*25+30,100,100);
				                    pen.drawImage(player.getPicture(),scWidth/2 -50 ,scHeight/3*2 + c*25,this);
				                   } 
	                            if(doorChoice == 3)
	                               {
	                               	
				                    pen.fillOval(scWidth/3 -100 -c*50,300+30,100,100);
				                    pen.drawImage(player.getPicture(),scWidth/3 -100 -c*50,300,this);
				                   }
			                     pause(200);
	                             pen.drawImage(cave.get(lastRoom).getRoomPic(),0,0,scWidth,scHeight,this);
			                  }
			            
                            swoosh.stop();
                            steps.stop();
                        } //end  for c
                    aDirection = -1;        
                    sDirection = -1;        
			        doorChoice = -1;
//                    if(shotNorth)
//			              shotNorth = false;
//                    if(shotEast)
//			              shotEast = false;
//                    if(shotSouth)
//			              shotSouth = false;
//                    if(shotWest)
//			              shotWest = false;
                    pen.drawImage(cave.get(currentRoom).getRoomPic(),0,0,scWidth,scHeight,this);
			        if (cave.get(currentRoom).getMonster().getType() == 3)  //pit
			          {
				        pen.setColor(Color.black);
				        pen.fillRoundRect(200,550,scWidth - 400,scHeight-200,200,100);
			            pen.drawString("" + cave.get(currentRoom).getMonster().getDescription(),10,170); 
					    pen.setFont(new Font("Timesroman",Font.ITALIC,100));
				        pen.setColor(Color.yellow);
			            pen.drawString("A HUGE PIT!" ,300,670); 
	                    if (random() < .8)
	                       {
	                       	   player.setHealth(player.getHealth() - 10);
	                       	   player.setScore(player.getScore() - 5);
	                           JOptionPane.showMessageDialog(null,"You encountered a pit,\n" + 
	                                         "but were barely able to hang \n"+
	                                         "on to the edge and scramble out. \n"+
	                                         "You can retrace your steps or \n"+
	                                         "continue through another door.\n"+
	                                         "You lost 5 points and 10% health,");
	                       }                  
	                    else
	                       {    
					            pause(5000);     
					            gameNotOver = false;    
					       }       
			          }
			        else  
			        if (cave.get(currentRoom).getMonster().getType() == 2)
			          {
			            pen.drawString("" + cave.get(currentRoom).getMonster().getDescription(),10,170); 
			            for (int m = 0; m< 22; m ++)
			              {
			                   cave.get(currentRoom).getMonster().getMonsterSound().play();
			                   pen.drawImage(cave.get(currentRoom).getRoomPic(),0,0,scWidth,scHeight,this);
				               pen.drawImage(cave.get(currentRoom).getMonster().getMonsterPic(),
				                  1600 - m*80,600-m*65, m*80,m*100,this); 
				               pause(50);   
			              } 
			            gameNotOver = false;      
			          }
			        else  
			        if (cave.get(currentRoom).getMonster().getType() == 1)
			          {
			            int save = currentRoom;
			            currentRoom = (int)(random()*cave.size());
					    pen.setFont(new Font("Timesroman",Font.ITALIC,30));
				        pen.setColor(Color.yellow);
			            for (int m = 0; m< (int)(random()*24); m ++)
			              {
			                   //cave.get(save).getMonster().getMonsterSound().play();
			                   pen.drawImage(cave.get((int)(random()*24)).getRoomPic(),0,0,scWidth,scHeight,this);
			                   pen.drawString("A bat is carrying you " +
			               			cave.get(save).getMonster().getDescription(),500,370); 
				               pause(500);   
			                   pen.drawImage(cave.get(currentRoom).getRoomPic(),0,0,scWidth,scHeight,this);
			              } 
		               player.setScore(player.getScore()-10);
		               player.setHealth(player.getHealth()-10);
			          }
			        else
			          {    
					        myScreen =createImage(getSize().width,getSize().height);
					        Graphics o = myScreen.getGraphics();
					        doubleBuffer(o);
					        pen.drawImage(myScreen,0,0,scWidth,scHeight,this);
					  }      
	         } 
	     else    //game has ended
	         {
				    pen.setFont(new Font("Timesroman",Font.ITALIC,250));
			        pen.setColor(Color.yellow);
		            pen.drawString("You Lose!" ,200,470); 
		            pause(5000);     
	         }	    
	     pen.setColor(Color.blue);     
	     pen.fillRect(0,scHeight -100,400,100);     
	     pen.setColor(Color.yellow);     
	     pen.setFont(new Font("Timesroman",Font.ITALIC,30));
	     pen.drawString("Score " + player.getScore(),40,scHeight -60);
	     for(int a = 0; a < player.getArrows(); a++)
	        pen.drawImage(arrowNorth,a*20 +170,scHeight-90,30,30,this);   
	     for(int a = 0; a < player.getSpells(); a++)
	        pen.drawImage(spellPicNum,a*20 +310,scHeight-90,10,30,this);   
	     pen.setColor(Color.yellow);     
	     for(int a = 0; a < player.getHealth()* 4; a+=40)
	          pen.fillRect(a,scHeight -40,40,30);  //health     
out.println(player.getHealth());
	  }   
	public void doubleBuffer(Graphics pen)  // Draws the window
	 {         
	           {      
	                setTitle("Hunt the Wumpus  -- COL Warr.   To navigate press N S E W C A L"); 
			        pen.drawImage(cave.get(currentRoom).getRoomPic(),0,0,scWidth,scHeight,this);
	                pen.setColor(Color.black);
	                pen.fillRect(0,0,700,200);
	                pen.setColor(Color.cyan);
			        pen.setFont(new Font("Timesroman",0,30));//toString
			        pen.drawString(cave.get(currentRoom).getDescription() ,30,120);
			        pen.setFont(new Font("Timesroman",0,20));//toString
			        pen.drawString(getWhichDoors(),100,80);
			        pen.drawString("Choose your direction (NESW) (L)ist visited rooms (S)earch warnings",30,160);
			        checkMonster(pen);
			        ArrayList <Integer> a = new ArrayList<Integer>();
			        a =cave.get(currentRoom).getDoors();
			        for(Integer d :a)
			           {
				          if (d >= 0 && cave.get(d).getMonster().getType() != 0)
		    		          pen.drawString("(C)ast a spell, shoot (A)rrow",100,180);
		    		   }     
			   }     
	 }    
	public void setPenColor(Graphics pen)
	{
	    switch (currentRoom)
	       {
	          case 0: pen.setColor(Color.white);
	              break;
	          case 1: pen.setColor(Color.white);
	              break;
	          case 2: pen.setColor(Color.green);
	              break;
	          case 3: pen.setColor(Color.green);
	              break;
	          default: pen.setColor(Color.black);
	              break;
	       }
	}   
	public void checkMonster( Graphics pen)
	{
	        String warning= "";
	        int thisDoor=0;												
	        for(int i = 0; i < cave.get(currentRoom).getDoors().size();i++)
	          {
	          	thisDoor = cave.get(currentRoom).getDoors().get(i);
	            if (thisDoor >= 0)
	               {
	                  if (cave.get(thisDoor).getMonster().getType()==1)  //bat
	                     pen.drawString( "You hear the faint beating of wings.",500,300);
	                  if (cave.get(thisDoor).getMonster().getType()==2)  //bat
	                     pen.drawString( " What a revolting smell.",500,400);
	                  if (cave.get(thisDoor).getMonster().getType()==3)  //bat
	                     pen.drawString( "The breeze is really cold.",500,500);
	               }  
	          }
	}	               
	public String getWhichDoors()
	{
	        String doors = "Directions you can go: ";
	        int thisDoor =0;
	        for(int i = 0; i < cave.get(currentRoom).getDoors().size();i++)
	          {
	          	thisDoor = cave.get(currentRoom).getDoors().get(i);
	            if (thisDoor >= 0)
	              {
	                if (i == 0)
	                  {
	                    doors += "North ";
	                    btnNorth.setVisible(true);
	                  }  
	                if (i == 1)
	                  {
	                    doors += "East ";
	                    btnEast.setVisible(true);
	                  }  
	                if (i == 2)
	                  {
	                    doors += "South ";
	                    btnSouth.setVisible(true);
	                  }  
	                if (i == 3)
	                  {
	                    doors += "West";
	                    btnWest.setVisible(true);
	                  }  
	             }
	             else
	               {
	                if (i == 0)
	                  {
	                    btnNorth.setVisible(false);
	                    btnList.setVisible(true);
	                  }  
	                if (i == 1)
	                  {
	                  
	                    btnEast.setVisible(false);
	                  }  
	                if (i == 2)
	                  {
	                   
	                    btnSouth.setVisible(false);
	                  }  
	                if (i == 3)
	                  {
	                   
	                    btnWest.setVisible(false);
	                  }  
	             }
	           }    
	         return doors;  
	}
	public void keyPressed(KeyEvent e)
	{
	    keyPressed = true;
//	    setTitle(""+ KeyEvent.getKeyText(e.getKeyCode()));  
//	    System.out.println("hit + "+ KeyEvent.getKeyText(e.getKeyCode()));
	    switch(e.getKeyCode())
	       {
	       	  case KeyEvent.VK_N :doorChoice = 0;
	       	                        break; 
	       	  case KeyEvent.VK_E :doorChoice = 1;
	       	                        break; 
	       	  case KeyEvent.VK_S :doorChoice = 2;
	       	                        break; 
	       	  case KeyEvent.VK_W :doorChoice = 3;
	       	                        break; 
	       	  case KeyEvent.VK_C :doorChoice = 4;  //cast a spell
	       	                        break; 
	       	  case KeyEvent.VK_A :doorChoice = 5;  //shoot an arrow
	       	                        break; 
       	                          
	          case KeyEvent.VK_L :String temp = "Rooms you have visited\n\n"; // need to be sorted
				                     for(CaveRoom c:visited)
				                         temp += c + "\n"; 
				                     JOptionPane.showMessageDialog(null,temp);
	       	                        break; 
	      }
   	  player.setHealth(player.getHealth() - (int)(random()*10));
	}
	public void actionPerformed(ActionEvent b)
	{
		keyPressed = true;
		String s = b.toString();
	    if (b.getSource()==btnNorth)         
		     doorChoice = 0;     
	    if (b.getSource()==btnSouth)         
		     doorChoice = 2;     
	    if (b.getSource()==btnEast)         
		     doorChoice = 1;     
	    if (b.getSource()==btnWest)         
		     doorChoice = 3;     
	    player.setHealth(player.getHealth() - (int)(random()*10));
	}	
	public void mouseClicked(MouseEvent m)
	{
	}	
	public void mouseEntered(MouseEvent m)
	{
	}	
	public void mouseExited(MouseEvent m)
	{
	}	
	public void mousePressed(MouseEvent m)
	{
	}	
	public void mouseReleased(MouseEvent m)
	{
	}	
	  
	
	
	public void keyReleased(KeyEvent e)
	{
	}
	public void keyTyped(KeyEvent e)
	{
	}
	public void update(Graphics G)
	{
		  out.println("Got here");
		  paint(G);
	}	    
	public void pause (long r)
	{
	    try
	       {
	       	   Thread.sleep(r);
	       	}
	    catch (Exception e ) {}   	 
	}
}
class Player
{
	private String name;
	private String pictureName;
	private int score,health,spells;
	private int numArrows;
	private double money;
    private Image picture;
	public Player()
	{
		score = 0;
	    money = 100;
	    numArrows = 5;
	    spells = 3;
	    name = "";
	    pictureName = "";
    }
	public Player(String n,String p)
	{
		score = 0;
	    money = 100;
	    numArrows = 5;
	    spells = 3;
	    name = n;
	    pictureName = p;
	    loadPicture();
    }
	public Player(int s, double m, int a, int sp, int h,String n,String p)
	{
		score = s;
	    money = m;
	    numArrows = a;
	    spells = sp;
        health = h;
	    name = n;
	    pictureName = p;
	    loadPicture();
    }
    public String getName() { return name;}
    public String getPictureName() { return pictureName;}
    public int getScore() { return score;}
    public double getMoney() { return money;}
    public int getArrows() { return numArrows;}
    public int getSpells() { return spells;}
    public int getHealth() { return health;}
    public Image getPicture() { return picture;}
    public void setName(String n) {  name = n;}
    public void setScore(int s) {  score = s;}
    public void setHealth(int s) {  health = s;}
    public void setArrows(int s) {  numArrows = s;}
    public void setSpells(int s) {  spells = s;}
    public void addScore(int s) {  score += s;}
    public void setMoney(double m) {  money = m;}
    public void setPicture(String p) {  pictureName = p;}
    public void loadPicture() 
    	{  
	  	    picture = Toolkit.getDefaultToolkit().getImage(pictureName);
        }
    public String toString()
       {
       	   return String.format("Name = %s\nMoney = $%,.2f\nScore = %,d\nImage = \"%s\"" 
       	                       , name, money, score,pictureName); 
       }	                       
}
class CaveRoom 
{
	private Image room;
	private String description;
	private Monster monster;
	private ArrayList <Integer> door;
	CaveRoom()
	  {
	  	 monster = new Monster();
	  	 door = new ArrayList<Integer>();
	  	 description = "A normal room";
	  	 for(int x = 0; x< 4; x++)
	  	    door.add(-1);
	  }	    
	CaveRoom(String n,int a, int b, int c, int d,String picName)
	  {
	  	 monster = new Monster("no hazard",0);
	  	 room = Toolkit.getDefaultToolkit().getImage(picName);
         door = new ArrayList<Integer>();
	  	 description = n;
 	     door.add(a);
	     door.add(b);
	     door.add(c);
	     door.add(d);
	  }	
	CaveRoom(Monster m, String n,int a, int b, int c, int d,String picName)
	  {
	  	 monster = m;  
	  	 room = Toolkit.getDefaultToolkit().getImage(picName);
         door = new ArrayList<Integer>();
	  	 description = n;
 	     door.add(a);
	     door.add(b);
	     door.add(c);
	     door.add(d);
	  }	
	public Monster getMonster()
	  {
	  	return monster;
	  }	  
	public void setMonster(Monster d)
	  {
	  	monster= d;
	  }	  
	public void setMonster(String d, int t)
	  {
	  	monster.setDescription(d);
	  	monster.setType(t);
	  }	  
	public Image getRoomPic()
	  {
	  	return room;
	  }	  
	public ArrayList<Integer> getDoors()
	  {
	  	  return  door;
	  }	    
	public String getDescription()
	  {
	  	  return  description;
	  }	    
	public int getDoorHeading(int n)
	  {
	  	 return door.get(n);
	  }	       
	public String toString()
	  {
	  	  String s = description  
	  	         + " Doors: ";
	  	  for(int x = 0; x < door.size(); x++)
	  	     if (door.get(x) > -1)
	  	        if ( x == 0)
	  	            s += "North " + door.get(x) + " ";
	  	        else    
	  	        if ( x == 1)
	  	            s += "East " + door.get(x) + " ";
	  	        else    
	  	        if ( x == 2)
	  	            s += "South " + door.get(x) + " ";
	  	        else    
	  	            s += "West " + door.get(x) + " ";
	  	        return s;    
       }	  	           
}
class Monster
{
    private String description;
    private int type;
    private String soundFile;
    private String imageFile;
    private Image monsterPic;
    private AudioClip monsterSound;
	public Monster()   // default constructor
	   {
	   	   type = 0;
	   	   description = "No monster";
	   }
	public Monster(String d, int t)
	   {
	   	   type = t;
	   	   description = d;
	   }
	public Monster(String d, int t, String imageFile,String soundFile) //throws Exception
	   {
	   	   type = t;
	   	   this.soundFile = soundFile;
	   	   this.imageFile = imageFile;
	   	   description = d;
	  	   monsterPic = Toolkit.getDefaultToolkit().getImage(imageFile);
		   try {
		           monsterSound = Applet.newAudioClip(new URL("file:" + soundFile));
		        }    
		    catch (MalformedURLException e) 
		        {
		    	      System.out.println("error" + e);
		        }
	   }
	public Monster(Monster m)   // default constructor
	   {
	   	   type = m.type;
	   	   this.soundFile = m.soundFile;
	   	   this.imageFile = m.imageFile;
	   	   description = m.description;
	  	   monsterPic = m.monsterPic;
		   monsterSound = m.monsterSound;
	   }
    public String getSoundFile() {return soundFile;}
    public String getImageFile() {return imageFile;}
	public Image getMonsterPic()
	   {
	   	   return monsterPic;
	   }	      	 
	public AudioClip getMonsterSound()
	   {
	   	   return monsterSound;
	   }	      	 
	public int getType()  //accessor
	   {
	   	  return type;
	   }	     
	public String getDescription()  //accessor
	   {
	   	  return description;
	   }	     
	public void setType(int t) // mutator
	   {
	   	  type = t;
	   }	     
    public void setSoundFile(String s) {soundFile= s;}
    public void setImageFile(String s) {imageFile= s;}
	public void setDescription(String d) // mutator
	   {
	   	  description = d;
	   }	     
	public String toString()
	   {
	   	   return "Description: " + description + 
	   	          "\n                   type    0 = No Monster " +
	   	          "\n                           1 = Bat " +                                    
	   	          "\n                           2 = Wumpus " +                                    
	   	          "\n                           3 = Pit " +                                    
	   	          "\n                 Monster in this room " + type;
	   }	                                              
}	   	   

//Klein ISD Acceptable use policy:
//1.       Student developed games and other programming projects may not include profane references to a deity, 
//         obscene language, drug abuse or paraphernalia, images of suicide or criminal violence, suggested or 
//         explicit sexuality, partial/full/frontal nudity, or any subject matter inappropriate for young adults, 
//         and any content that may offend the moral standards of the community are strictly prohibited. Students 
//         must receive teacher approval on game and project design before developing content within a class 
//         assignment or project.  
//
//2.       All games developed, viewed, or shown/demonstrated on a Klein ISD computer, and/or as part of Klein ISD 
//         assignments and projects must meet the Entertainment Software Rating Board rating for Early Childhood or 
//         Everyone.
//			(ESRB: http://www.esrb.org/ratings/ratings_guide.jsp#rating_categories)
//
//3.       Additionally, student created games and projects may not contain content that is categorized by the 
//         following ESRB content descriptors: Alcohol Reference, Animated Blood, Blood, Blood and Gore, Crude Humor, 
//         Drug Reference, Fantasy Violence, Intense Violence, Language, Lyrics, Mature Humor, Nudity, Partial Nudity, 
//         Real Gambling, Sexual Content, Sexual Themes, Sexual Violence, Simulated Gambling, and Strong Language. 
//
			   	