Skip to content

Commit

Permalink
Revert "Database update"
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert-0410 authored May 28, 2021
1 parent 9a610bf commit 636ff6a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 28 deletions.
Binary file not shown.
Binary file modified questions.db
Binary file not shown.
24 changes: 8 additions & 16 deletions src/controller/EnvironmentManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,16 +180,14 @@ public void movePlayerUp() {

userIsMoving = Direction.NORTH;
questionPanel.enableButtons();
// change 'true' to pull from is adult ui setting
questionPanel.setMyQuestion(QUESTION_MANAGER.getRandomMultipleChoiceQuestion(true));
questionPanel.setMyQuestion(QUESTION_MANAGER.getRandomMultipleChoiceQuestion());

} else if(nextCell.getMyID() == CellType.DOOR.getID()) {

isWinningCell = CellType.PORTAL;
userIsMoving = Direction.NORTH;
questionPanel.enableButtons();
// change 'true' to pull from is adult ui setting
questionPanel.setMyQuestion(QUESTION_MANAGER.getRandomMultipleChoiceQuestion(true));
questionPanel.setMyQuestion(QUESTION_MANAGER.getRandomMultipleChoiceQuestion());

} else if(nextCell.getMyID() == CellType.FLOOR.getID()) {
List<GameObject> currentRow = myMap.get(myUserRow);
Expand Down Expand Up @@ -224,15 +222,13 @@ public void movePlayerRight() {
isWinningCell = CellType.PORTAL;
userIsMoving = Direction.EAST;
questionPanel.enableButtons();
// change 'true' to pull from is adult ui setting
questionPanel.setMyQuestion(QUESTION_MANAGER.getRandomMultipleChoiceQuestion(true));
questionPanel.setMyQuestion(QUESTION_MANAGER.getRandomMultipleChoiceQuestion());

} else if(nextCell.getMyID() == CellType.DOOR.getID()) {

userIsMoving = Direction.EAST;
questionPanel.enableButtons();
// change 'true' to pull from is adult ui setting
questionPanel.setMyQuestion(QUESTION_MANAGER.getRandomMultipleChoiceQuestion(true));
questionPanel.setMyQuestion(QUESTION_MANAGER.getRandomMultipleChoiceQuestion());

} else if(nextCell.getMyID() == CellType.FLOOR.getID()) {

Expand Down Expand Up @@ -264,15 +260,13 @@ public void movePlayerDown() {
isWinningCell = CellType.PORTAL;
userIsMoving = Direction.SOUTH;
questionPanel.enableButtons();
// change 'true' to pull from is adult ui setting
questionPanel.setMyQuestion(QUESTION_MANAGER.getRandomMultipleChoiceQuestion(true));
questionPanel.setMyQuestion(QUESTION_MANAGER.getRandomMultipleChoiceQuestion());

} else if(nextCell.getMyID() == CellType.DOOR.getID()) {

userIsMoving = Direction.SOUTH;
questionPanel.enableButtons();
// change 'true' to pull from is adult ui setting
questionPanel.setMyQuestion(QUESTION_MANAGER.getRandomMultipleChoiceQuestion(true));
questionPanel.setMyQuestion(QUESTION_MANAGER.getRandomMultipleChoiceQuestion());

} else if (nextCell.getMyID() == CellType.FLOOR.getID()) {
List<GameObject> currentRow = myMap.get(myUserRow);
Expand Down Expand Up @@ -306,15 +300,13 @@ public void movePlayerLeft() {
isWinningCell = CellType.PORTAL;
userIsMoving = Direction.WEST;
questionPanel.enableButtons();
// change 'true' to pull from is adult ui setting
questionPanel.setMyQuestion(QUESTION_MANAGER.getRandomMultipleChoiceQuestion(true));
questionPanel.setMyQuestion(QUESTION_MANAGER.getRandomMultipleChoiceQuestion());

} else if(nextCell.getMyID() == CellType.DOOR.getID()) {

userIsMoving = Direction.WEST;
questionPanel.enableButtons();
// change 'true' to pull from is adult ui setting
questionPanel.setMyQuestion(QUESTION_MANAGER.getRandomMultipleChoiceQuestion(true));
questionPanel.setMyQuestion(QUESTION_MANAGER.getRandomMultipleChoiceQuestion());

} else if(nextCell.getMyID() == CellType.FLOOR.getID()) {
final List<GameObject> currentRow = myMap.get(myUserRow);
Expand Down
28 changes: 16 additions & 12 deletions src/sql/QuestionManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,28 @@

/**
*
* @author sasha amador
* @version 1.1.03
* @author tom capaul
*
* The QuestionManager class connects our database, and is where our getMultipleChoice method is located.
* Simple class to demonstrate SQLite connectivity
* 1) create connection
* 2) add a table
* 3) add entries to the table
* 4) query the table for its contents
* 5) display the results
*
* NOTE: any interactions with a database should utilize a try/catch
* since things can go wrong
*
* @see <a href="https://shanemcd.org/2020/01/24/how-to-set-up-sqlite-with-jdbc-in-eclipse-on-windows/">
https://shanemcd.org/2020/01/24/how-to-set-up-sqlite-with-jdbc-in-eclipse-on-windows/</a>
*
* the getMultipleChoice method first does a parameter test to see if the user is playing in adult mode or
* child mode. From there the maze will be populated with random questions from the database which reflects
* the mode they are playing in
*/
public class QuestionManager {

Connection connection = null;

public QuestionManager() {
//super();
super();
databaseConnectionSetup();
}

Expand All @@ -39,17 +45,15 @@ private void databaseConnectionSetup(){
}
}

public Question getRandomMultipleChoiceQuestion(boolean isAdult) {
public Question getRandomMultipleChoiceQuestion() {
Question questionBank = new Question();

try {
Statement statement = connection.createStatement();
statement.setQueryTimeout(30); // set timeout to 30 sec.

String isAdultString = (isAdult) ? "1" : "0";

// need to update to actually return a random question instead of just the first one
ResultSet rs = statement.executeQuery(String.format("SELECT * FROM multiple_choice WHERE isAdult=%s ORDER BY RANDOM() LIMIT 1", isAdultString));
// need to update to actually return a random question istead of just the first one
ResultSet rs = statement.executeQuery("SELECT * FROM multiple_choice ORDER BY RANDOM() LIMIT 1");
// read the result set
String[] answers = new String[4];
answers[0] = rs.getString("optionA");
Expand Down

0 comments on commit 636ff6a

Please sign in to comment.