Skip to content

Commit

Permalink
fix: reset round when lose or win round
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagotn committed May 2, 2021
1 parent ce33a3a commit a30cfb8
Showing 1 changed file with 43 additions and 36 deletions.
79 changes: 43 additions & 36 deletions lib/blocs/game.bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,52 +33,59 @@ class GameBloc extends ChangeNotifier {
select(String level) {
switch (level) {
case EASY:
currentLevel = EASY;
rows = easyRows;
columns = easyColumns;
mines = easyMines;
started = false;
seconds = 0;
timer?.cancel();
createGrids();
notifyListeners();
resetRound(
EASY,
easyRows,
easyColumns,
easyMines,
);
break;
case MEDIUM:
currentLevel = MEDIUM;
rows = mediumRows;
columns = mediumColumns;
mines = mediumMines;
started = false;
seconds = 0;
timer?.cancel();
createGrids();
notifyListeners();
resetRound(
MEDIUM,
mediumRows,
mediumColumns,
mediumMines,
);
break;
case HARD:
currentLevel = HARD;
rows = hardRows;
columns = hardColumns;
mines = hardMines;
started = false;
seconds = 0;
timer?.cancel();
createGrids();
notifyListeners();
resetRound(
HARD,
hardRows,
hardColumns,
hardMines,
);
break;
default:
currentLevel = MEDIUM;
rows = mediumRows;
columns = mediumColumns;
mines = mediumMines;
started = false;
seconds = 0;
timer?.cancel();
createGrids();
notifyListeners();
resetRound(
MEDIUM,
mediumRows,
mediumColumns,
mediumMines,
);
break;
}
}

void resetRound(
String level,
int levelRows,
int levelColumns,
int levelMines,
) {
currentLevel = level;
rows = levelRows;
columns = levelColumns;
mines = levelMines;
started = false;
win = false;
lose = false;
seconds = 0;
timer?.cancel();
createGrids();
notifyListeners();
}

void createGrids() {
gridState =
List.generate(rows, (i) => List.generate(columns, (j) => empty));
Expand Down

0 comments on commit a30cfb8

Please sign in to comment.