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