diff --git a/resources/SQLiteKakuro.db b/resources/SQLiteKakuro.db index 188eac6..ea1bdb4 100644 Binary files a/resources/SQLiteKakuro.db and b/resources/SQLiteKakuro.db differ diff --git a/src/kakuro/GameModel.java b/src/kakuro/GameModel.java deleted file mode 100644 index 74cd1dd..0000000 --- a/src/kakuro/GameModel.java +++ /dev/null @@ -1,92 +0,0 @@ -// @author Vsevolod Ivanov -// @author ... -// @brief Game model class which handles the Kakuro game storage. - -package kakuro; - -import java.util.Enumeration; - -import javax.swing.JTextField; -import javax.swing.tree.TreeNode; - -public class GameModel -{ - - public final int columns; - public final int rows; - public BoardCell[][] board; - private static UniquePartitions partitions; - - public GameModel(final int columns, final int rows) - { - this.columns = columns; - this.rows = rows; - partitions = new UniquePartitions(); - } - - public void initBoard() - { - board = new BoardCell[this.rows][this.columns]; - - for(int row = 0; row < this.rows; row++) - { - for(int column = 0; column < this.columns; column++) - { - board[row][column] = new BoardCell(BoardCell.CellType.EMPTY); - } - } - } - - //TODO: to remove - iteration2 - public void generateBoard10x10() - { - // second row - TreeNode eightBlocksTree = partitions.root.getChildAt(6 /* start at two blocks tree */); - // chose a random sum in children - TreeNode randEightBlockTree = eightBlocksTree.getChildAt(Tools.randomInt(0,7)); - int randEightBlockSum = Integer.parseInt(randEightBlockTree.toString()); - board[1][0] = new BoardCell(BoardCell.CellType.FILLED01, -1, randEightBlockSum); - // mark & fill the input cells - int[] array = Tools.childrenToArray(randEightBlockTree); - for(int column = 1; column <= 8; column++) - { - board[1][column] = new BoardCell(BoardCell.CellType.INPUT, -1, array[column-1]); - } - // row - 1 - eightBlocksTree = partitions.root.getChildAt(6 /* start at two blocks tree */); - // chose a random sum in children - randEightBlockTree = eightBlocksTree.getChildAt(Tools.randomInt(1,7)); - randEightBlockSum = Integer.parseInt(randEightBlockTree.toString()); - board[8][0] = new BoardCell(BoardCell.CellType.FILLED01, -1, randEightBlockSum); - // mark & fill the input cells - array = Tools.childrenToArray(randEightBlockTree); - for(int column = 8; column >=1; column--) - { - board[8][column] = new BoardCell(BoardCell.CellType.INPUT, -1, array[8-column]); - } - // second row - eightBlocksTree = partitions.root.getChildAt(6 /* start at two blocks tree */); - // chose a random sum in children - randEightBlockTree = eightBlocksTree.getChildAt(Tools.randomInt(0,7)); - randEightBlockSum = Integer.parseInt(randEightBlockTree.toString()); - // find sum for column that connect first row to row - 1 - for(Enumeration tree = eightBlocksTree.children(); tree.hasMoreElements();) - { - TreeNode candidateTree = tree.nextElement(); - int[] candidatesArray = Tools.childrenToArray(candidateTree); - // second column - if (candidatesArray[0] == board[1][1].getSecondValue() && candidatesArray[7] == board[1][8].getSecondValue()) - { - // put sum number - int sum = Integer.parseInt(candidateTree.toString()); - board[0][1] = new BoardCell(BoardCell.CellType.FILLED10, sum); - // mark & fill the input cells - for(int row = 1; row < 8; row++) - { - board[row+1][1] = new BoardCell(BoardCell.CellType.INPUT, -1, candidatesArray[row]); - } - break; - } - } - } -} diff --git a/src/kakuro/GameView.java b/src/kakuro/GameView.java deleted file mode 100644 index cd6fdb1..0000000 --- a/src/kakuro/GameView.java +++ /dev/null @@ -1,356 +0,0 @@ -// @author Vsevolod Ivanov -// @author Isabelle Charette -// @brief Game view class which handles the Kakuro game interface. - -package kakuro; - -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.GridLayout; -import java.text.NumberFormat; -import java.util.Scanner; -import javax.swing.JFormattedTextField; -import javax.swing.JFrame; -import javax.swing.JPanel; -import javax.swing.JTextField; -import javax.swing.border.LineBorder; -import javax.swing.text.NumberFormatter; - -/* - * SOURCES - * Examples on extending JPanel class and using paintComponent method // Examples for textfield formatting - * http://programmedlessons.org/java5/Notes/chap36/ch36_10.html - * https://docs.oracle.com/javase/tutorial/uiswing/components/formattedtextfield.html - * https://docs.oracle.com/javase/8/docs/api/javax/swing/JFormattedTextField.html - */ - -import kakuro.GameController.UserActions; - -public class GameView -{ - private GameController controller; - private Scanner inputReader = new Scanner(System.in); - private ButtonMenu buttonMenu; - // TODO remove and use listeners to interact directly with model.board - public JTextField[][] saveInput; - private JPanel currentPanel; //The reference to the current displaying pane (board UI) - - public ButtonMenu getButtonMenu() { - return buttonMenu; - } - - public void setButtonMenu(ButtonMenu buttonMenu) { - this.buttonMenu = buttonMenu; - } - - JFrame frame; - int gridSizeX; - int gridSizeY; - NumberFormat numberFormat = NumberFormat.getInstance(); - NumberFormatter numberFormatter = new NumberFormatter(numberFormat); - - public GameView(final GameController controller, Boolean X11) - { - if (controller != null) - { - this.controller = controller; - gridSizeX = controller.model.rows; - gridSizeY = controller.model.columns; - } - if (X11) { - frame = new JFrame("KAKURO"); - buttonMenu = new ButtonMenu(frame, gridSizeX, gridSizeY, controller); - saveInput = new JTextField[controller.model.rows][controller.model.columns]; - } - - numberFormatter.setValueClass(Integer.class); - numberFormatter.setMinimum(1); - numberFormatter.setMaximum(9); - // TODO remove see definition comment - saveInput=new JTextField[controller.model.rows][controller.model.columns]; - } - - public void printStartup() - { - System.out.println("welcome to kakuro game!"); - System.out.println("=> use numbers between 1-9 to fill the cells;"); - } - - public void loadInputInModel() - { - for(int row = 0; row < controller.model.columns; row++) - { - for(int column = 0; column < controller.model.rows; column++) - { - BoardCell cell = controller.model.board[row][column]; - String value = this.saveInput[row][column].getText(); - if(!value.isEmpty()) { - switch (cell.getType()) - { - case INPUT: - controller.model.board[row][column].setFirstValue(Integer.parseInt(value)); - break; - default: - break; - } - } - } - } - } - - public int getMinNumberValid() { - return (int) numberFormatter.getMinimum(); - } - - public Object getNumberFormatterClassType() { - return numberFormatter.getClass(); - } - - - public int getMaxNumberValid() { - return (int) numberFormatter.getMaximum(); - } - - //creates user interface of the game board - public void board_ui() { - - int frameSize = 60; - //creating grid of cells - JPanel panel = new JPanel(new GridLayout(gridSizeX,gridSizeY)); - //creating window of the game - - //this allows temporary invalid input, particularly to be able to delete and try again - //if invalid input, when clicking onto another cell, the input will be deleted - numberFormatter.setAllowsInvalid(true); - - //identifies type of each cell and populates it - //input or non-playable - for(int row = 0; row < controller.model.rows; row++) - { - for(int column = 0; column < controller.model.columns; column++) - { - JFormattedTextField textField = null; - - //tracking the type of each cell - BoardCell cell = controller.model.board[row][column]; - //adding extra panel that will overlay the cells that are non-playable with game level numbers and diagonal line - JPanel diagonalPanel = null; - - //according to type of cell, populate - switch (cell.getType()) - { - case EMPTY: - textField = new JFormattedTextField(numberFormatter); - settingTextField(textField); - textField.setBorder(new LineBorder(Color.GRAY,1)); - panel.add(textField); - break; - - case INPUT: - textField = new JFormattedTextField(numberFormatter); - textField.setHorizontalAlignment(JTextField.CENTER); - textField.setBorder(new LineBorder(Color.GRAY,1)); - //When you load a game, there is some data exists. We have to check to make sure we are displaying the saved input - if(cell.getFirstValue()!=-1) - textField.setValue(cell.getFirstValue()); - panel.add(textField); - break; - - case FILLED01: - textField = new JFormattedTextField(cell.getSecondValue()); - settingTextField(textField); - //adding diagonal line in board cell - diagonalPanel = new line_panel(new BorderLayout(), textField, true); - diagonalPanel.setBorder(new LineBorder(Color.GRAY,1)); - panel.add(diagonalPanel); - break; - - case FILLED10: - textField = new JFormattedTextField(cell.getFirstValue()); - settingTextField(textField); - //adding diagonal line in board cell - diagonalPanel = new line_panel(new BorderLayout(), textField, false); - diagonalPanel.setBorder(new LineBorder(Color.GRAY,1)); - panel.add(diagonalPanel); - break; - - case FILLED11: - textField = new JFormattedTextField(cell.getFirstValue()); - JFormattedTextField textFieldRIGHT = new JFormattedTextField(cell.getSecondValue()); - settingTextField(textField); - settingTextField(textFieldRIGHT); - //using constructor that expects two text values to place in board cell - diagonalPanel = new line_panel(new BorderLayout(), textField, textFieldRIGHT); - diagonalPanel.setBorder(new LineBorder(Color.GRAY,1)); - panel.add(diagonalPanel); - break; - - default: - break; - } - //placing textfield value in input array to track user input - this.saveInput[row][column] = textField; - } - } - int x = frameSize*gridSizeX; - int y = frameSize*gridSizeY; - - frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - frame.setSize(x, y); - frame.setResizable(false); - - //If a panel is already attached to the frame, remove it - if(currentPanel != null) - frame.getContentPane().remove(currentPanel); - - //Save a reference to the new panel - frame.getContentPane().add(panel); - currentPanel = panel; - - // currentPanel = panel; - frame.setVisible(true); - - } - - public void settingTextField(JTextField txt) { - txt.setBackground(Color.black); - txt.setForeground(Color.white); - txt.setBorder(javax.swing.BorderFactory.createEmptyBorder()); - txt.setEditable(false); - } - public void printBoard(Boolean showAnswerValues) - { - System.out.println("board:"); - for(int row = 0; row < controller.model.rows; row++) - { - for(int column = 0; column < controller.model.columns; column++) - { - int value = 0; - int value2 = 0; - BoardCell cell = controller.model.board[row][column]; - switch (cell.getType()) - { - case EMPTY: - System.out.print(" x "); - break; - case INPUT: - System.out.print(" " + - (showAnswerValues ? (cell.getSecondValue() != -1 ? cell.getSecondValue() : "_") : - (cell.getFirstValue() != -1 ? cell.getFirstValue() : "_")) + - " "); - break; - case FILLED11: - value = cell.getFirstValue(); - value2 = cell.getSecondValue(); - System.out.print(" " + value + "\\" + value2); - break; - case FILLED10: - value = cell.getFirstValue(); - System.out.print(" " + value + "\\"); - break; - case FILLED01: - value2 = cell.getSecondValue(); - System.out.print(" \\" + value2); - break; - default: - break; - } - if (value > 9 || value2 > 9) - System.out.print(" "); - } - System.out.println(); - } - } - - public UserActions printGetUserAction() - { - System.out.print("\nList of actions i=input s=solve a=answers\nChoose an action: "); - switch (inputReader.next()) - { - case "i": - return UserActions.INPUT; - - case "s": - return UserActions.SOLVE; - case "a": - return UserActions.ANSWERS; - default: - return UserActions.UNKNOWN; - } - } - - public void printGetInputNumber() - { - int row = -1; - int column = -1; - int number = -1; - while (true) - { - while (row < 1 || row > 10) - { - System.out.print("row: "); - try { - row = inputReader.nextInt(); - if (row < 1 || row > 10) - System.out.println("error: out of bounds"); - } - catch (java.util.InputMismatchException e) - { - System.out.println("error: invalid digit"); - inputReader.nextLine(); - } - } - while (column < 1 || column > 10) - { - System.out.print("column: "); - try { - column = inputReader.nextInt(); - if (column < 1 || column > 10) - System.out.println("error: out of bounds"); - } - catch (java.util.InputMismatchException e) - { - System.out.println("error: invalid digit"); - inputReader.nextLine(); - } - } - if (controller.model.board[row-1][column-1].getType() == BoardCell.CellType.INPUT) - break; - else { - System.out.println("error: not an input cell"); - row = -1; - column = -1; - } - } - while (number < 1 || number > 9) - { - try { - System.out.print("number: "); - number = inputReader.nextInt(); - if (number < 1 || number > 9) - System.out.println("error: out of bounds"); - } - catch (java.util.InputMismatchException e) - { - System.out.println("error: invalid digit"); - inputReader.nextLine(); - } - } - controller.model.board[row-1][column-1].setFirstValue(number); - } - - public void printSolveBoard() - { - Boolean success = controller.solveBoard(); - if (success) - System.out.println("The board is solved!"); - else - System.out.println("The solution is incorrect."); - } - - public void settingUpMenu() { - //chronoSetUp MUST be called before buttonsSetUp. - buttonMenu.chronoSetUp(); - buttonMenu.buttonsSetUp(); - } -} diff --git a/src/kakuro/Main.java b/src/kakuro/Main.java index 07f1403..4cd5da8 100644 --- a/src/kakuro/Main.java +++ b/src/kakuro/Main.java @@ -4,6 +4,8 @@ package kakuro; +import kakuro.controllers.GameController; + public class Main { public static void main(String[] args) diff --git a/src/kakuro/controllers/ChronoController.java b/src/kakuro/controllers/ChronoController.java new file mode 100644 index 0000000..7a28ece --- /dev/null +++ b/src/kakuro/controllers/ChronoController.java @@ -0,0 +1,85 @@ +package kakuro.controllers; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.JComponent; +import javax.swing.JLabel; +import javax.swing.Timer; + +import kakuro.models.ChronoModel; +import kakuro.views.ChronoView; + +public class ChronoController { + private ChronoModel chronoModel; + private ChronoView chronoView; + private ActionListener timerListener; + private Timer time; + private boolean isVisible; + + public ChronoController() { + chronoModel = new ChronoModel(); + chronoView = new ChronoView(); + + isVisible=false; + timerSetUp(); + } + + public void timerSetUp() { + timerListener= new ActionListener() + { + public void actionPerformed(ActionEvent e1) + { + chronoView.setTimerLabel(chronoModel.updateTime()); + } + }; + + chronoModel.getDelay(); + time = new Timer(chronoModel.getDelay(), timerListener); + } + + public void chronoPause() { + time.stop(); + } + + public void chronoStart() { + time.start(); + } + + public void show() { + chronoView.timerLabel.setVisible(true); + } + + public void hide() { + chronoView.timerLabel.setVisible(false); + } + + public JLabel getTimerLabel() { + return chronoView.timerLabel; + } + + public void toggleTimerDisplay() { + chronoView.timerLabel.setVisible(!isVisible); + } + + public void resetTimer() { + chronoModel.resetTimer(); + chronoView.timerLabel.setText("0:0:0:0"); + } + + public int getHours() { + return chronoModel.getHours(); + } + + public int getMinutes() { + return chronoModel.getMinutes(); + } + + public int getSeconds() { + return chronoModel.getSeconds(); + } + + public JComponent getView() { + return chronoView.timerLabel; + } +} diff --git a/src/kakuro/GameController.java b/src/kakuro/controllers/GameController.java similarity index 69% rename from src/kakuro/GameController.java rename to src/kakuro/controllers/GameController.java index afacc72..27b5f8b 100644 --- a/src/kakuro/GameController.java +++ b/src/kakuro/controllers/GameController.java @@ -2,14 +2,19 @@ // @author Nalveer Moocheet // @brief Game controller class which handles the Kakuro game. -package kakuro; +package kakuro.controllers; +import kakuro.core.Cell; +import kakuro.core.DatabaseConnection; import kakuro.game.dao.GameDao; import kakuro.game.dao.GameDaoImpl; import kakuro.gameprogress.dao.GameProgressDao; import kakuro.gameprogress.dao.GameProgressDaoImpl; -import kakuro.utils.DatabaseConnection; +import kakuro.models.GameModel; +import kakuro.views.GameConsole; +import kakuro.views.GameView; +import java.awt.BorderLayout; import java.sql.Connection; import java.sql.SQLException; import java.util.ArrayList; @@ -26,6 +31,15 @@ public class GameController public GameView view; public GameModel model; private Boolean gui = true; + + //Sub-views controller + private ChronoController chronoController; + //public BoardController boardController; + public MenuBarController buttonMenuController; + + public GameConsole console; + + public boolean isPaused = false; public enum UserActions { @@ -54,33 +68,35 @@ private void initGame(GameModel model) model.initBoard(); - this.view = new GameView(this, gui); + //Currently the view must be loaded the first to populate the data + chronoController = new ChronoController(); + //boardController = new BoardController(model.rows, model.columns, this); + buttonMenuController = new MenuBarController(this); - view.printStartup(); - view.printBoard(false/*show answer values*/); - if (gui){ - view.board_ui(); - view.settingUpMenu(); - } + this.view = new GameView(this, gui, chronoController.getView(), buttonMenuController.getView());; + this.console = new GameConsole(this); + + console.printStartup(); + console.printBoard(false/*show answer values*/); } public void loopGame() { while (true) { - switch (view.printGetUserAction()) + switch (console.printGetUserAction()) { case INPUT: - view.printGetInputNumber(); - view.printBoard(false/*show answer values*/); + console.printGetInputNumber(); + console.printBoard(false/*show answer values*/); break; case SOLVE: if (gui) - view.loadInputInModel(); - view.printSolveBoard(); + loadInputInModel(false); + console.printSolveBoard(); break; case ANSWERS: - view.printBoard(true/*show answer values*/); + console.printBoard(true/*show answer values*/); break; case UNKNOWN: default: @@ -104,6 +120,8 @@ public void disconnectDatabase() { public void saveGame() { try { + chronoController.chronoPause(); + loadInputInModel(false); //TODO: fixed player and to fix in iteration 3 gameProgress.save(getDatabaseConnection(), "TestPlayer", model.board); @@ -113,20 +131,20 @@ public void saveGame() { } } - public BoardCell[][] loadGame() { + public Cell[][] loadGame() { try { //TODO: fixed player and to fix in iteration 3 - BoardCell[][] boardCell = gameProgress.load(getDatabaseConnection(), "TestPlayer"); + Cell[][] boardCell = gameProgress.load(getDatabaseConnection(), "TestPlayer"); if(boardCell != null) { model.board = boardCell; System.out.println("Successfully loaded game progress"); - view.printStartup(); - view.printBoard(false); + console.printStartup(); + console.printBoard(false); if (gui){ - view.board_ui(); + view.updateView(); } return model.board; @@ -142,16 +160,21 @@ public BoardCell[][] loadGame() { public void loadPreconfiguredGame(int gameLevel) { try { - ArrayList boardCells = game.loadAllPreconfiguredGames(getDatabaseConnection()); + ArrayList boardCells = game.loadAllPreconfiguredGames(getDatabaseConnection()); + //Load the new game model model.board = boardCells.get(gameLevel-1); - - view.printStartup(); - view.printBoard(false); + console.printStartup(); + console.printBoard(false); if (gui){ - view.board_ui(); + //Update the new view + view.updateView(); + + //Start the timer + chronoController.show(); + chronoController.chronoStart(); } } catch(SQLException e) { @@ -181,7 +204,7 @@ public Boolean solveBoard() int sum = 0; map = new HashMap(); //continues to add horizontally until next cell is not an INPUT type - while(column <= model.columns && model.board[i][column].getType()==BoardCell.CellType.INPUT) { //horizontal sum check + while(column <= model.columns && model.board[i][column].getType()==Cell.CellType.INPUT) { //horizontal sum check int cell = model.board[i][column].getFirstValue(); //getting cell value @@ -212,7 +235,7 @@ public Boolean solveBoard() int sum = 0; map = new HashMap(); - while(row <= model.rows && model.board[row][j].getType()==BoardCell.CellType.INPUT) { + while(row <= model.rows && model.board[row][j].getType()==Cell.CellType.INPUT) { int cell = model.board[row][j].getFirstValue(); @@ -243,7 +266,7 @@ public Boolean solveBoard() int sumColumns = 0; map = new HashMap(); //checking row sum - while(column <= model.columns && model.board[i][column].getType()==BoardCell.CellType.INPUT) { //horizontal sum check + while(column <= model.columns && model.board[i][column].getType()==Cell.CellType.INPUT) { //horizontal sum check int cell = model.board[i][column].getFirstValue(); @@ -260,7 +283,7 @@ public Boolean solveBoard() map.clear(); //checking column sum - while(row <= model.rows && model.board[row][j].getType()==BoardCell.CellType.INPUT) { //vertical sum check + while(row <= model.rows && model.board[row][j].getType()==Cell.CellType.INPUT) { //vertical sum check int cell = model.board[row][j].getFirstValue(); @@ -305,16 +328,16 @@ public Boolean solveBoard() } public void loadInputInModel(boolean clearInput) { - JTextField[][] saveInput = view.saveInput; + JTextField[][] saveInput = view.getSavedInput(); String value; for(int row = 0; row < model.columns; row++) { for(int column = 0; column < model.rows; column++) { - BoardCell cell = model.board[row][column]; + Cell cell = model.board[row][column]; - if (cell.getType() == BoardCell.CellType.INPUT) + if (cell.getType() == Cell.CellType.INPUT) { if(clearInput) { saveInput[row][column].setText(""); @@ -329,4 +352,42 @@ public void loadInputInModel(boolean clearInput) { } } } + + public void pause() { + isPaused = true; + chronoController.chronoPause(); + view.hideBoard(); + } + + public void resume() { + isPaused = false; + chronoController.chronoStart(); + view.showBoard(); + } + + public void restart() { + chronoController.resetTimer(); + chronoController.chronoStart(); + loadInputInModel(true); //Clear inputs + } + + public void submit() { + chronoController.chronoPause(); + loadInputInModel(false); //No clearing inputs + solveBoard(); + console.printSolveBoard(); + } + + //Number formatter + public int getMinNumberValid() { + return view.getMinNumberValid(); + } + + public Object getNumberFormatterClassType() { + return view.getNumberFormatterClassType(); + } + + public int getMaxNumberValid() { + return view.getMaxNumberValid(); + } } diff --git a/src/kakuro/controllers/MenuBarController.java b/src/kakuro/controllers/MenuBarController.java new file mode 100644 index 0000000..8fa04e4 --- /dev/null +++ b/src/kakuro/controllers/MenuBarController.java @@ -0,0 +1,59 @@ +package kakuro.controllers; + +import javax.swing.JComponent; + +import kakuro.core.Cell; +import kakuro.core.GameDifficulty; +import kakuro.views.MenuBarView; + +public class MenuBarController { + GameController appController; + + private MenuBarView buttonMenuView; + private boolean isPaused; + + public MenuBarController(GameController appController){ + this.appController = appController; + buttonMenuView = new MenuBarView(this); + } + + public MenuBarView getButtonMenuView() { + return buttonMenuView; + } + + public boolean isPaused() { + return appController.isPaused; + } + + public void pause() { + appController.pause(); + } + + public void resume() { + appController.resume(); + } + + public JComponent getView() { + return buttonMenuView.mainPanel; + } + + public void submit() { + appController.submit(); + } + + public void save() { + appController.saveGame(); + } + + public Cell[][] load() { + return appController.loadGame(); + } + + public void loadPreconfiguredGame(GameDifficulty gameLevel) { + appController.loadPreconfiguredGame(GameDifficulty.GameDifficultyToInt(gameLevel)); + } + + public void restart() { + appController.restart(); + } +} diff --git a/src/kakuro/BoardCell.java b/src/kakuro/core/Cell.java similarity index 67% rename from src/kakuro/BoardCell.java rename to src/kakuro/core/Cell.java index 9df167d..be5a8b8 100644 --- a/src/kakuro/BoardCell.java +++ b/src/kakuro/core/Cell.java @@ -1,11 +1,11 @@ // @author Vsevolod Ivanov // @author ... -package kakuro; +package kakuro.core; -public class BoardCell +public class Cell { - enum CellType + public enum CellType { EMPTY, /* | | */ INPUT, /* | | */ @@ -18,40 +18,40 @@ enum CellType private int value1 = -1; private int value2 = -1; - BoardCell(CellType type) + public Cell(CellType type) { this.type = type; }; - BoardCell(CellType type, int value1) + public Cell(CellType type, int value1) { this.type = type; this.value1 = value1; } - BoardCell(CellType type, int value1, int value2) + public Cell(CellType type, int value1, int value2) { this.type = type; this.value1 = value1; this.value2 = value2; } - int getFirstValue() + public int getFirstValue() { return this.value1; } - int getSecondValue() + public int getSecondValue() { return this.value2; } - void setFirstValue(int value) + public void setFirstValue(int value) { this.value1 = value; } - CellType getType() + public CellType getType() { return this.type; } diff --git a/src/kakuro/utils/DatabaseConnection.java b/src/kakuro/core/DatabaseConnection.java similarity index 99% rename from src/kakuro/utils/DatabaseConnection.java rename to src/kakuro/core/DatabaseConnection.java index e0c2051..5c7cd8a 100644 --- a/src/kakuro/utils/DatabaseConnection.java +++ b/src/kakuro/core/DatabaseConnection.java @@ -1,6 +1,6 @@ //@author Brian Gamboc-Javiniar and Nolan Mckay -package kakuro.utils; +package kakuro.core; import java.io.File; import java.sql.Connection; diff --git a/src/kakuro/core/GameDifficulty.java b/src/kakuro/core/GameDifficulty.java new file mode 100644 index 0000000..96b37fa --- /dev/null +++ b/src/kakuro/core/GameDifficulty.java @@ -0,0 +1,26 @@ +/* @author Hoang Thuan Pham + * Date created: March 9th, 2020 + * Enumerator: GameDifficulty + * Description: An enumerator for different levels of game difficulties +*/ + + +package kakuro.core; + +public enum GameDifficulty { + EASY, //Easy game difficulty + MEDIUM, //Medium game difficulty + DIFFICULT; //Difficult game difficulty + + /*Convert the enumerator to an integer. The method is to support database storage where enumerators are not supported. + * @param: an enumerator type + * @return: the corresponding integer to an enumerator value + * */ + public static int GameDifficultyToInt(GameDifficulty difficulty) { + switch(difficulty) { + case EASY: return 1; + case MEDIUM: return 2; + default: return 3; + } + } +} diff --git a/src/kakuro/core/GameDifficultyListItem.java b/src/kakuro/core/GameDifficultyListItem.java new file mode 100644 index 0000000..5c16272 --- /dev/null +++ b/src/kakuro/core/GameDifficultyListItem.java @@ -0,0 +1,19 @@ +package kakuro.core; + +public class GameDifficultyListItem { + private String description; + private GameDifficulty difficulty; + + public GameDifficultyListItem(String description, GameDifficulty difficulty) { + this.description = description; + this.difficulty = difficulty; + } + + public GameDifficulty getDifficulty() { + return difficulty; + } + + public String toString() { + return description; + } +} diff --git a/src/kakuro/line_panel.java b/src/kakuro/core/LinePanel.java similarity index 90% rename from src/kakuro/line_panel.java rename to src/kakuro/core/LinePanel.java index 5ab2cd5..030f515 100644 --- a/src/kakuro/line_panel.java +++ b/src/kakuro/core/LinePanel.java @@ -3,7 +3,7 @@ // @brief class used to populate non-playable board cells: adds numbers and diagonal line // class extending JPanel to use the graphics with paintComponent method overriding -package kakuro; +package kakuro.core; import java.awt.BasicStroke; import java.awt.BorderLayout; @@ -23,10 +23,10 @@ * https://docs.oracle.com/javase/8/docs/api/javax/swing/JFormattedTextField.html */ -public class line_panel extends JPanel { +public class LinePanel extends JPanel { //constructor used if only one number in the cell - public line_panel(LayoutManager layout, JTextField textField, Boolean align) { + public LinePanel(LayoutManager layout, JTextField textField, Boolean align) { super(layout); this.setBackground(Color.black); settingTxt(textField); @@ -41,7 +41,7 @@ public line_panel(LayoutManager layout, JTextField textField, Boolean align) { } //constructor used if two numbers in the cell - public line_panel(LayoutManager layout, JTextField textFieldLEFT, JTextField textFieldRIGHT) { + public LinePanel(LayoutManager layout, JTextField textFieldLEFT, JTextField textFieldRIGHT) { super(layout); this.setBackground(Color.black); diff --git a/src/kakuro/Tools.java b/src/kakuro/core/Tools.java similarity index 98% rename from src/kakuro/Tools.java rename to src/kakuro/core/Tools.java index 31d593b..be1a618 100644 --- a/src/kakuro/Tools.java +++ b/src/kakuro/core/Tools.java @@ -1,7 +1,7 @@ //@author Vsevolod Ivanov //@author ... -package kakuro; +package kakuro.core; import java.util.Enumeration; import java.util.Random; diff --git a/src/kakuro/UniquePartitions.java b/src/kakuro/core/UniquePartitions.java similarity index 98% rename from src/kakuro/UniquePartitions.java rename to src/kakuro/core/UniquePartitions.java index 9d66c26..078c906 100644 --- a/src/kakuro/UniquePartitions.java +++ b/src/kakuro/core/UniquePartitions.java @@ -5,15 +5,15 @@ // Level 2 : possible sums for that number of cells // Level 3 : an array of its values representing consecutively cells values from smallest to largest -package kakuro; +package kakuro.core; import javax.swing.tree.DefaultMutableTreeNode; public class UniquePartitions { - DefaultMutableTreeNode root; + public DefaultMutableTreeNode root; - UniquePartitions() + public UniquePartitions() { this.root = new DefaultMutableTreeNode(0); fillCombinations(this.root); diff --git a/src/kakuro/game/dao/GameDao.java b/src/kakuro/game/dao/GameDao.java index 3acb354..a74bbfd 100644 --- a/src/kakuro/game/dao/GameDao.java +++ b/src/kakuro/game/dao/GameDao.java @@ -6,7 +6,7 @@ import java.sql.SQLException; import java.util.ArrayList; -import kakuro.BoardCell; +import kakuro.core.Cell; public interface GameDao { @@ -17,5 +17,5 @@ public interface GameDao { * - the database connection * @return BoardCell object */ - ArrayList loadAllPreconfiguredGames(Connection conn) throws SQLException; + ArrayList loadAllPreconfiguredGames(Connection conn) throws SQLException; } diff --git a/src/kakuro/game/dao/GameDaoImpl.java b/src/kakuro/game/dao/GameDaoImpl.java index 7893939..62aa8e2 100644 --- a/src/kakuro/game/dao/GameDaoImpl.java +++ b/src/kakuro/game/dao/GameDaoImpl.java @@ -10,15 +10,15 @@ import com.google.gson.Gson; -import kakuro.BoardCell; +import kakuro.core.Cell; public class GameDaoImpl implements GameDao { private final String LOAD_ALL_PRECONFIGURED_GAMES = "SELECT cells FROM game"; @Override - public ArrayList loadAllPreconfiguredGames(Connection conn) throws SQLException { + public ArrayList loadAllPreconfiguredGames(Connection conn) throws SQLException { Gson gson = new Gson(); - ArrayList boardCells = new ArrayList(); + ArrayList boardCells = new ArrayList(); PreparedStatement pstmt = conn.prepareStatement(LOAD_ALL_PRECONFIGURED_GAMES); @@ -27,7 +27,7 @@ public ArrayList loadAllPreconfiguredGames(Connection conn) throw while(rs.next()) { String cells = rs.getString("cells"); - boardCells.add(gson.fromJson(cells, BoardCell[][].class)); + boardCells.add(gson.fromJson(cells, Cell[][].class)); } return boardCells; diff --git a/src/kakuro/gameprogress/dao/GameProgressDao.java b/src/kakuro/gameprogress/dao/GameProgressDao.java index 2750c12..0ee6aa1 100644 --- a/src/kakuro/gameprogress/dao/GameProgressDao.java +++ b/src/kakuro/gameprogress/dao/GameProgressDao.java @@ -4,7 +4,8 @@ import java.sql.Connection; import java.sql.SQLException; -import kakuro.BoardCell; + +import kakuro.core.Cell; public interface GameProgressDao { /** @@ -15,7 +16,7 @@ public interface GameProgressDao { * @param uid * - the username of the player */ - void save(Connection conn, String uid, BoardCell[][] board) throws SQLException; + void save(Connection conn, String uid, Cell[][] board) throws SQLException; /** * @@ -26,5 +27,5 @@ public interface GameProgressDao { * - the username of the player * @return BoardCell object */ - BoardCell[][] load(Connection conn, String uid) throws SQLException; + Cell[][] load(Connection conn, String uid) throws SQLException; } diff --git a/src/kakuro/gameprogress/dao/GameProgressDaoImpl.java b/src/kakuro/gameprogress/dao/GameProgressDaoImpl.java index 3bdb93b..35e5921 100644 --- a/src/kakuro/gameprogress/dao/GameProgressDaoImpl.java +++ b/src/kakuro/gameprogress/dao/GameProgressDaoImpl.java @@ -8,14 +8,14 @@ import java.sql.SQLException; import com.google.gson.*; -import kakuro.BoardCell; +import kakuro.core.Cell; public class GameProgressDaoImpl implements GameProgressDao { private final String SAVE_GAME_PROGRESS = "UPDATE game_progress SET cells=? WHERE username=?"; private final String LOAD_GAME_PROGRESS = "SELECT cells FROM game_progress WHERE username=?"; @Override - public void save(Connection conn, String uid, BoardCell[][] board) throws SQLException { + public void save(Connection conn, String uid, Cell[][] board) throws SQLException { Gson gson = new Gson(); String boardCellJSON = gson.toJson(board); @@ -27,7 +27,7 @@ public void save(Connection conn, String uid, BoardCell[][] board) throws SQLExc } @Override - public BoardCell[][] load(Connection conn, String uid) throws SQLException { + public Cell[][] load(Connection conn, String uid) throws SQLException { Gson gson = new Gson(); PreparedStatement pstmt = conn.prepareStatement(LOAD_GAME_PROGRESS); @@ -38,7 +38,7 @@ public BoardCell[][] load(Connection conn, String uid) throws SQLException { if(rs.next()) { String cells = rs.getString("cells"); - return gson.fromJson(cells, BoardCell[][].class); + return gson.fromJson(cells, Cell[][].class); } return null; diff --git a/src/kakuro/Chrono.java b/src/kakuro/models/ChronoModel.java similarity index 56% rename from src/kakuro/Chrono.java rename to src/kakuro/models/ChronoModel.java index 43e2cd9..113d456 100644 --- a/src/kakuro/Chrono.java +++ b/src/kakuro/models/ChronoModel.java @@ -1,43 +1,37 @@ -package kakuro; +package kakuro.models; //@author Audrey St-Louis //@brief Timer class import javax.swing.*; +import javax.swing.border.EmptyBorder; import java.awt.BorderLayout; +import java.awt.Font; import java.awt.event.*; -public class Chrono +public class ChronoModel { - private int hours=0; - private int minutes=0; - private int seconds=0; - private int delay=1000; - JLabel timerLabel; - ActionListener timerListener; - Timer time; + private int hours; + private int minutes; + private int seconds; + private int delay; + /* Constructor : Creates all the UI components and add them on the panel. */ - public Chrono() + public ChronoModel() { - timerLabel = new JLabel("0:"+hours+":"+minutes+":"+seconds); - } - - public JLabel getTimerLabel() { - - return timerLabel; - } - public void validation() { - + hours=0; + minutes=0; + seconds=0; + delay=1000; } - + /* Checks if the user have clicked on a button. If he clicks on pause, the timer will stop. If he clicks on start, the timer will start. If * he clicks on new game, the timer will restart and a new grid will appear on the screen. * The timer is set to start automatically when the application is launched since a game will already be ready to play. * Need to implement : Save feature */ - - public void checkTime() { + public String updateTime() { seconds++; if(seconds==60) { @@ -49,43 +43,15 @@ public void checkTime() { minutes=0; hours++; } - timerLabel.setText("0:"+hours+":"+minutes+":"+seconds); + + return "0:"+hours+":"+minutes+":"+seconds; } - + //Getters and setters public int getDelay() { return this.delay; } - - public void timerSetUp() { - timerListener= new ActionListener() - { - public void actionPerformed(ActionEvent e1) - { - checkTime(); - } - }; - - time = new Timer(delay,timerListener); - time.start(); - } - - public void chronoPause() { - time.stop(); - } - - public void chronoStart() { - time.start(); - } - - public void resetTimer() { - hours=0; - minutes=0; - seconds=0; - timerLabel.setText("0:"+hours+":"+minutes+":"+seconds); - } - public int getHours() { return hours; } @@ -109,5 +75,11 @@ public int getSeconds() { public void setSeconds(int seconds) { this.seconds = seconds; } + + public void resetTimer() { + hours=0; + minutes=0; + seconds=0; + } } diff --git a/src/kakuro/models/GameModel.java b/src/kakuro/models/GameModel.java new file mode 100644 index 0000000..b2c0dd4 --- /dev/null +++ b/src/kakuro/models/GameModel.java @@ -0,0 +1,41 @@ +// @author Vsevolod Ivanov +// @author ... +// @brief Game model class which handles the Kakuro game storage. + +package kakuro.models; + +import java.util.Enumeration; + +import javax.swing.JTextField; +import javax.swing.tree.TreeNode; + +import kakuro.core.*; + +public class GameModel +{ + + public final int columns; + public final int rows; + public Cell[][] board; + private static UniquePartitions partitions; + + public GameModel(final int columns, final int rows) + { + this.columns = columns; + this.rows = rows; + partitions = new UniquePartitions(); + } + + public void initBoard() + { + board = new Cell[this.rows][this.columns]; + + for(int row = 0; row < this.rows; row++) + { + for(int column = 0; column < this.columns; column++) + { + board[row][column] = new Cell(Cell.CellType.EMPTY); + } + } + } +} diff --git a/src/kakuro/PlayerModel.java b/src/kakuro/models/PlayerModel.java similarity index 96% rename from src/kakuro/PlayerModel.java rename to src/kakuro/models/PlayerModel.java index 2c77c87..3c8b0b0 100644 --- a/src/kakuro/PlayerModel.java +++ b/src/kakuro/models/PlayerModel.java @@ -1,4 +1,4 @@ -package kakuro; +package kakuro.models; //TODO: iteration 3 work public class PlayerModel { diff --git a/src/kakuro/views/ChronoView.java b/src/kakuro/views/ChronoView.java new file mode 100644 index 0000000..6c212a7 --- /dev/null +++ b/src/kakuro/views/ChronoView.java @@ -0,0 +1,28 @@ +package kakuro.views; + +import java.awt.Font; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.JLabel; +import javax.swing.SwingConstants; +import javax.swing.Timer; +import javax.swing.border.EmptyBorder; + +import kakuro.models.ChronoModel; + +public class ChronoView { + + public JLabel timerLabel; + + public ChronoView() { + timerLabel = new JLabel("0:0:0:0", SwingConstants.CENTER); + timerLabel.setFont(new Font(timerLabel.getFont().getFontName(), Font.PLAIN, 20)); + timerLabel.setVisible(false); + timerLabel.setBorder(new EmptyBorder(10,0,10,0));//top,left,bottom,right + } + + public void setTimerLabel(String label) { + timerLabel.setText(label); + } +} diff --git a/src/kakuro/views/GameConsole.java b/src/kakuro/views/GameConsole.java new file mode 100644 index 0000000..481acf4 --- /dev/null +++ b/src/kakuro/views/GameConsole.java @@ -0,0 +1,151 @@ +package kakuro.views; + +import java.util.Scanner; + +import kakuro.controllers.GameController; +import kakuro.controllers.GameController.UserActions; +import kakuro.core.*; + +public class GameConsole { + private GameController controller; + private Scanner inputReader = new Scanner(System.in); + + public GameConsole(final GameController controller) { + this.controller = controller; + } + + public void printStartup() + { + System.out.println("welcome to kakuro game!"); + System.out.println("=> use numbers between 1-9 to fill the cells;"); + } + + public void printBoard(Boolean showAnswerValues) + { + System.out.println("board:"); + for(int row = 0; row < controller.model.rows; row++) + { + for(int column = 0; column < controller.model.columns; column++) + { + int value = 0; + int value2 = 0; + Cell cell = controller.model.board[row][column]; + switch (cell.getType()) + { + case EMPTY: + System.out.print(" x "); + break; + case INPUT: + System.out.print(" " + + (showAnswerValues ? (cell.getSecondValue() != -1 ? cell.getSecondValue() : "_") : + (cell.getFirstValue() != -1 ? cell.getFirstValue() : "_")) + + " "); + break; + case FILLED11: + value = cell.getFirstValue(); + value2 = cell.getSecondValue(); + System.out.print(" " + value + "\\" + value2); + break; + case FILLED10: + value = cell.getFirstValue(); + System.out.print(" " + value + "\\"); + break; + case FILLED01: + value2 = cell.getSecondValue(); + System.out.print(" \\" + value2); + break; + default: + break; + } + if (value > 9 || value2 > 9) + System.out.print(" "); + } + System.out.println(); + } + } + + public UserActions printGetUserAction() + { + System.out.print("\nList of actions i=input s=solve a=answers\nChoose an action: "); + switch (inputReader.next()) + { + case "i": + return UserActions.INPUT; + + case "s": + return UserActions.SOLVE; + case "a": + return UserActions.ANSWERS; + default: + return UserActions.UNKNOWN; + } + } + + public void printGetInputNumber(){ + int row = -1; + int column = -1; + int number = -1; + while (true) + { + while (row < 1 || row > 10) + { + System.out.print("row: "); + try { + row = inputReader.nextInt(); + if (row < 1 || row > 10) + System.out.println("error: out of bounds"); + } + catch (java.util.InputMismatchException e) + { + System.out.println("error: invalid digit"); + inputReader.nextLine(); + } + } + while (column < 1 || column > 10) + { + System.out.print("column: "); + try { + column = inputReader.nextInt(); + if (column < 1 || column > 10) + System.out.println("error: out of bounds"); + } + catch (java.util.InputMismatchException e) + { + System.out.println("error: invalid digit"); + inputReader.nextLine(); + } + } + if (controller.model.board[row-1][column-1].getType() == Cell.CellType.INPUT) + break; + else { + System.out.println("error: not an input cell"); + row = -1; + column = -1; + } + } + while (number < 1 || number > 9) + { + try { + System.out.print("number: "); + number = inputReader.nextInt(); + if (number < 1 || number > 9) + System.out.println("error: out of bounds"); + } + catch (java.util.InputMismatchException e) + { + System.out.println("error: invalid digit"); + inputReader.nextLine(); + } + } + controller.model.board[row-1][column-1].setFirstValue(number); + } + + public void printSolveBoard() + { + Boolean success = controller.solveBoard(); + if (success) + System.out.println("The board is solved!"); + else + System.out.println("The solution is incorrect."); + } +} diff --git a/src/kakuro/views/GameView.java b/src/kakuro/views/GameView.java new file mode 100644 index 0000000..cbf673f --- /dev/null +++ b/src/kakuro/views/GameView.java @@ -0,0 +1,214 @@ +// @author Vsevolod Ivanov +// @author Isabelle Charette +// @brief Game view class which handles the Kakuro game interface. + +package kakuro.views; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Font; +import java.awt.GridLayout; +import java.text.NumberFormat; +import java.util.Scanner; + +import javax.swing.JComponent; +import javax.swing.JFormattedTextField; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTextField; +import javax.swing.SwingConstants; +import javax.swing.border.LineBorder; +import javax.swing.text.NumberFormatter; + +import kakuro.controllers.GameController; +import kakuro.controllers.GameController.UserActions; +import kakuro.controllers.MenuBarController; +import kakuro.controllers.ChronoController; +import kakuro.core.Cell; +import kakuro.core.LinePanel; + +public class GameView +{ + private GameController controller; + + //UI components + JTextField[][] cells; + JPanel currentBoard; + + //Main application frame and properties + JFrame frame; + int gridSizeX; + int gridSizeY; + + //Number formatter for displaying + NumberFormat numberFormat = NumberFormat.getInstance(); + NumberFormatter numberFormatter = new NumberFormatter(numberFormat); + + public GameView(final GameController controller, Boolean X11, JComponent chronoLabel, JComponent menuBar) + { + //Initialize number formatter + numberFormatter.setValueClass(Integer.class); + numberFormatter.setMinimum(1); + numberFormatter.setMaximum(9); + + if (controller != null) + { + this.controller = controller; + gridSizeX = controller.model.rows; + gridSizeY = controller.model.columns; + } + + if (X11) { + frame = new JFrame("KAKURO"); + //buttonMenu = new ButtonMenuView(frame, gridSizeX, gridSizeY, controller); + + //Initialize the application frame + int frameSize = 60; + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + int x = frameSize*gridSizeX; + int y = frameSize*gridSizeY; + frame.setSize(x, y); + frame.setResizable(false); + + //Create a timer at the top + frame.getContentPane().add(chronoLabel, BorderLayout.BEFORE_FIRST_LINE); + //Main game UI stays at the center + currentBoard = getBoardUI(controller.model.board); + frame.getContentPane().add(currentBoard); + //Button menu stays at the bottom + frame.getContentPane().add(menuBar, BorderLayout.AFTER_LAST_LINE); + + frame.pack(); + frame.setSize(x,y); + frame.setVisible(true); + } + } + + public JPanel getBoardUI(Cell[][] board) { + //creating grid of cells + cells = new JTextField[gridSizeX][gridSizeY]; + JPanel panel = new JPanel(new GridLayout(gridSizeX,gridSizeY)); + //creating window of the game + + //this allows temporary invalid input, particularly to be able to delete and try again + //if invalid input, when clicking onto another cell, the input will be deleted + numberFormatter.setAllowsInvalid(true); + + //identifies type of each cell and populates it + //input or non-playable + for(int row = 0; row < gridSizeX; row++) + { + for(int column = 0; column < gridSizeY; column++) + { + JFormattedTextField textField = null; + + //tracking the type of each cell + Cell cell = board[row][column]; + //adding extra panel that will overlay the cells that are non-playable with game level numbers and diagonal line + JPanel diagonalPanel = null; + + //according to type of cell, populate + switch (cell.getType()) + { + case EMPTY: + textField = new JFormattedTextField(numberFormatter); + settingTextField(textField); + textField.setBorder(new LineBorder(Color.GRAY,1)); + panel.add(textField); + break; + + case INPUT: + textField = new JFormattedTextField(numberFormatter); + textField.setHorizontalAlignment(JTextField.CENTER); + textField.setBorder(new LineBorder(Color.GRAY,1)); + //When you load a game, there is some data exists. We have to check to make sure we are displaying the saved input + if(cell.getFirstValue()!=-1) + textField.setValue(cell.getFirstValue()); + panel.add(textField); + break; + + case FILLED01: + textField = new JFormattedTextField(cell.getSecondValue()); + settingTextField(textField); + //adding diagonal line in board cell + diagonalPanel = new LinePanel(new BorderLayout(), textField, true); + diagonalPanel.setBorder(new LineBorder(Color.GRAY,1)); + panel.add(diagonalPanel); + break; + + case FILLED10: + textField = new JFormattedTextField(cell.getFirstValue()); + settingTextField(textField); + //adding diagonal line in board cell + diagonalPanel = new LinePanel(new BorderLayout(), textField, false); + diagonalPanel.setBorder(new LineBorder(Color.GRAY,1)); + panel.add(diagonalPanel); + break; + + case FILLED11: + textField = new JFormattedTextField(cell.getFirstValue()); + JFormattedTextField textFieldRIGHT = new JFormattedTextField(cell.getSecondValue()); + settingTextField(textField); + settingTextField(textFieldRIGHT); + //using constructor that expects two text values to place in board cell + diagonalPanel = new LinePanel(new BorderLayout(), textField, textFieldRIGHT); + diagonalPanel.setBorder(new LineBorder(Color.GRAY,1)); + panel.add(diagonalPanel); + break; + + default: + break; + } + + //placing textfield value in input array to track user input + this.cells[row][column] = textField; + } + } + + return panel; + } + + public JTextField[][] getSavedInput(){ + return cells; + } + + public void settingTextField(JTextField txt) { + txt.setBackground(Color.black); + txt.setForeground(Color.white); + txt.setBorder(javax.swing.BorderFactory.createEmptyBorder()); + txt.setEditable(false); + } + + public void updateView() { + //If a panel is already attached to the frame, remove it + JPanel newBoardPanel = getBoardUI(controller.model.board); + if(currentBoard != null) + frame.getContentPane().remove(currentBoard); + + //Save a reference to the new panel + frame.getContentPane().add(newBoardPanel); + currentBoard = newBoardPanel;; + } + + public void showBoard() { + currentBoard.setVisible(true); + } + + public void hideBoard() { + currentBoard.setVisible(false); + } + + //Number formatter methods + public int getMinNumberValid() { + return (int) numberFormatter.getMinimum(); + } + + public Object getNumberFormatterClassType() { + return numberFormatter.getClass(); + } + + public int getMaxNumberValid() { + return (int) numberFormatter.getMaximum(); + } +} diff --git a/src/kakuro/ButtonMenu.java b/src/kakuro/views/MenuBarView.java similarity index 52% rename from src/kakuro/ButtonMenu.java rename to src/kakuro/views/MenuBarView.java index 8a254d2..163afc0 100644 --- a/src/kakuro/ButtonMenu.java +++ b/src/kakuro/views/MenuBarView.java @@ -1,4 +1,4 @@ -package kakuro; +package kakuro.views; import java.awt.BorderLayout; import java.awt.event.ActionEvent; @@ -9,69 +9,54 @@ import javax.swing.JOptionPane; import javax.swing.JPanel; -public class ButtonMenu { +import kakuro.controllers.ChronoController; +import kakuro.controllers.GameController; +import kakuro.controllers.MenuBarController; +import kakuro.core.GameDifficulty; +import kakuro.core.GameDifficultyListItem; + +public class MenuBarView { + //Controller + MenuBarController menuBarController; + + //UI components JButton pause_button; - JButton play_button; JButton submit_button; - JButton newGame_button; JButton choose_game_button; JButton save_button; JButton restart_button; JButton load_button; - JPanel mainPanel; - Chrono chrono; - public Chrono getChrono() { - return chrono; - } - - public void setChrono(Chrono chrono) { - this.chrono = chrono; - } - - GameController gameController; + public JPanel mainPanel; - - public ButtonMenu(JFrame appFrame, int x, int y, GameController gameController) { - this.gameController = gameController; + public MenuBarView(MenuBarController menuBarController) { + this.menuBarController = menuBarController; + + //Initialize the buttons pause_button = new JButton("Pause"); - play_button = new JButton("Play"); submit_button = new JButton("Submit"); - newGame_button = new JButton("New Game"); - choose_game_button = new JButton("Choose a game"); + choose_game_button = new JButton("New Game"); save_button = new JButton("Save"); restart_button = new JButton("Restart"); load_button = new JButton("Load Game"); mainPanel = new JPanel(); - chrono = new Chrono(); - - // Set up - mainPanel.add(play_button).setVisible(false); + + //Set up the event listeners + buttonsSetUp(); + + //Set up visibility and add the buttons to a panel mainPanel.add(pause_button).setVisible(false); - mainPanel.add(restart_button); + mainPanel.add(restart_button).setVisible(false);; mainPanel.add(submit_button).setVisible(false); mainPanel.add(choose_game_button); mainPanel.add(save_button).setVisible(false); mainPanel.add(load_button); - - if (appFrame != null) - { - appFrame.getContentPane().add(chrono.getTimerLabel(), BorderLayout.BEFORE_FIRST_LINE); - appFrame.getContentPane().add(mainPanel, BorderLayout.AFTER_LAST_LINE); - appFrame.pack(); - appFrame.setSize(x,y); - appFrame.setVisible(true); - } - } - - public void chronoSetUp() { - chrono.timerSetUp(); } private void toggleMenu() { - play_button.setVisible(true); pause_button.setVisible(true); submit_button.setVisible(true); save_button.setVisible(true); + restart_button.setVisible(true); choose_game_button.setVisible(false); load_button.setVisible(false); @@ -84,26 +69,14 @@ public void buttonsSetUp() { { public void actionPerformed(ActionEvent e) { - chrono.chronoPause(); - } - }); - - /* With the use of an Action Listener to know if the user has clicked on the button, this part of the method will start the timer. */ - play_button.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent e) - { - chrono.chronoStart(); - } - }); - - /* With the use of an Action Listener to know if the user has clicked on the button, this part of the loop method will restart the timer. */ - newGame_button.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent e) - { - chrono.resetTimer(); - chrono.chronoStart(); + if(!menuBarController.isPaused()) { + pause_button.setText("Resume"); + menuBarController.pause(); + } + else { + pause_button.setText("Pause"); + menuBarController.resume(); + } } }); @@ -112,11 +85,7 @@ public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) { - chrono.chronoPause(); - //loads data into model - gameController.loadInputInModel(false); //No clearing inputs - gameController.solveBoard(); - gameController.view.printSolveBoard(); + menuBarController.submit(); } }); @@ -127,10 +96,7 @@ public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) { - chrono.chronoPause(); - gameController.view.loadInputInModel(); - - gameController.saveGame(); + menuBarController.save(); } }); @@ -142,11 +108,11 @@ public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) { - if(gameController.loadGame() != null) { + if(menuBarController.load() != null) { JOptionPane.showMessageDialog(null, "Successfully loaded saved game!"); toggleMenu(); } else { - JOptionPane.showMessageDialog(null, "You do not have any saved game!", "Not Found", JOptionPane.ERROR_MESSAGE); + JOptionPane.showMessageDialog(null, "You do not have any saved game!", "Not Found", JOptionPane.ERROR_MESSAGE); } } }); @@ -161,14 +127,15 @@ public void actionPerformed(ActionEvent e) { //TODO: hardcoded for now and need other boards solution boards -iteration 2 UI - Object[] levels = {"1", "2", "3"}; - String chooseGame = (String) JOptionPane.showInputDialog(null, "Choose a level (1 - 3), 1 being easiest to 3 being the hardest", "Difficulty level", JOptionPane.PLAIN_MESSAGE, null, levels, levels[0]); + GameDifficultyListItem[] levels = {new GameDifficultyListItem("Easy", GameDifficulty.EASY), + new GameDifficultyListItem("Medium", GameDifficulty.MEDIUM), + new GameDifficultyListItem("Difficult", GameDifficulty.DIFFICULT)}; + + GameDifficultyListItem difficultyItem = (GameDifficultyListItem) JOptionPane.showInputDialog(null, "Choose a difficulty level", "Difficulty level", JOptionPane.PLAIN_MESSAGE, null, levels, levels[0]); - if(chooseGame != null) { - int gameLevel = Integer.parseInt(chooseGame); + if(difficultyItem != null) { + menuBarController.loadPreconfiguredGame(difficultyItem.getDifficulty()); toggleMenu(); - - gameController.loadPreconfiguredGame(gameLevel); } } }); @@ -177,9 +144,7 @@ public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) { - chrono.resetTimer(); - chrono.chronoStart(); - gameController.loadInputInModel(true); //Clear inputs + menuBarController.restart(); } }); } diff --git a/tests/kakuro/TestBoard.java b/tests/kakuro/TestBoard.java index 79984d8..473ab5e 100644 --- a/tests/kakuro/TestBoard.java +++ b/tests/kakuro/TestBoard.java @@ -9,6 +9,10 @@ import org.junit.Before; import org.junit.Test; +import kakuro.controllers.GameController; +import kakuro.core.Cell; +import kakuro.models.GameModel; + public class TestBoard{ private Boolean GUI = false; //disable GUI private Boolean solved = false; @@ -31,11 +35,11 @@ public void testValidBoard(){ GameController controller = new GameController(10,10, GUI); GameModel model = new GameModel(10,10); model.initBoard(); //initialize board - model.board[0][1] = new BoardCell(BoardCell.CellType.FILLED10, 5); - model.board[1][0] = new BoardCell(BoardCell.CellType.FILLED01,-1,4); - model.board[1][1] = new BoardCell(BoardCell.CellType.INPUT,3,-1); - model.board[2][1] = new BoardCell(BoardCell.CellType.INPUT,2,-1); - model.board[1][2] = new BoardCell(BoardCell.CellType.INPUT,1,-1); + model.board[0][1] = new Cell(Cell.CellType.FILLED10, 5); + model.board[1][0] = new Cell(Cell.CellType.FILLED01,-1,4); + model.board[1][1] = new Cell(Cell.CellType.INPUT,3,-1); + model.board[2][1] = new Cell(Cell.CellType.INPUT,2,-1); + model.board[1][2] = new Cell(Cell.CellType.INPUT,1,-1); controller.model = model; // Act solved = controller.solveBoard(); @@ -49,11 +53,11 @@ public void testNotValidBoardOneSumIsWrong(){ GameController controller = new GameController(10,10, GUI); GameModel model = new GameModel(10,10); model.initBoard(); - model.board[0][1] = new BoardCell(BoardCell.CellType.FILLED10, 5); - model.board[1][0] = new BoardCell(BoardCell.CellType.FILLED01,-1,4); - model.board[1][1] = new BoardCell(BoardCell.CellType.INPUT,3,-1); - model.board[2][1] = new BoardCell(BoardCell.CellType.INPUT,2,-1); - model.board[1][2] = new BoardCell(BoardCell.CellType.INPUT,5,-1); + model.board[0][1] = new Cell(Cell.CellType.FILLED10, 5); + model.board[1][0] = new Cell(Cell.CellType.FILLED01,-1,4); + model.board[1][1] = new Cell(Cell.CellType.INPUT,3,-1); + model.board[2][1] = new Cell(Cell.CellType.INPUT,2,-1); + model.board[1][2] = new Cell(Cell.CellType.INPUT,5,-1); controller.model = model; // Act solved = controller.solveBoard(); @@ -67,11 +71,11 @@ public void testNotValidBoardCorrectSumDuplicateEntries(){ GameController controller = new GameController(10,10, GUI); GameModel model = new GameModel(10,10); model.initBoard(); - model.board[0][1] = new BoardCell(BoardCell.CellType.FILLED10, 5); - model.board[1][0] = new BoardCell(BoardCell.CellType.FILLED01,-1,4); - model.board[1][1] = new BoardCell(BoardCell.CellType.INPUT,2,-1); - model.board[2][1] = new BoardCell(BoardCell.CellType.INPUT,3,-1); - model.board[1][2] = new BoardCell(BoardCell.CellType.INPUT,2,-1); + model.board[0][1] = new Cell(Cell.CellType.FILLED10, 5); + model.board[1][0] = new Cell(Cell.CellType.FILLED01,-1,4); + model.board[1][1] = new Cell(Cell.CellType.INPUT,2,-1); + model.board[2][1] = new Cell(Cell.CellType.INPUT,3,-1); + model.board[1][2] = new Cell(Cell.CellType.INPUT,2,-1); controller.model = model; // Act solved = controller.solveBoard(); diff --git a/tests/kakuro/TestBoardCell.java b/tests/kakuro/TestBoardCell.java index 6cee191..7bab8f0 100644 --- a/tests/kakuro/TestBoardCell.java +++ b/tests/kakuro/TestBoardCell.java @@ -9,27 +9,30 @@ import org.junit.BeforeClass; import org.junit.Test; -public class TestBoardCell{ +import kakuro.core.Cell; + +public class TestBoardCell +{ @Test public void testNonInputCell(){ // Arrange - BoardCell.CellType cellType = BoardCell.CellType.EMPTY; + Cell.CellType cellType = Cell.CellType.EMPTY; // Act - BoardCell cell = new BoardCell(cellType); + Cell cell = new Cell(cellType); // Assert - assertEquals(cell.getType(), BoardCell.CellType.EMPTY); + assertEquals(cell.getType(), Cell.CellType.EMPTY); } @Test public void testInputCell(){ // Arrange int inputNumber = 1; - BoardCell.CellType cellType = BoardCell.CellType.EMPTY; + Cell.CellType cellType = Cell.CellType.EMPTY; // Act - BoardCell cell = new BoardCell(cellType, inputNumber); + Cell cell = new Cell(cellType, inputNumber); // Assert assertEquals(cell.getFirstValue(), inputNumber); - assertEquals(cell.getType(), BoardCell.CellType.EMPTY); + assertEquals(cell.getType(), Cell.CellType.EMPTY); } @Test @@ -37,12 +40,12 @@ public void testInputAnswerCell(){ // Arrange int inputNumber = 1; int answerNumber = 3; - BoardCell.CellType cellType = BoardCell.CellType.EMPTY; + Cell.CellType cellType = Cell.CellType.EMPTY; // Act - BoardCell cell = new BoardCell(cellType, inputNumber, answerNumber); + Cell cell = new Cell(cellType, inputNumber, answerNumber); // Assert assertEquals(cell.getFirstValue(), inputNumber); assertEquals(cell.getSecondValue(), answerNumber); - assertEquals(cell.getType(), BoardCell.CellType.EMPTY); + assertEquals(cell.getType(), Cell.CellType.EMPTY); } } diff --git a/tests/kakuro/TestBoardUI.java b/tests/kakuro/TestBoardUI.java index a4426c6..f94a351 100644 --- a/tests/kakuro/TestBoardUI.java +++ b/tests/kakuro/TestBoardUI.java @@ -10,6 +10,8 @@ import org.junit.BeforeClass; import org.junit.Test; +import kakuro.controllers.GameController; + public class TestBoardUI { @Test public void testBoardUIGeneration(){ diff --git a/tests/kakuro/TestChrono.java b/tests/kakuro/TestChrono.java index 746fa47..4893b11 100644 --- a/tests/kakuro/TestChrono.java +++ b/tests/kakuro/TestChrono.java @@ -10,6 +10,12 @@ import org.junit.BeforeClass; import org.junit.Test; +import kakuro.controllers.GameController; +import kakuro.controllers.MenuBarController; +import kakuro.controllers.ChronoController; +import kakuro.views.MenuBarView; +import kakuro.views.GameView; + public class TestChrono{ private int faultToleranceMs = 200; @@ -18,17 +24,16 @@ public class TestChrono{ public void testRunStopChronoAfter3Seconds() throws InterruptedException{ // Arrange int waitSeconds = 3; - GameController gameController = new GameController(10, 10, false); - GameView gameView = new GameView(gameController, false/*GUI*/); - gameView.setButtonMenu(new ButtonMenu(null, 0, 0, null)); + ChronoController chronoController = new ChronoController(); + // Act - gameView.settingUpMenu(); // chrono starts + chronoController.chronoStart(); Thread.sleep(waitSeconds * 1000/*ms*/ + faultToleranceMs); - gameView.getButtonMenu().getChrono().chronoPause(); + chronoController.chronoPause(); - int hours = gameView.getButtonMenu().getChrono().getHours(); - int minutes = gameView.getButtonMenu().getChrono().getMinutes(); - int seconds = gameView.getButtonMenu().getChrono().getSeconds(); + int hours = chronoController.getHours(); + int minutes = chronoController.getMinutes(); + int seconds = chronoController.getSeconds(); // Assert System.out.println("Chrono was run for " + seconds + " seconds"); assertTrue(waitSeconds == seconds); diff --git a/tests/kakuro/TestDBConnection.java b/tests/kakuro/TestDBConnection.java index a508721..7e22eba 100644 --- a/tests/kakuro/TestDBConnection.java +++ b/tests/kakuro/TestDBConnection.java @@ -10,7 +10,7 @@ import org.junit.Test; -import kakuro.utils.DatabaseConnection; +import kakuro.core.DatabaseConnection; public class TestDBConnection { @Test diff --git a/tests/kakuro/TestGameController.java b/tests/kakuro/TestGameController.java index d06d975..0d107ee 100644 --- a/tests/kakuro/TestGameController.java +++ b/tests/kakuro/TestGameController.java @@ -10,14 +10,11 @@ import java.sql.Connection; import java.sql.SQLException; -import java.util.ArrayList; - import org.junit.Test; - -import kakuro.game.dao.GameDao; -import kakuro.game.dao.GameDaoImpl; -import kakuro.gameprogress.dao.GameProgressDaoImpl; -import kakuro.utils.DatabaseConnection; +import kakuro.models.GameModel; +import kakuro.controllers.GameController; +import kakuro.core.Cell; +import kakuro.core.DatabaseConnection; public class TestGameController { Boolean GUI = false; @@ -64,116 +61,83 @@ public void testDisconnectDatabase() { Connection conn = db.getConnection(); //Assert try { - assertEquals(conn.isClosed(), true); + assertEquals(conn.isClosed(), true); } catch (SQLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + // TODO Auto-generated catch block + e.printStackTrace(); + } + } @Test -// @brief Test Valid Board + // @brief Test Valid Board public void testBoardSolveValidBoard() { - // Arrange - int columns = 10; - int rows = 10; - // Act - GameModel model = new GameModel(columns, rows); - // Assert - assertEquals(model.columns, columns); - assertEquals(model.rows, rows); - // Arrange - GameController controller1 = new GameController(10,10, GUI); - GameModel model1 = new GameModel(10,10); - model1.initBoard(); //initialize board - model1.board[0][1] = new BoardCell(BoardCell.CellType.FILLED10, 5); - model1.board[1][0] = new BoardCell(BoardCell.CellType.FILLED01,-1,4); - model1.board[1][1] = new BoardCell(BoardCell.CellType.INPUT,3,-1); - model1.board[2][1] = new BoardCell(BoardCell.CellType.INPUT,2,-1); - model1.board[1][2] = new BoardCell(BoardCell.CellType.INPUT,1,-1); - controller1.model = model1; - // Act - solved = controller1.solveBoard(); - // Assert + //Arrange + GameController controller = new GameController(10,10, GUI); + GameModel model = controller.model; + model.initBoard(); //initialize board + model.board[0][1] = new Cell(Cell.CellType.FILLED10, 5); + model.board[1][0] = new Cell(Cell.CellType.FILLED01,-1,4); + model.board[1][1] = new Cell(Cell.CellType.INPUT,3,-1); + model.board[2][1] = new Cell(Cell.CellType.INPUT,2,-1); + model.board[1][2] = new Cell(Cell.CellType.INPUT,1,-1); + //Act + solved = controller.solveBoard(); + //Assert assertEquals(solved, true); } @Test -// @brief Test Invalid Board with one wrong vertical sum + // @brief Test Invalid Board with one wrong vertical sum public void testBoardSolveInvalidBoardWithOneWrongVerticalSum() { - // Arrange - int columns = 10; - int rows = 10; - // Act - GameModel model = new GameModel(columns, rows); - // Assert - assertEquals(model.columns, columns); - assertEquals(model.rows, rows); - GameController controller2 = new GameController(10,10, GUI); - GameModel model2 = new GameModel(10,10); - model2.initBoard(); - model2.board[0][1] = new BoardCell(BoardCell.CellType.FILLED10, 5); - model2.board[1][0] = new BoardCell(BoardCell.CellType.FILLED01,-1,4); - model2.board[1][1] = new BoardCell(BoardCell.CellType.INPUT,3,-1); - model2.board[2][1] = new BoardCell(BoardCell.CellType.INPUT,6,-1); - model2.board[1][2] = new BoardCell(BoardCell.CellType.INPUT,1,-1); - controller2.model = model2; - // Act - solved = controller2.solveBoard(); - // Assert + //Arrange + GameController controller = new GameController(10,10, GUI); + GameModel model = controller.model; + model.initBoard(); //initialize board + model.board[0][1] = new Cell(Cell.CellType.FILLED10, 5); + model.board[1][0] = new Cell(Cell.CellType.FILLED01,-1,4); + model.board[1][1] = new Cell(Cell.CellType.INPUT,3,-1); + model.board[2][1] = new Cell(Cell.CellType.INPUT,6,-1); + model.board[1][2] = new Cell(Cell.CellType.INPUT,1,-1); + //Act + solved = controller.solveBoard(); + //Assert assertEquals(solved, false); } @Test -// @brief Test Invalid Board with one wrong horizontal sum + // @brief Test Invalid Board with one wrong horizontal sum public void testBoardSolveInvalidBoardWithOneWrongHorizontalSum() { - // Arrange - int columns = 10; - int rows = 10; - // Act - GameModel model = new GameModel(columns, rows); - // Assert - assertEquals(model.columns, columns); - assertEquals(model.rows, rows); - GameController controller2 = new GameController(10,10, GUI); - GameModel model2 = new GameModel(10,10); - model2.initBoard(); - model2.board[0][1] = new BoardCell(BoardCell.CellType.FILLED10, 5); - model2.board[1][0] = new BoardCell(BoardCell.CellType.FILLED01,-1,8); - model2.board[1][1] = new BoardCell(BoardCell.CellType.INPUT,3,-1); - model2.board[2][1] = new BoardCell(BoardCell.CellType.INPUT,2,-1); - model2.board[1][2] = new BoardCell(BoardCell.CellType.INPUT,1,-1); - controller2.model = model2; - // Act - solved = controller2.solveBoard(); - // Assert + //Arrange + GameController controller = new GameController(10,10, GUI); + GameModel model = controller.model; + model.initBoard(); //initialize board + model.board[0][1] = new Cell(Cell.CellType.FILLED10, 5); + model.board[1][0] = new Cell(Cell.CellType.FILLED01,-1,8); + model.board[1][1] = new Cell(Cell.CellType.INPUT,3,-1); + model.board[2][1] = new Cell(Cell.CellType.INPUT,2,-1); + model.board[1][2] = new Cell(Cell.CellType.INPUT,1,-1); + //Act + solved = controller.solveBoard(); + //Assert assertEquals(solved, false); } @Test -// @brief Test Invalid Board with correct sum but duplicate entries + // @brief Test Invalid Board with correct sum but duplicate entries public void testBoardSolveInvalidBoardWithDuplicateEntries() { - // Arrange - int columns = 10; - int rows = 10; - // Act - GameModel model = new GameModel(columns, rows); - // Assert - assertEquals(model.columns, columns); - assertEquals(model.rows, rows); - // Arrange - GameController controller3 = new GameController(10,10, GUI); - GameModel model3 = new GameModel(10,10); - model3.initBoard(); - model3.board[0][1] = new BoardCell(BoardCell.CellType.FILLED10, 5); - model3.board[1][0] = new BoardCell(BoardCell.CellType.FILLED01,-1,4); - model3.board[1][1] = new BoardCell(BoardCell.CellType.INPUT,2,-1); - model3.board[2][1] = new BoardCell(BoardCell.CellType.INPUT,3,-1); - model3.board[1][2] = new BoardCell(BoardCell.CellType.INPUT,2,-1); - controller3.model = model3; - // Act - solved = controller3.solveBoard(); - // Assert + //Arrange + GameController controller = new GameController(10,10, GUI); + GameModel model = controller.model; + model.initBoard(); //initialize board + model.board[0][1] = new Cell(Cell.CellType.FILLED10, 5); + model.board[1][0] = new Cell(Cell.CellType.FILLED01,-1,4); + model.board[1][1] = new Cell(Cell.CellType.INPUT,2,-1); + model.board[2][1] = new Cell(Cell.CellType.INPUT,3,-1); + model.board[1][2] = new Cell(Cell.CellType.INPUT,2,-1); + //Act + solved = controller.solveBoard(); + //Assert assertEquals(solved, false); } } diff --git a/tests/kakuro/TestGameViewInput.java b/tests/kakuro/TestGameViewInput.java index 7f894a9..9184ff7 100644 --- a/tests/kakuro/TestGameViewInput.java +++ b/tests/kakuro/TestGameViewInput.java @@ -12,19 +12,23 @@ import org.junit.BeforeClass; import org.junit.Test; -public class TestGameViewInput{ - +import kakuro.controllers.GameController; +import kakuro.views.GameView; + +public class TestGameViewInput +{ + private static GameController gameController; - private static GameView gameView; @BeforeClass - public static void onlyOnce(){ + public static void onlyOnce() + { gameController = new GameController(10, 10, false); - gameView = new GameView(gameController, false/*GUI*/); } - private boolean hasValidRange(final int value){ - return (value <= gameView.getMaxNumberValid() && value >= gameView.getMinNumberValid()); + private boolean hasValidRange(final int value) + { + return (value <= gameController.getMaxNumberValid() && value >= gameController.getMinNumberValid()); } @Test @@ -88,7 +92,7 @@ public void testInvalidInputString(){ String value = "yo"; Boolean isValid = false; // Act - isValid = gameView.getNumberFormatterClassType().equals(value.getClass()); + isValid = gameController.getNumberFormatterClassType().equals(value.getClass()); // Assert assertFalse(isValid); } diff --git a/tests/kakuro/TestPlayerDao.java b/tests/kakuro/TestPlayerDao.java index d183117..62dacce 100644 --- a/tests/kakuro/TestPlayerDao.java +++ b/tests/kakuro/TestPlayerDao.java @@ -4,10 +4,9 @@ package kakuro; +import kakuro.core.DatabaseConnection; import kakuro.player.dao.*; -import kakuro.utils.DatabaseConnection; - import static org.junit.Assert.assertEquals; import java.sql.SQLException; diff --git a/tests/kakuro/TestPlayerModel.java b/tests/kakuro/TestPlayerModel.java index ddd888b..d64d453 100644 --- a/tests/kakuro/TestPlayerModel.java +++ b/tests/kakuro/TestPlayerModel.java @@ -6,7 +6,8 @@ import static org.junit.Assert.assertEquals; import org.junit.Test; -import kakuro.PlayerModel; + +import kakuro.models.PlayerModel; //iteration 3 diff --git a/tests/kakuro/TestUniquePartitions.java b/tests/kakuro/TestUniquePartitions.java index 45dd509..9b3a7ba 100644 --- a/tests/kakuro/TestUniquePartitions.java +++ b/tests/kakuro/TestUniquePartitions.java @@ -12,6 +12,8 @@ import org.junit.BeforeClass; import org.junit.Test; +import kakuro.core.*; + public class TestUniquePartitions { private static UniquePartitions partitions;