public void checkScore() {
        if (p.calculateScore() > Integer.parseInt(highscore.split(":")[1])) {
            String name = JOptionPane.showInputDialog("Highscore! Input name:");
            highscore = name+ ":" + p.calculateScore();
            File scoreFile = new File("highscore.dat");
            if(!scoreFile.exists()){
                try{
                scoreFile.createNewFile();
                } catch (Exception e){
                    e.printStackTrace();
                }
            }
            FileWriter writer = null;
            BufferedWriter buffWriter = null;
            
            try{
                writer = new FileWriter(scoreFile);
                buffWriter = new BufferedWriter(writer);
                writer.write(highscore);
            }catch (Exception e) {
                
            }
            finally {
                try {
                    if(buffWriter!=null){
                        buffWriter.close();
                    }
                } catch (Exception e){
                    e.printStackTrace();
                } 
            }
        }
    }