diff --git a/assets/audio/turn.mp3 b/assets/audio/turn.mp3 new file mode 100644 index 0000000..141aaac Binary files /dev/null and b/assets/audio/turn.mp3 differ diff --git a/lib/core/service/app_sounds.dart b/lib/core/service/app_sounds.dart index 81bb7af..7089d88 100644 --- a/lib/core/service/app_sounds.dart +++ b/lib/core/service/app_sounds.dart @@ -16,6 +16,7 @@ class AppSounds { static const _button = 'button.mp3'; // فشردنِ دکمه‌ها static const _selectHokm = 'select_hokm.mp3'; // انتخابِ حکم static const _heartBeat = 'heart_beat.mp3'; // ثانیه‌های پایانیِ نوبت + static const _turn = 'turn.mp3'; // شروعِ نوبتِ خودِ کاربر static const _all = [ _shuffle, @@ -26,6 +27,7 @@ class AppSounds { _button, _selectHokm, _heartBeat, + _turn, ]; static final Map _pools = {}; @@ -59,6 +61,9 @@ class AppSounds { static void cut() => _play(_cut, 0.9); static void win() => _play(_win, 0.9); static void selectHokm() => _play(_selectHokm, 0.9); + static void turn() => _play(_turn, 0.9); // نوبتِ کاربر برای بازی + // شمارشِ معکوسِ شروعِ بازی (۳…۲…۱) — کلیکِ کوتاه برای هر عدد. + static void tick() => _play(_button, 0.7, cutoffMs: 200); // کنترلِ ضربانِ قلب: همیشه حداکثر یک ضربان هم‌زمان (بدون انباشت/تکرارِ سریع) // و قابلِ توقف وقتی نوبت تمام می‌شود. diff --git a/lib/feature/game/presentation/screen/game_screen.dart b/lib/feature/game/presentation/screen/game_screen.dart index 851b30e..9c1e8d0 100644 --- a/lib/feature/game/presentation/screen/game_screen.dart +++ b/lib/feature/game/presentation/screen/game_screen.dart @@ -31,6 +31,7 @@ class _GameScreenState extends State { late final HokmGame _game; Timer? _introTimer; bool _introHidden = false; + int _countdown = 0; // شمارشِ معکوسِ شروعِ بازی پس از یافتنِ حریفان (۳…۲…۱) @override void initState() { @@ -90,12 +91,23 @@ class _GameScreenState extends State { }, builder: (context, state) { if (state.state != null && _introTimer == null) { - // کمی «حریفان پیدا شد» نشان بده، بعد اوورلی را کنار بزن و همان - // لحظه انیمیشنِ بُر زدن (با صدا) را اجرا کن. - _introTimer = Timer(const Duration(milliseconds: 1000), () { - if (!mounted) return; - setState(() => _introHidden = true); - _game.endIntro(); + // حریفان پیدا شدند ⇒ شمارشِ معکوسِ ۳…۲…۱ با صدا تا کاربر بداند + // بازی در حالِ شروع است، سپس اوورلی کنار می‌رود و بُر زدن اجرا می‌شود. + _countdown = 3; // داخلِ build هستیم؛ همین build مقدار را نشان می‌دهد + AppSounds.tick(); + _introTimer = Timer.periodic(const Duration(seconds: 1), (t) { + if (!mounted) { + t.cancel(); + return; + } + if (_countdown <= 1) { + t.cancel(); + setState(() => _introHidden = true); + _game.endIntro(); + } else { + setState(() => _countdown--); + AppSounds.tick(); + } }); } return Stack( @@ -286,6 +298,42 @@ class _GameScreenState extends State { 'در حال یافتن حریفان…', style: TextStyle(color: Colors.white70, fontSize: 13), ), + ] else if (_countdown > 0) ...[ + const SizedBox(height: 14), + const Text( + 'شروع بازی', + style: TextStyle(color: Colors.white70, fontSize: 13), + ), + const SizedBox(height: 6), + TweenAnimationBuilder( + // هر عدد با یک «پاپ» ظاهر می‌شود تا واضح و جلب‌توجه باشد. + key: ValueKey(_countdown), + tween: Tween(begin: 1.6, end: 1.0), + duration: const Duration(milliseconds: 400), + curve: Curves.easeOut, + builder: (_, scale, child) => + Transform.scale(scale: scale, child: child), + child: Container( + width: 54, + height: 54, + alignment: Alignment.center, + decoration: BoxDecoration( + shape: BoxShape.circle, + gradient: const LinearGradient( + colors: [AppColors.gold, AppColors.goldDark], + ), + border: Border.all(color: Colors.white, width: 2), + ), + child: Text( + '$_countdown', + style: const TextStyle( + color: Color(0xFF3A0A12), + fontSize: 26, + fontWeight: FontWeight.bold, + ), + ), + ), + ), ], ], ), diff --git a/lib/feature/game/presentation/widgets/flame/hokm_game.dart b/lib/feature/game/presentation/widgets/flame/hokm_game.dart index 697202a..ed56786 100644 --- a/lib/feature/game/presentation/widgets/flame/hokm_game.dart +++ b/lib/feature/game/presentation/widgets/flame/hokm_game.dart @@ -45,7 +45,7 @@ class HokmGame extends FlameGame { double _shake = 0; double _t = 0; List _prevTrick = const []; - bool _cutThisTrick = false; // افکتِ بریدن فقط یک‌بار در هر دست + int _bestTrumpRank = 0; // بالاترین رتبه‌ی حکمِ بازی‌شده در دستِ جاری (برای افکتِ بریدن) int _prevHandSize = 0; // برای تشخیصِ پخشِ کارت (دستِ جدید) جهت صدای بُر زدن bool _silent = false; // هنگام خروج از میز، دیگر صدایی پخش نشود bool _introActive = true; // تا پایانِ نمایشِ «جستجوی حریف» @@ -135,17 +135,19 @@ class HokmGame extends FlameGame { } final addedOne = now.length == _prevTrick.length + 1 && _isPrefix(_prevTrick, now); - if (now.length <= 1) _cutThisTrick = false; // دستِ جدید ⇒ ریستِ افکتِ بریدن + if (now.length <= 1) _bestTrumpRank = 0; // دستِ جدید ⇒ ریستِ بالاترین حکم if (addedOne) { final card = s.trick.last; - final isCut = - s.trump != null && + // بریدن: خالِ راهبر حکم نیست و کارتِ بازی‌شده حکم است. + final isTrump = s.trump != null && s.leadSuit != null && s.leadSuit != s.trump && suitName(card.card) == s.trump; - // افکتِ بریدن فقط برای اولین بریدنِ هر دست (بریدن‌های بعدی فقط صدای گذاشتن). - if (isCut && !_cutThisTrick) { - _cutThisTrick = true; + final rank = isTrump ? rankValue(card.card) : 0; + // افکتِ بریدن فقط وقتی حکمِ بازی‌شده «دست را می‌برد» (بالاترین حکم تا کنون): + // یعنی اولین بریدن یا روبریدنِ بالاتر. حکمِ پایین‌تر (بازنده) فقط صدای گذاشتن. + if (isTrump && rank > _bestTrumpRank) { + _bestTrumpRank = rank; _shake = 1.0; add(Lightning()); AppSounds.cut(); // بریدن با حکم (شمشیر) @@ -273,6 +275,8 @@ class HokmGame extends FlameGame { _turnElapsed = 0; _beatPlayed = false; _hbAccum = 0; + // صدای «نوبتِ شما» فقط هنگامِ بازیِ کارت (نه پخش/انتخابِ حکم). + if (s.phase == 'playing' && !_dealing) AppSounds.turn(); } _turnElapsed += dt;