match-three/lib/utils/constants.dart
savinmax 3f12ce8d3f Add dynamic grid sizing support for levels
- Add gridWidth and gridHeight properties to level configuration
- Update GameGrid to accept custom dimensions instead of using constants
- Modify GridComponent to calculate gem size based on grid dimensions
- Update MatchThreeGame constructor to pass grid dimensions
- Ensure proper scaling and positioning for variable grid sizes
2025-09-21 18:06:00 +02:00

34 lines
1.1 KiB
Dart

import 'dart:math' as math;
class GameConstants {
static const double gemSize = 64.0;
static const double gridPadding = 16.0;
static const int minMatchLength = 3;
// Gem types
static const List<int> gemTypes = [0, 1, 2, 3, 4, 5];
// Animation durations
static const double swapDuration = 0.3;
static const double fallDuration = 0.5;
static const double matchDuration = 0.2;
// Scoring
static const int baseScore = 100;
static const int comboMultiplier = 50;
// Dynamic gem size calculation
static double calculateGemSize(int gridWidth, int gridHeight,
double availableWidth, double availableHeight) {
// Calculate gem size based on available space and grid dimensions
final gemSizeByWidth = (availableWidth - (2 * gridPadding)) / gridWidth;
final gemSizeByHeight = (availableHeight - (2 * gridPadding)) / gridHeight;
// Use the smaller dimension to ensure the grid fits in both directions
final calculatedSize = math.min(gemSizeByWidth, gemSizeByHeight);
// Ensure minimum size for playability and maximum size for performance
return math.max(32.0, math.min(calculatedSize, 80.0));
}
}