use of eu.tn.model.Rules in project TNCY-English-Project by mrngg.
the class AnswerSheetController method updateSheet.
public void updateSheet() throws IOException {
if (actualTest.successRules() != 0) {
actualRules = actualTest.randomRules().getName();
for (Rules r : actualTest.getRules()) {
if (r.getName().equals(actualRules)) {
r.setVisited(true);
actualSentences = r.randomSentences().getName();
for (Sentences s : r.getSentences()) {
if (s.getName().equals(actualSentences)) {
s.setVisited(true);
}
}
if (r.getError() >= 3) {
hint.setText(r.getHint());
}
}
}
sentences.setText(actualSentences);
answer.setText("");
} else {
for (Rules r : actualTest.getRules()) {
r.setSuccess(0);
r.setVisited(false);
r.setError(0);
for (Sentences s : r.getSentences()) {
s.setVisited(false);
}
}
Stage primaryStage = new Stage();
primaryStage.setTitle("Shakespeare");
BorderPane root = new BorderPane();
FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass().getResource("../view/EndScreen.fxml"));
loader.setControllerFactory((iC -> new EndScreenController(actualTest)));
root.setCenter(loader.load());
primaryStage.setOnCloseRequest(event -> {
Platform.exit();
});
primaryStage.setTitle("Shakespeare");
primaryStage.setScene(new Scene(root, 710, 532));
primaryStage.show();
Stage stage = (Stage) validateB.getScene().getWindow();
stage.close();
}
}
use of eu.tn.model.Rules in project TNCY-English-Project by mrngg.
the class DbRulesController method newRules.
public void newRules() {
GridPane grid = new GridPane();
grid.setAlignment(Pos.CENTER);
grid.setHgap(10);
grid.setVgap(10);
grid.setPadding(new Insets(25, 25, 25, 25));
Label name = new Label("Name :");
TextField nameTF = new TextField();
grid.add(nameTF, 1, 1);
grid.add(name, 0, 1);
Label hint = new Label("Hint :");
TextField hintTF = new TextField();
grid.add(hintTF, 1, 2);
grid.add(hint, 0, 2);
Button btn = new Button("Create");
grid.add(btn, 0, 3);
Scene secondScene = new Scene(grid, 300, 150);
Stage newWindow = new Stage();
newWindow.setTitle("Create a rule");
newWindow.setScene(secondScene);
newWindow.show();
btn.setOnAction((event) -> {
if (nameTF.getText() != null && hintTF.getText() != null) {
new Rules(nameTF.getText(), hintTF.getText());
ObservableList<String> items = FXCollections.observableArrayList();
for (int i = 0; i < rules.size(); i++) {
items.add(rules.get(i).getName());
}
availableRules.setItems(items);
newWindow.close();
try {
new Database().save();
} catch (IOException e) {
e.printStackTrace();
}
}
});
}
use of eu.tn.model.Rules in project TNCY-English-Project by mrngg.
the class DbRulesController method editRules.
public void editRules() throws IOException {
if (availableRules.getSelectionModel().getSelectedItem() != null) {
GridPane grid = new GridPane();
grid.setAlignment(Pos.CENTER);
grid.setHgap(10);
grid.setVgap(10);
grid.setPadding(new Insets(25, 25, 25, 25));
Label name = new Label("Name :");
TextField nameTF = new TextField();
nameTF.setText(availableRules.getSelectionModel().getSelectedItem().toString());
grid.add(nameTF, 1, 1);
grid.add(name, 0, 1);
Label hint = new Label("Hint :");
TextField hintTF = new TextField();
String hintR = "";
for (Rules r : rules) {
if (r.getName().equals(availableRules.getSelectionModel().getSelectedItem().toString())) {
hintR = r.getHint();
}
}
hintTF.setText(hintR);
grid.add(hintTF, 1, 2);
grid.add(hint, 0, 2);
Button btn = new Button("Edit");
grid.add(btn, 0, 3);
Scene secondScene = new Scene(grid, 300, 150);
Stage newWindow = new Stage();
newWindow.setTitle("Edit a rule");
newWindow.setScene(secondScene);
newWindow.show();
btn.setOnAction((event) -> {
if (nameTF.getText() != null && hintTF.getText() != null) {
for (Rules r : rules) {
if (r.getName().equals(availableRules.getSelectionModel().getSelectedItem().toString())) {
r.setName(nameTF.getText());
r.setHint(hintTF.getText());
}
}
ObservableList<String> items = FXCollections.observableArrayList();
for (int i = 0; i < rules.size(); i++) {
items.add(rules.get(i).getName());
}
availableRules.setItems(items);
newWindow.close();
rulesName.setText(nameTF.getText());
rulesHint.setText(hintTF.getText());
try {
new Database().save();
} catch (IOException e) {
e.printStackTrace();
}
}
});
}
}
use of eu.tn.model.Rules in project TNCY-English-Project by mrngg.
the class AnswerSheetController method validate.
public void validate() throws IOException {
if (answer.getText() != null) {
for (Rules r : actualTest.getRules()) {
if (r.getName().equals(actualRules)) {
for (Sentences s : r.getSentences()) {
if (s.getName().equals(actualSentences)) {
if (answer.getText().equals(s.getAnswer())) {
r.setSuccess(r.getSuccess() + 1);
r.setError(0);
} else {
r.setSuccess(0);
r.setError(r.getError() + 1);
}
}
}
}
}
updateSheet();
}
}
use of eu.tn.model.Rules in project TNCY-English-Project by mrngg.
the class AnswerSheetController method correctSentence.
public void correctSentence() throws IOException {
for (Rules r : actualTest.getRules()) {
if (r.getName().equals(actualRules)) {
for (Sentences s : r.getSentences()) {
if (s.getName().equals(actualSentences)) {
if (s.getAnswer().equals("")) {
r.setSuccess(r.getSuccess() + 1);
r.setError(0);
} else {
r.setSuccess(0);
r.setError(r.getError() + 1);
}
}
}
}
}
updateSheet();
for (Rules r : actualTest.getRules()) {
System.out.println(r.getSuccess());
}
}
Aggregations