Skip to content

Commit

Permalink
Some error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
fulcorno committed Mar 24, 2015
1 parent 11d8943 commit 2176733
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
31 changes: 25 additions & 6 deletions Impiccato/src/it/polito/tdp/impiccato/ImpiccatoController.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,33 @@ private void updateView() {

txtErrori.setText(String.format("%d", model.getErrori()));
txtParola.setText(model.getMaschera());
pbErrori.setProgress( (double)model.getErrori()/model.getMAX_ERRORI()) ;
pbErrori.setProgress((double) model.getErrori() / model.getMAX_ERRORI());

}

@FXML
void doStart(ActionEvent event) {

model.startGame(txtSegreto.getText());
String segreto = txtSegreto.getText();

// remove spaces and converto to uppercase
segreto = segreto.trim().toUpperCase();

// must not be empty
if (segreto.length() == 0) {
txtSoluzione.setText("ERRORE parola non valida");
return;
}

// must only contain letters
for (int i = 0; i < segreto.length(); i++) {
if (!Character.isUpperCase(segreto.charAt(i))) {
txtSoluzione.setText("ERRORE parola non valida");
return;
}
}

model.startGame(segreto);

inMatch = true;
updateView();
Expand All @@ -89,11 +108,11 @@ void doStart(ActionEvent event) {
void doTry(ActionEvent event) {

String t = comboLettera.getValue();
if(t==null) {
if (t == null) {
// no selected letter
return ;
return;
}

model.tryLetter(t);

if (model.isWinner()) {
Expand Down Expand Up @@ -125,7 +144,7 @@ void initialize() {
for (char ch = 'A'; ch <= 'Z'; ch++) {
comboLettera.getItems().add(String.valueOf(ch));
}

}

public void setModel(ImpiccatoModel model) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public ImpiccatoModel() {
*/
public void startGame(String segreto) {
this.segreto = segreto.toUpperCase();

errori = 0;
provate.clear();

Expand Down

0 comments on commit 2176733

Please sign in to comment.