90 lines
1.7 KiB
Dart
90 lines
1.7 KiB
Dart
import 'dart:async';
|
|
import 'dart:ui';
|
|
|
|
import 'package:match_magic/game/board.dart';
|
|
|
|
enum GameMode {
|
|
timeAttack,
|
|
levelProgression,
|
|
}
|
|
|
|
class GameModeManager {
|
|
final bool currentMode;
|
|
final VoidCallback onGameOver;
|
|
|
|
int remainingTime = 20;
|
|
int targetScore = 5000;
|
|
int currentLevel = 1;
|
|
static int movesLeft = 20;
|
|
|
|
Timer? _timer;
|
|
|
|
GameModeManager({
|
|
required this.currentMode,
|
|
required this.onGameOver,
|
|
});
|
|
|
|
void initializeMode() {
|
|
if (currentMode) {
|
|
_startLevelProgressionMode();
|
|
} else if (!currentMode) {
|
|
_startTimeAttackMode();
|
|
}
|
|
}
|
|
|
|
// Reset modes
|
|
void resetMode() {
|
|
_timer?.cancel();
|
|
remainingTime = 20;
|
|
currentLevel = 1;
|
|
movesLeft = 20;
|
|
}
|
|
|
|
// Time mode
|
|
void _startTimeAttackMode() {
|
|
_timer = Timer.periodic(Duration(seconds: 1), (timer) {
|
|
if (remainingTime > 0) {
|
|
remainingTime--;
|
|
} else {
|
|
onGameOver();
|
|
_timer?.cancel();
|
|
}
|
|
});
|
|
}
|
|
|
|
// Levels mode
|
|
void _startLevelProgressionMode() {
|
|
movesLeft = 20; // Number of moves per level
|
|
}
|
|
|
|
// Time update
|
|
void updateTime(double dt) {}
|
|
|
|
// Game Completion Logic
|
|
bool isGameOverCondition() {
|
|
if (!currentMode) {
|
|
return remainingTime <= 0;
|
|
} else if (currentMode) {
|
|
return movesLeft <= 0;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
// Moving to the next level
|
|
void nextLevel() {
|
|
if (Board.score >= targetScore) {
|
|
currentLevel++;
|
|
targetScore += 100;
|
|
movesLeft = 20;
|
|
}
|
|
}
|
|
|
|
// Updating the number of remaining moves
|
|
void updateMoves(int movesUsed) {
|
|
movesLeft -= movesUsed;
|
|
if (movesLeft <= 0 && Board.score < targetScore) {
|
|
onGameOver();
|
|
}
|
|
}
|
|
}
|