public boolean isMatchFinished() { if (match.isCorrect()) { if (match.getIdBoard() != 0) dataController.saveRecord(currentUser.username, match.getIdBoard(), match.getTime()); dataController.updateScore(currentUser.username); return true; } return false; }
// Logueja un usuari public boolean correctUserLogin(String username, String password) { if (dataController.existUser(username, password)) { currentUser.username = username; currentUser.password = password; return true; } return false; }
public SimpleEntry<String, Integer> solveBoard(int id) { // Anem a buscar el tauler a la bd, el resolem i el retornem SimpleEntry<String, Integer> board = dataController.getBoard(id); SudokuGame sudokuGame = new SudokuGame(board.getKey(), board.getValue()); int time = sudokuGame.sudokuSolve(); SimpleEntry<String, Integer> result = new SimpleEntry<String, Integer>(sudokuGame.boardToString(), time); return result; }
public void startMatch(int id) { // Inicia una partida a partir d'un tauler de la bd SimpleEntry<String, Integer> board = dataController.getBoard(id); match = new Match(); match.setIdBoard(id); match.setBoardSolved(new SudokuBoard(board.getKey(), board.getValue())); match.setGame(new SudokuGame(board.getKey(), board.getValue())); match.setInitialState(new SudokuBoard(board.getKey(), board.getValue())); }
public void continueMatch(int id) { // Continua una partida guardada SimpleEntry< Integer, SimpleEntry< Integer, SimpleEntry<String, SimpleEntry<String, SimpleEntry<String, Integer>>>>> savedMatch = dataController.getSavedMatch(id, currentUser.username); match = new Match(); match.setTime((int) (System.currentTimeMillis() - (savedMatch.getKey() * 1000))); match.setIdBoard(savedMatch.getValue().getKey()); match.setHintsRemaining(savedMatch.getValue().getValue().getValue().getValue().getValue()); int size = (int) Math.sqrt(Math.sqrt((savedMatch.getValue().getValue().getKey().length() + 1) / 2)); match.setBoardSolved(new SudokuBoard(savedMatch.getValue().getValue().getKey(), size)); match.setGame(new SudokuGame(savedMatch.getValue().getValue().getValue().getKey(), size)); match.setInitialState( new SudokuBoard(savedMatch.getValue().getValue().getValue().getValue().getKey(), size)); }
public void saveFinishedMatch() { // Guarda una partida finalitzada if (match != null) { int time = match.getTime(); int ended = 1; int idBoard = match.getIdBoard(); String boardSolved = match.getBoardSolved().boardToString(); String boardState = match.getGame().boardToString(); String initialState = match.getInitialState().boardToString(); int hintsRemaining = match.getHintsRemaining(); dataController.saveMatch( time, ended, idBoard, boardSolved, boardState, initialState, currentUser.username, hintsRemaining); match = null; } }
public void saveMatch() { // Guarda una partida a mitges if (match != null) { int time = (int) (System.currentTimeMillis() - match.getTime()) / 1000; int ended = 0; int idBoard = match.getIdBoard(); String boardSolved = match.getBoardSolved().boardToString(); String boardState = match.getGame().boardToString(); String initialState = match.getInitialState().boardToString(); int hintsRemaining = match.getHintsRemaining(); dataController.saveMatch( time, ended, idBoard, boardSolved, boardState, initialState, currentUser.username, hintsRemaining); match = null; } }
public ArrayList<AbstractMap.SimpleEntry<String, Integer>> getRanking() { return dataController.getRanking("10"); }
public void disableUser() { dataController.disableUser(currentUser.username); }
public void changePassword(String password) { dataController.changePassword(currentUser.username, password); currentUser.password = password; }
public int getNumberFinishedMatches(int id) { return dataController.getNumberFinishedMatches(id); }
public int getBoardSize(int idBoard) { if (idBoard == 0) return 3; return dataController.getBoardSize(idBoard); }
public ArrayList<SimpleEntry<Integer, SimpleEntry<String, Integer>>> getAllBoards() { return dataController.getAllBoards(); }
public void saveBoard(String board, int size) { dataController.saveBoard(board, size); }
public int getNumberUsers() { return dataController.getNumberUsers(); }
public String generateBoard(int numCells, int diff) { SimpleEntry<String, String> boardGen = dataController.getSysBoard(diff); SudokuBoard board = new SudokuBoard(boardGen.getKey(), 3); SudokuFactory.generate(board, new SudokuBoard(boardGen.getValue(), 3), numCells); return board.boardToString(); }
public int getNumberBoards() { return dataController.getNumberBoards(); }
public String getInitialBoard(int id) { return dataController.getInitialBoard(id); }
public ArrayList< SimpleEntry< Integer, SimpleEntry<String, SimpleEntry<Integer, SimpleEntry<Integer, Integer>>>>> getFinishedMatches() { return dataController.getFinishedMatches(currentUser.username); }
public void createUser(String username, String password) throws SQLException { // Si intenta crear un usuari amb un nom que ja existeix, envia una excepcio dataController.createUser(username, password); }
public SimpleEntry<Integer, SimpleEntry<String, SimpleEntry<Integer, Integer>>> getFinishedMatch( int option) { return dataController.getFinishedMatch(currentUser.username, option); }
public void closeProgram() { dataController.closeProgram(); }
public SimpleEntry<String, Integer> getBoard(int id) { return dataController.getBoard(id); }
public ArrayList<SimpleEntry<String, Integer>> getBoardBestTimes(int id) { return dataController.getBoardBestTimes(id); }