Guest User

Untitled

a guest
Jun 23rd, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.16 KB | None | 0 0
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package dodger;
  6. import java.util.HashMap;
  7. import java.awt.event.KeyEvent;
  8. import java.io.*;
  9. /**
  10.  *
  11.  * @author Will
  12.  */
  13. public class Keybindings {
  14.     public Keybindings() {load();}
  15.     public HashMap<String, Integer> hash = new HashMap<String, Integer>();
  16.     public static String dir = "lib"+File.separator+"keybindings.txt";
  17.     public void load() {
  18.         File file = new File(dir);
  19.         try{
  20.             if (file.exists()) {
  21.                 BufferedReader in = new BufferedReader(new FileReader(file));
  22.                 String line = in.readLine();
  23.                 boolean stop = false;
  24.                 while(line != null && !stop) {
  25.                     if (!line.equals("reload")) {
  26.                         try{
  27.                             String[] split = line.split("=");
  28.                             hash.put(split[0], Integer.valueOf(split[1]));
  29.                         }catch(Exception e) {}
  30.                     }else{
  31.                         init();
  32.                         stop = true;
  33.                     }
  34.                     line = in.readLine();
  35.                 }
  36.                 in.close();
  37.             }else{
  38.                 init();
  39.             }
  40.         }catch(IOException e) {
  41.         }
  42.     }
  43.    
  44.     public void init() {
  45.        
  46.         File file = new File(dir);
  47.         try{
  48.             file.createNewFile();
  49.             PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(file)));
  50.             out.println("left="+KeyEvent.VK_LEFT);
  51.             out.println("right="+KeyEvent.VK_RIGHT);
  52.             out.println("increase_speed="+KeyEvent.VK_UP);
  53.             out.println("decrease_speed="+KeyEvent.VK_DOWN);
  54.             out.println("pause="+KeyEvent.VK_P);
  55.             out.println("restart="+KeyEvent.VK_R);
  56.             out.println("playback="+KeyEvent.VK_B);
  57.             out.println("fire="+KeyEvent.VK_SPACE);
  58.             out.println("highscores="+KeyEvent.VK_H);
  59.             out.println("set_name="+KeyEvent.VK_N);
  60.             out.close();
  61.         }catch(IOException e) {
  62.            
  63.         }
  64.     }
  65. }
Add Comment
Please, Sign In to add comment