...
This commit is contained in:
@@ -35,10 +35,7 @@ class CardFlipController with ChangeNotifier {
|
||||
bool _isGameStarted = false;
|
||||
bool get isGameStarted => _isGameStarted;
|
||||
|
||||
// [🔥 신규] 매칭된 쌍의 개수
|
||||
int get matchedPairsCount => _cards.where((c) => c.isMatched).length ~/ 2;
|
||||
|
||||
// [🔥 신규] 총 쌍의 개수
|
||||
int get totalPairsCount => _cards.length ~/ 2;
|
||||
|
||||
void setUserInfo(String userId, String? userName) {
|
||||
@@ -91,32 +88,56 @@ class CardFlipController with ChangeNotifier {
|
||||
final Random random = Random();
|
||||
|
||||
if (difficulty.contentType == CardContentType.calculation) {
|
||||
// [🔥 수정] 연산 모드
|
||||
final Set<int> usedResults = {};
|
||||
|
||||
// 레벨 4인지 확인 (한 자릿수 덧셈/뺄셈만)
|
||||
final bool isLevel4 = difficulty.levelIndex == 4;
|
||||
|
||||
for (int i = 0; i < pairsCount; i++) {
|
||||
String equation;
|
||||
String answer;
|
||||
int result;
|
||||
|
||||
while (true) {
|
||||
final int opType = random.nextInt(3);
|
||||
// Lv 4: 0(덧셈), 1(뺄셈)만 선택 / 그 외: 0, 1, 2(곱셈) 선택
|
||||
final int opType = isLevel4 ? random.nextInt(2) : random.nextInt(3);
|
||||
int a, b;
|
||||
if (opType == 0) { // +
|
||||
a = random.nextInt(15) + 1;
|
||||
b = random.nextInt(15) + 1;
|
||||
|
||||
if (opType == 0) { // 덧셈 (+)
|
||||
if (isLevel4) {
|
||||
// 한 자릿수 (1~9)
|
||||
a = random.nextInt(9) + 1;
|
||||
b = random.nextInt(9) + 1;
|
||||
} else {
|
||||
// 두 자릿수 포함 (1~15)
|
||||
a = random.nextInt(15) + 1;
|
||||
b = random.nextInt(15) + 1;
|
||||
}
|
||||
result = a + b;
|
||||
equation = "$a + $b";
|
||||
} else if (opType == 1) { // -
|
||||
a = random.nextInt(20) + 5;
|
||||
b = random.nextInt(a - 1) + 1;
|
||||
|
||||
} else if (opType == 1) { // 뺄셈 (-)
|
||||
if (isLevel4) {
|
||||
// 결과가 양수이고 한 자릿수 내에서 처리되도록
|
||||
a = random.nextInt(9) + 2; // 2~10
|
||||
b = random.nextInt(a - 1) + 1;
|
||||
} else {
|
||||
a = random.nextInt(20) + 5;
|
||||
b = random.nextInt(a - 1) + 1;
|
||||
}
|
||||
result = a - b;
|
||||
equation = "$a - $b";
|
||||
} else { // *
|
||||
|
||||
} else { // 곱셈 (*)
|
||||
// Lv 4에서는 이 블록에 들어오지 않음
|
||||
a = random.nextInt(9) + 2;
|
||||
b = random.nextInt(5) + 2;
|
||||
result = a * b;
|
||||
equation = "$a x $b";
|
||||
}
|
||||
|
||||
// 정답 중복 방지
|
||||
if (!usedResults.contains(result)) {
|
||||
usedResults.add(result);
|
||||
answer = result.toString();
|
||||
@@ -130,6 +151,7 @@ class CardFlipController with ChangeNotifier {
|
||||
}
|
||||
}
|
||||
else if (difficulty.contentType == CardContentType.pairWord) {
|
||||
// 연상 모드
|
||||
var entries = CardFlipDifficulties.wordPairs.entries.toList()..shuffle();
|
||||
for (int i = 0; i < pairsCount; i++) {
|
||||
var entry = entries[i % entries.length];
|
||||
@@ -139,6 +161,7 @@ class CardFlipController with ChangeNotifier {
|
||||
}
|
||||
}
|
||||
else {
|
||||
// 동일 매칭 모드
|
||||
List<String> pool = List.of(CardFlipDifficulties.emojis)..shuffle();
|
||||
for (int i = 0; i < pairsCount; i++) {
|
||||
String content;
|
||||
|
||||
Reference in New Issue
Block a user