title: Add Score in maze game written in java
body: <p>I am going to make a maze game in java. I have done almost but i have facing problem to add score. I have add the time spend to end the game, but it doesn;t terminate. here is my code. Please help me to print the total time.....</p>
  
  <pre><code>package Maze;   
  import java.awt.*;
  import java.awt.event.*;
  import javax.swing.*;
  
  public class Board extends JPanel implements ActionListener
   {
       private Timer timer;
       private Map m;
       private Player p;
       private boolean win=false;
       long startTime=0;
       long message=0;
  
       public Board()
       {
           startTime=System.currentTimeMillis();
           m= new Map();
           p= new Player();
           addKeyListener(new Al());
           setFocusable(true);
           timer=new Timer(25, this);
           timer.start();
       }
  
       public void actionPerformed(ActionEvent e)
       {
           if(m.getMap(p.getTileX(), p.getTileY()).equals("f"))
           {               
               win=true;
               message=(startTime+10000)-System.currentTimeMillis();
           }
  
          repaint(); 
       }
       public void paint(Graphics g)
       {
          super.paint(g);
          if(!win&amp;&amp;(System.currentTimeMillis()&lt;=(startTime+10000)))
          {
           for(int y=0;y&lt;14;y++)
           {
               for(int x=0;x&lt;14;x++)
               {
                   if(m.getMap(x,y).equals("f"))
                       g.drawImage(m.getFinish(), x*32, y*32, null);
                   if(m.getMap(x, y).equals("w"))
                          g.drawImage(m.getWall(), x*32, y*32, null);
                  if(m.getMap(x, y).equals("g"))
                          g.drawImage(m.getGrass(), x*32, y*32, null);
  
               }
           }
           g.drawImage(p.getPlayer(), p.getTileX()*32, p.getTileY()*32,null);
          }
  
              else if(win)
               {
                  long end = System.currentTimeMillis();
                  long time=end-startTime;
                  //String str=Long.toString(time);
                  JOptionPane.showMessageDialog(null, "Your Score:"+time);
                  //System.exit(0);
                  //g.drawImage(m.getWinn(), 32, 32, null);
                  //JOptionPane.showMessageDialog(this, "Winner");
               }
          else
          {
              g.drawImage(m.getLose(), 32, 32, null);
          }
  
       }
       public class Al extends KeyAdapter{
  
           public void keyPressed(KeyEvent e){
  
          /*   long startTime1 = System.currentTimeMillis();
               totalTime=(startTime1-startTime)/1000;
               JOptionPane.showMessageDialog(null,totalTime); */   
               int keycode= e.getKeyCode();
  
               if(keycode==KeyEvent.VK_UP )
               {
                   if(!m.getMap(p.getTileX(),p.getTileY()-1).equals("w"))
                   {
                       p.move( 0, -1);
                   }
               }
  
               if(keycode==KeyEvent.VK_DOWN )
               {
                   if(!m.getMap(p.getTileX(),p.getTileY()+1).equals("w"))
                   {
                       p.move( 0, 1);
                   }
               }
               if(keycode==KeyEvent.VK_LEFT )
               {
                   if(!m.getMap(p.getTileX()-1,p.getTileY()).equals("w"))
                   {
                       p.move( -1, 0);
                   }
               }
               if(keycode==KeyEvent.VK_RIGHT )
               {
                   if(!m.getMap(p.getTileX()+1,p.getTileY()).equals("w"))
                   {
                       p.move( 1, 0  );    
                   }
  
               }
  
           }
  
       }
   }
  </code></pre>
  
  <p>and here is my confusion point</p>
  
  <pre><code>else if(win)
  {
      long end = System.currentTimeMillis();
      long time=end-startTime;
      // String str=Long.toString(time);
      JOptionPane.showMessageDialog(null, "Your Score:"+time);
      // System.exit(0);
      // g.drawImage(m.getWinn(), 32, 32, null);
      //JOptionPane.showMessageDialog(this, "Winner");
  }
  </code></pre>