flutter_sudoku/lib/models/sudoku_theme.dart

117 lines
4.1 KiB
Dart
Raw Permalink Normal View History

2025-11-07 17:07:22 +09:00
// lib/models/sudoku_theme.dart
import 'package:flutter/material.dart';
// 1. SudokuTheme 클래스
// '게임 시작' 시점에 동적으로 생성될 객체입니다.
class SudokuTheme {
final String name; // "숫자", "알파벳", "과일"
final List<String> symbols; // 👈 '게임에 실제 사용할' 무작위로 뽑힌 기호 리스트
const SudokuTheme({required this.name, required this.symbols});
// 1-based 정수(1)를 테마 기호("🍎")로 변환
String getSymbol(int value) {
if (value > 0 && value <= symbols.length) {
return symbols[value - 1]; // 1 -> index 0
}
return '?';
}
// 테마 기호("🍎")를 1-based 정수(1)로 변환
int getValue(String symbol) {
int index = symbols.indexOf(symbol);
if (index != -1) {
return index + 1; // index 0 -> 1
}
return 0;
}
}
// 2. AppThemes 클래스 (테마 저장소 역할)
class AppThemes {
// --- 테마 이름 정의 ---
static const String random = "랜덤";
static const String numbers = "숫자";
static const String letters = "알파벳";
static const String fruits = "과일";
static const String korean = "한글";
static const String animals = "동물";
// --- 1. 거대한 '상징 풀' 정의 (25개 이상) ---
static const List<String> _numberPool = [
"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16",
"17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30"
];
static const List<String> _letterPool = [
"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P",
"Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"
];
static const List<String> _fruitPool = [
"🍎", "🍌", "🍇", "🍓", "🍊", "🍋", "🍉", "🍑", "🍒", "🥝", "🥥", "🍍", "🥑", "🍆", "🍅", "🌽",
"🥕", "🫑", "🌶️", "🥦", "🥬", "🥒", "🍄", "🥜", "🫘", "🍏", "🍐", "🍈", "🥭", "🫒"
];
static const List<String> _koreanPool = [
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "", "", "", "", ""
];
static const List<String> _animalPool = [
"🐶", "🐱", "🐭", "🐹", "🐰", "🦊", "🐻", "🐼", "🐨", "🐯", "🦁", "🐮", "🐷", "🐸", "🐵", "🐔",
"🐧", "🐦", "🐤", "🦆", "🦅", "🦉", "🦇", "🐺", "🐗", "🐴", "🦄", "🐝", "🐛", "🦋"
];
// --- 2. 홈 화면 '선택' 메뉴에 표시될 이름 리스트 ---
static final List<String> selectableThemeNames = [
random,
numbers,
letters,
fruits,
korean,
animals
];
// --- 3. 테마 이름과 실제 '상징 풀'을 매핑 ---
static final Map<String, List<String>> _themePools = {
numbers: _numberPool,
letters: _letterPool,
fruits: _fruitPool,
korean: _koreanPool,
animals: _animalPool,
};
// --- 4. [핵심] 게임 시작 시 호출될 테마 '빌더' 함수 ---
2025-11-11 14:38:15 +09:00
static SudokuTheme buildGameTheme(String themeName, int gridSize, {bool isEasyMode = false}) { // 👈 [수정]
2025-11-07 17:07:22 +09:00
String effectiveThemeName = themeName;
if (themeName == random) {
final actualThemes = _themePools.keys.toList();
effectiveThemeName = (actualThemes..shuffle()).first;
}
final List<String> pool = _themePools[effectiveThemeName] ?? _numberPool;
if (pool.length < gridSize) {
throw Exception("$effectiveThemeName 테마의 상징이 ${pool.length}개뿐입니다. $gridSize개가 필요합니다.");
}
2025-11-11 14:38:15 +09:00
List<String> selectedSymbols;
// 🔽 [수정] 'isEasyMode'가 true이면 섞지 않고 순서대로 뽑음
if (isEasyMode) {
// (예: 4x4 Easy -> 1,2,3,4 또는 A,B,C,D)
selectedSymbols = pool.sublist(0, gridSize);
} else {
// 그 외: 거대 풀을 섞은 뒤, gridSize만큼 뽑음
selectedSymbols = (pool.toList()..shuffle()).sublist(0, gridSize);
}
2025-11-07 17:07:22 +09:00
return SudokuTheme(
2025-11-11 14:38:15 +09:00
name: effectiveThemeName,
symbols: selectedSymbols,
2025-11-07 17:07:22 +09:00
);
}
}