diff --git a/src/authoring/InsertBefore.java b/src/authoring/InsertBefore.java index 500de29..9d0feb1 100755 --- a/src/authoring/InsertBefore.java +++ b/src/authoring/InsertBefore.java @@ -137,7 +137,7 @@ public void actionPerformed(ActionEvent e) { panel.add(btnDisplayOnBraille); - String[] array= {"Advance Options","Repeat", "Button Repeat", "Button Location", "User Input", "Reset Buttons", "Go To Location", "Clear All", "Clear Cell", + String[] array= {"Advance Options", "Say Score", "Say Total","Repeat", "Button Repeat", "Button Location", "User Input", "Reset Buttons", "Go To Location", "Clear All", "Clear Cell", "Set Pins", "Set Character", "Raise Pin", "Lower Pin", "Set Voice", "Location Tag"}; diff --git a/src/commands/PointCommand.java b/src/commands/PointCommand.java new file mode 100644 index 0000000..8bf2276 --- /dev/null +++ b/src/commands/PointCommand.java @@ -0,0 +1,70 @@ +package commands; + +/** + * Command wrapper to represent the /~point and /~offset in the Scenario Parser. + * Offset represents the total score, compared to what the user has scored. + * This command allows tracking of users correct answers, and total answers + * from QuestionCommand. + * + * This command is not implemented to be added in the Authoring App. + * + * @author Dyllan Bertrand + * @version 1.0 + * @since 2019-03-08 + */ +public class PointCommand implements PlayerCommand { + + + String type; + /** + * Default Constructor that used to instantiate the /~point section + */ + public PointCommand() { + type = ""; + } + + /** + * This constructor is used to instantiate the point command with the + * "offset" value to add to the total score + * + * @param type - This is passed a specific value of offset. + */ + public PointCommand(String type) { + this.type = type; + } + + @Override + public String toString() { + return ""; + } + + @Override + public String serialize() { + if(!type.equals("offset")) + return "/~point"; + else + return "/~offset"; + } + + @Override + public String getEditLabel() { + return "Ignored"; + } + + @Override + public String getCurrentValue() { + return ""; + } + + @Override + public void setCurrentValue(String newValue) { + + } + + @Override + public void editCommand() { + + + } + +} diff --git a/src/commands/SayScoreCommand.java b/src/commands/SayScoreCommand.java new file mode 100644 index 0000000..4c887cd --- /dev/null +++ b/src/commands/SayScoreCommand.java @@ -0,0 +1,66 @@ +package commands; + +/** + * Command wrapper to represent the /~say-score and /~say-total in the player. There are no + * input values from the user. The values are automatically assigned if the user chooses + * to use to output the user score or score total. + * + * @author Dyllan Bertrand + * @version 1.0 + * @since 2019-03-21 + */ +public class SayScoreCommand implements PlayerCommand { + + boolean scoreType; + + /** + * Constructs a SayScoreCommand with the scoreType value as the input value + * + * @param scoreType + * Determines whether the command type is Score or Total + */ + public SayScoreCommand(boolean scoreType) { + this.scoreType = scoreType; + } + + @Override + public String toString() { + if(this.scoreType) + return "Say user score"; + else + return "Say score total"; + } + + @Override + public String serialize() { + if(this.scoreType) + return "/~say-score"; + else + return "/~say-total"; + } + + @Override + public String getEditLabel() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getCurrentValue() { + // TODO Auto-generated method stub + return null; + } + + @Override + public void setCurrentValue(String newValue) { + // TODO Auto-generated method stub + + } + + @Override + public void editCommand() { + // TODO Auto-generated method stub + + } + +} diff --git a/src/enamel/ScenarioParser.java b/src/enamel/ScenarioParser.java index 2d4a029..163f2da 100755 --- a/src/enamel/ScenarioParser.java +++ b/src/enamel/ScenarioParser.java @@ -24,6 +24,7 @@ public class ScenarioParser public boolean userInput; private String scenarioFilePath; private int score = 0; + private int offset = 0; Logger logger = Logger.getLogger(ScenarioParser.class.getName()); public ScenarioParser() @@ -223,11 +224,20 @@ else if (fileLine.length () >= 21 && fileLine.substring(0, 21).equals("/~disp-ce else if (fileLine.length () >= 7 && fileLine.substring(0, 7).equals("/~point")) { incrementScore(); + } + //The key phrase to increment offset for total score + else if (fileLine.length () >= 8 && fileLine.substring(0, 8).equals("/~offset")) + { + incrementOffset(); } //The key phrase to speak the current score. else if (fileLine.length () >= 11 && fileLine.substring(0, 11).equals("/~say-score")) { speak(((Integer)this.score).toString()); + } + else if(fileLine.length () >= 11 && fileLine.substring(0, 11).equals("/~say-total")) + { + speak(((Integer)(this.score + this.offset)).toString()); } //The key phrase to log an incorrect answer. else if (fileLine.length() >= 11 && fileLine.substring(0, 11).equals("/~incorrect")) @@ -389,6 +399,14 @@ private void incrementScore() { logger.log(Level.INFO, "REPORT: User's current score is {0}", ((Integer)this.score).toString()); } + /** + * This method corresponds to /~offset. This helps to calculate what the users score is out of. + * Offset + Score = Total + */ + private void incrementOffset() { + this.offset ++; + } + /* * This method corresponds to the /~disp-cell-pins: key phrase in the scenario, and it implements the * setPins method in the BrailleCell class. @@ -700,7 +718,10 @@ private void setCellAndButton () { cellNum = Integer.parseInt(fileScanner.nextLine().split("\\s")[1]); buttonNum = Integer.parseInt(fileScanner.nextLine().split("\\s")[1]); - sim = new TactilePlayer (cellNum, buttonNum); + sim = new VisualPlayer (cellNum, buttonNum); + //sim = new TactilePlayer (cellNum, buttonNum); + //TODO: Replace tactilePlayer when you are done + // OR JUST DON'T COMMIT THIS CLASS FILE } catch (Exception e) { diff --git a/src/listeners/NewButtonListener.java b/src/listeners/NewButtonListener.java index 5ee8505..672e04d 100755 --- a/src/listeners/NewButtonListener.java +++ b/src/listeners/NewButtonListener.java @@ -31,6 +31,7 @@ import commands.RepeatButtonCommand; import commands.RepeatCommand; import commands.ResetButtonCommand; +import commands.SayScoreCommand; import commands.SetPinsCommand; import commands.SetStringCommand; import commands.SetVoiceCommand; @@ -140,7 +141,7 @@ public void actionPerformed(ActionEvent e) { btnDisplayOnBraille.setFont(new Font(FONT_FACE, Font.PLAIN, FONT_SIZE)); panel.add(btnDisplayOnBraille); - String[] array = { "Advance Options", "Repeat", "Button Repeat", "Button Location", "User Input", + String[] array = { "Advance Options", "Say Score", "Say Total", "Repeat", "Button Repeat", "Button Location", "User Input", "Reset Buttons", "Go To Location", "Clear All", "Clear Cell", "Set Pins", "Set Character", "Raise Pin", "Lower Pin", "Set Voice", "Location Tag" }; @@ -201,6 +202,29 @@ public void processAnswer(String answer, String ID) { gui.counterMap.put("Display on Braille Cell", gui.counterMap.get("Display on Braille Cell") + 1); } break; + + case "Say Score": + value = JOptionPane.showOptionDialog(gui, "Say Score?", "Edit Item Details", + JOptionPane.YES_NO_OPTION, JOptionPane.PLAIN_MESSAGE, null, null, null); + value = ((Integer)(value) == 0) ? true : null; + if(value != null) { + if(ID == "add") + gui.getLeftPanel().addItem(new SayScoreCommand((boolean)value)); + else + gui.getLeftPanel().addItemAt(new SayScoreCommand((boolean)value)); + } + break; + case "Say Total": + value = JOptionPane.showOptionDialog(gui, "Say Total?", "Edit Item Details", + JOptionPane.YES_NO_OPTION, JOptionPane.PLAIN_MESSAGE, null, null, null); + value = ((Integer)(value) == 0) ? false : null; + if(value != null) { + if(ID == "add") + gui.getLeftPanel().addItem(new SayScoreCommand((boolean)value)); + else + gui.getLeftPanel().addItemAt(new SayScoreCommand((boolean)value)); + } + break; case "Repeat": value = JOptionPane.showInputDialog(gui, "Text to be repeated", "Edit Item Details", JOptionPane.PLAIN_MESSAGE, null, null, ""); diff --git a/src/listeners/NewQuestionListener.java b/src/listeners/NewQuestionListener.java index d811cb8..3907066 100755 --- a/src/listeners/NewQuestionListener.java +++ b/src/listeners/NewQuestionListener.java @@ -17,6 +17,7 @@ import commands.GoHereCommand; import commands.PauseCommand; import commands.PlayerCommand; +import commands.PointCommand; import commands.ResetButtonCommand; import commands.SetStringCommand; import commands.SkipButtonCommand; @@ -133,6 +134,8 @@ public void windowClosed(WindowEvent e) { qc.addCommand(new UserInputCommand()); // Labels for bad qc.addCommand(new GoHereCommand("" + randomLabel + "-bad")); + // Adds offset to count total score + qc.addCommand(new PointCommand("offset")); if (ques.getRepeatField().getText().length() > 0 && ques.getIntroField().getText() != "none") qc.addCommand(new TTSCommand(ques.getRepeatField().getText())); else if (ques.getIncorrectAudio() != "none") @@ -145,6 +148,8 @@ else if (ques.getIncorrectSound() != "none") // Label for good holder = new GoHereCommand("" + randomLabel + "-good"); qc.addCommand(holder); + holder = new PointCommand(); + qc.addCommand(holder); if (ques.getCorrectField().getText().length() > 0) qc.addCommand(new TTSCommand(ques.getCorrectField().getText()));