Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/Point Collection System #30

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/authoring/InsertBefore.java
Original file line number Diff line number Diff line change
Expand Up @@ -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"};


Expand Down
70 changes: 70 additions & 0 deletions src/commands/PointCommand.java
Original file line number Diff line number Diff line change
@@ -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() {


}

}
66 changes: 66 additions & 0 deletions src/commands/SayScoreCommand.java
Original file line number Diff line number Diff line change
@@ -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

}

}
23 changes: 22 additions & 1 deletion src/enamel/ScenarioParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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"))
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
{
Expand Down
26 changes: 25 additions & 1 deletion src/listeners/NewButtonListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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" };

Expand Down Expand Up @@ -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, "");
Expand Down
5 changes: 5 additions & 0 deletions src/listeners/NewQuestionListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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")
Expand All @@ -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()));
Expand Down