// lib/models/sudoku_theme.dart import 'package:flutter/material.dart'; // 1. SudokuTheme 클래스 // '게임 시작' 시점에 동적으로 생성될 객체입니다. class SudokuTheme { final String name; // "숫자", "알파벳", "과일" final List 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 _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 _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 _fruitPool = [ "🍎", "🍌", "🍇", "🍓", "🍊", "🍋", "🍉", "🍑", "🍒", "🥝", "🥥", "🍍", "🥑", "🍆", "🍅", "🌽", "🥕", "🫑", "🌶️", "🥦", "🥬", "🥒", "🍄", "🥜", "🫘", "🍏", "🍐", "🍈", "🥭", "🫒" ]; static const List _koreanPool = [ "가", "나", "다", "라", "마", "바", "사", "아", "자", "차", "카", "타", "파", "하", "고", "노", "도", "로", "모", "보", "소", "오", "조", "초", "코", "구", "누", "두", "루", "무" ]; static const List _animalPool = [ "🐶", "🐱", "🐭", "🐹", "🐰", "🦊", "🐻", "🐼", "🐨", "🐯", "🦁", "🐮", "🐷", "🐸", "🐵", "🐔", "🐧", "🐦", "🐤", "🦆", "🦅", "🦉", "🦇", "🐺", "🐗", "🐴", "🦄", "🐝", "🐛", "🦋" ]; // --- 2. 홈 화면 '선택' 메뉴에 표시될 이름 리스트 --- static final List selectableThemeNames = [ random, numbers, letters, fruits, korean, animals ]; // --- 3. 테마 이름과 실제 '상징 풀'을 매핑 --- static final Map> _themePools = { numbers: _numberPool, letters: _letterPool, fruits: _fruitPool, korean: _koreanPool, animals: _animalPool, }; // --- 4. [핵심] 게임 시작 시 호출될 테마 '빌더' 함수 --- static SudokuTheme buildGameTheme(String themeName, int gridSize) { String effectiveThemeName = themeName; // 1. "랜덤"이 선택된 경우 if (themeName == random) { // "랜덤"을 제외한 실제 테마 이름 리스트에서 무작위로 하나 선택 final actualThemes = _themePools.keys.toList(); effectiveThemeName = (actualThemes..shuffle()).first; } // 2. 해당 테마의 '거대 풀'을 가져옴 (없으면 숫자로 대체) final List pool = _themePools[effectiveThemeName] ?? _numberPool; // 3. 거대 풀을 섞은 뒤, 게임에 필요한 만큼(gridSize)만 뽑음 if (pool.length < gridSize) { throw Exception("$effectiveThemeName 테마의 상징이 ${pool.length}개뿐입니다. $gridSize개가 필요합니다."); } final List selectedSymbols = (pool.toList()..shuffle()).sublist(0, gridSize); // 4. 이 게임만을 위한 '일회용' SudokuTheme 객체를 생성하여 반환 return SudokuTheme( name: effectiveThemeName, // 실제 사용된 테마 이름 (예: "과일") symbols: selectedSymbols, // 무작위로 뽑힌 기호 리스트 ); } }