From 636ff6a1d9f3dc6f2f0aaaff0995ac687b0bfc8d Mon Sep 17 00:00:00 2001 From: Robert-0410 <62630290+Robert-0410@users.noreply.github.com> Date: Fri, 28 May 2021 14:53:52 -0700 Subject: [PATCH] Revert "Database update" --- .../360GroupProject/sql/QuestionManager.class | Bin 2266 -> 0 bytes questions.db | Bin 24576 -> 24576 bytes src/controller/EnvironmentManager.java | 24 +++++---------- src/sql/QuestionManager.java | 28 ++++++++++-------- 4 files changed, 24 insertions(+), 28 deletions(-) delete mode 100644 out/production/360GroupProject/sql/QuestionManager.class diff --git a/out/production/360GroupProject/sql/QuestionManager.class b/out/production/360GroupProject/sql/QuestionManager.class deleted file mode 100644 index 4c723f7d5f94c8677167c5f63c26a840db049e74..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2266 zcmZ`)TYD2#6kU^~nMpdO5PAzJ1Q19X35V^C>cowvZaYTZ z%xk8$rdtxi<+^DymOcrCITunKOn2Njg6~}OV4{OCO+tF(zOSi~`*St}mxXwfl)9G4` z&5z)Oijz1+u2^1Pw{0>fVIb~R(p_8_r*THcSru_4NV!|kUPK9UL*Q2h-~08qBIBF{ zwR>7&B;oJHI3{GAS22lK+t_h0XRNhrEnM6-&6@O=jo3gb>BklCXp`|DUD1P6dTdjyVO( z9V4w^rDMzsb-bry6}NwGnuBo^$gmuUTOxG=ok4)CA=$lkgx?Uklf6g%V z#b&LfTgzIhN>3zLFKg8m%`$}TIRnmpgRKnax^IN{WK2b1P5(X=bkcE>C@ek-vj6;VR=?xh&$%GLIYM4r0aBaU<_(c@i$Pt2qX zpd$|g$Ss1etnEj+!}vi nrq4JH!TbpX{=z94Nf{UTkk9-h@MS0xUEt!*zmlt`#Wf1RiUS@hm36m!KL?qM>P!V5ezFQx)xo5KpEE?=F_Y#OH!Gf$?G)>KF~KuiDs^ zDSg3VXGbuM9L(x4^btyE--8NfXIj%bkey0r4I}tjnP>|OkO$Or0EzyCEG#o)R}Q-= zpM*UR+!~fj121+Qy2s@nn*EXn!5sF{o-Hi2OXXCT;r+@sneR4+!fTYdHCmSohnj3a ziMkDFdA>`m!kW3Ps_W_0Wa@82Hwb1ev*{U~I7HmZpqiT8FD0sxlhfu9Tu=M1^#2(p1#o*NunK Ykw;;*oXcnPGPbf6t}5Lx_p0N601>=QM*si- diff --git a/src/controller/EnvironmentManager.java b/src/controller/EnvironmentManager.java index 64f8063..06ec70d 100644 --- a/src/controller/EnvironmentManager.java +++ b/src/controller/EnvironmentManager.java @@ -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 currentRow = myMap.get(myUserRow); @@ -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()) { @@ -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 currentRow = myMap.get(myUserRow); @@ -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 currentRow = myMap.get(myUserRow); diff --git a/src/sql/QuestionManager.java b/src/sql/QuestionManager.java index 07d6380..2d26cff 100644 --- a/src/sql/QuestionManager.java +++ b/src/sql/QuestionManager.java @@ -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 +https://shanemcd.org/2020/01/24/how-to-set-up-sqlite-with-jdbc-in-eclipse-on-windows/ * - * 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(); } @@ -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");