Guest User

Untitled

a guest
Dec 11th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. private void processInput() {
  2. System.out.print("\nX – ukončenie hry, MA1 – označenie dlaždice v riadku A a stĺpci 1, OB4 – odkrytie dlaždice v riadku B a stĺpci 4"+
  3. "\nZadaj vstup: ");
  4. String retazec = readLine();
  5. try {
  6. handleInput(retazec);
  7. } catch (WrongFormatException ex) {
  8. Logger.getLogger(ConsoleUI.class.getName()).log(Level.SEVERE, null, ex);
  9. }
  10.  
  11. }
  12. private void handleInput(String input) throws WrongFormatException {
  13. int row,column;
  14.  
  15. Pattern pattern = Pattern.compile("(x)|([m,o])([a-"+(char)(field.getRowCount()+'a'-1)+"])(\\d+)");
  16.  
  17. input = input.toLowerCase();
  18. Matcher matcher = pattern.matcher(input);
  19.  
  20. if (matcher.matches() == true) {
  21.  
  22. if(matcher.group(1) != null) { // ak bolo zadane x
  23. System.out.println("Koniec");
  24. System.exit(0);
  25. }
  26. else {
  27. row = Integer.valueOf(matcher.group(3).charAt(0)) - 'a';
  28. column = Integer.valueOf(matcher.group(4)).intValue();
  29. if(column < field.getColumnCount()) {
  30. if(matcher.group(2).endsWith("m"))
  31. field.markTile(row, column);
  32. else if(matcher.group(2).endsWith("o"))
  33. field.openTile(row, column);
  34. }
  35. else throw new WrongFormatException("Zly vstup, opakujte volbu.");
  36. }
  37. }
  38. else {
  39. throw new WrongFormatException("Zly vstup, opakujte volbu.");
  40. }
  41. }
  42. }
Add Comment
Please, Sign In to add comment