mnemo_cards/mnemo_cards_snake_game/lib/models/game_items.dart

99 lines
1.9 KiB
Dart
Raw Normal View History

2025-11-10 23:55:41 +00:00
import 'dart:math';
import 'package:flutter/material.dart';
class GameItem {
final Offset position;
final ItemType type;
final String content;
final bool isCorrect;
final double value;
final int maxCycles;
int remainingCycles;
GameItem({
required this.position,
required this.type,
required this.content,
this.isCorrect = true,
this.value = 1.0,
required this.maxCycles,
this.remainingCycles = -1,
}) {
if (remainingCycles == -1) {
remainingCycles = maxCycles;
}
}
bool get isExpired => remainingCycles <= 0;
double get remainingLifetimePercent =>
(remainingCycles / 10.0).clamp(0.0, 1.0);
// Calculate opacity based on remaining lifetime
double get opacity {
if (remainingLifetimePercent >= 1.0) {
return 1.0;
} else {
return (remainingLifetimePercent).clamp(0.2, 1.0);
}
}
// Decrease remaining cycles by 1
void decrementCycle() {
remainingCycles--;
}
}
enum ItemType {
letter,
word,
slowTime,
health,
scoreMultiplier,
categoryChallenge,
shield, // Temporary invincibility
magnet, // Attracts nearby items
}
class PowerUp {
final PowerUpType type;
final Duration duration;
final double value;
DateTime? activatedAt;
PowerUp({
required this.type,
required this.duration,
required this.value,
});
bool get isActive {
if (activatedAt == null) return false;
return DateTime.now().difference(activatedAt!) < duration;
}
void activate() {
activatedAt = DateTime.now();
}
}
enum PowerUpType {
slowTime,
scoreMultiplier,
shield, // Temporary invincibility
magnet // Attracts nearby items
}
class Category {
final String name;
final List<String> correctAnswers;
final List<String> wrongAnswers;
Category({
required this.name,
required this.correctAnswers,
required this.wrongAnswers,
});
}