예제 #1
0
 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;
 }
예제 #2
0
 // 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;
 }
예제 #3
0
 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;
 }
예제 #4
0
 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()));
 }
예제 #5
0
 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));
 }
예제 #6
0
 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;
   }
 }
예제 #7
0
 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;
   }
 }
예제 #8
0
 public ArrayList<AbstractMap.SimpleEntry<String, Integer>> getRanking() {
   return dataController.getRanking("10");
 }
예제 #9
0
 public void disableUser() {
   dataController.disableUser(currentUser.username);
 }
예제 #10
0
 public void changePassword(String password) {
   dataController.changePassword(currentUser.username, password);
   currentUser.password = password;
 }
예제 #11
0
 public int getNumberFinishedMatches(int id) {
   return dataController.getNumberFinishedMatches(id);
 }
예제 #12
0
 public int getBoardSize(int idBoard) {
   if (idBoard == 0) return 3;
   return dataController.getBoardSize(idBoard);
 }
예제 #13
0
 public ArrayList<SimpleEntry<Integer, SimpleEntry<String, Integer>>> getAllBoards() {
   return dataController.getAllBoards();
 }
예제 #14
0
 public void saveBoard(String board, int size) {
   dataController.saveBoard(board, size);
 }
예제 #15
0
 public int getNumberUsers() {
   return dataController.getNumberUsers();
 }
예제 #16
0
 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();
 }
예제 #17
0
 public int getNumberBoards() {
   return dataController.getNumberBoards();
 }
예제 #18
0
 public String getInitialBoard(int id) {
   return dataController.getInitialBoard(id);
 }
예제 #19
0
 public ArrayList<
         SimpleEntry<
             Integer, SimpleEntry<String, SimpleEntry<Integer, SimpleEntry<Integer, Integer>>>>>
     getFinishedMatches() {
   return dataController.getFinishedMatches(currentUser.username);
 }
예제 #20
0
 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);
 }
예제 #21
0
 public SimpleEntry<Integer, SimpleEntry<String, SimpleEntry<Integer, Integer>>> getFinishedMatch(
     int option) {
   return dataController.getFinishedMatch(currentUser.username, option);
 }
예제 #22
0
 public void closeProgram() {
   dataController.closeProgram();
 }
예제 #23
0
 public SimpleEntry<String, Integer> getBoard(int id) {
   return dataController.getBoard(id);
 }
예제 #24
0
 public ArrayList<SimpleEntry<String, Integer>> getBoardBestTimes(int id) {
   return dataController.getBoardBestTimes(id);
 }