Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void processInput() {
- 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"+
- "\nZadaj vstup: ");
- String retazec = readLine();
- try {
- handleInput(retazec);
- } catch (WrongFormatException ex) {
- Logger.getLogger(ConsoleUI.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- private void handleInput(String input) throws WrongFormatException {
- int row,column;
- Pattern pattern = Pattern.compile("(x)|([m,o])([a-"+(char)(field.getRowCount()+'a'-1)+"])(\\d+)");
- input = input.toLowerCase();
- Matcher matcher = pattern.matcher(input);
- if (matcher.matches() == true) {
- if(matcher.group(1) != null) { // ak bolo zadane x
- System.out.println("Koniec");
- System.exit(0);
- }
- else {
- row = Integer.valueOf(matcher.group(3).charAt(0)) - 'a';
- column = Integer.valueOf(matcher.group(4)).intValue();
- if(column < field.getColumnCount()) {
- if(matcher.group(2).endsWith("m"))
- field.markTile(row, column);
- else if(matcher.group(2).endsWith("o"))
- field.openTile(row, column);
- }
- else throw new WrongFormatException("Zly vstup, opakujte volbu.");
- }
- }
- else {
- throw new WrongFormatException("Zly vstup, opakujte volbu.");
- }
- }
- }
Add Comment
Please, Sign In to add comment