fix: trump trick

This commit is contained in:
2026-06-24 14:17:21 +03:30
parent e0d6763c00
commit 500c61a409
4 changed files with 70 additions and 13 deletions
Binary file not shown.
+5
View File
@@ -16,6 +16,7 @@ class AppSounds {
static const _button = 'button.mp3'; // فشردنِ دکمه‌ها static const _button = 'button.mp3'; // فشردنِ دکمه‌ها
static const _selectHokm = 'select_hokm.mp3'; // انتخابِ حکم static const _selectHokm = 'select_hokm.mp3'; // انتخابِ حکم
static const _heartBeat = 'heart_beat.mp3'; // ثانیه‌های پایانیِ نوبت static const _heartBeat = 'heart_beat.mp3'; // ثانیه‌های پایانیِ نوبت
static const _turn = 'turn.mp3'; // شروعِ نوبتِ خودِ کاربر
static const _all = [ static const _all = [
_shuffle, _shuffle,
@@ -26,6 +27,7 @@ class AppSounds {
_button, _button,
_selectHokm, _selectHokm,
_heartBeat, _heartBeat,
_turn,
]; ];
static final Map<String, AudioPool> _pools = {}; static final Map<String, AudioPool> _pools = {};
@@ -59,6 +61,9 @@ class AppSounds {
static void cut() => _play(_cut, 0.9); static void cut() => _play(_cut, 0.9);
static void win() => _play(_win, 0.9); static void win() => _play(_win, 0.9);
static void selectHokm() => _play(_selectHokm, 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);
// کنترلِ ضربانِ قلب: همیشه حداکثر یک ضربان هم‌زمان (بدون انباشت/تکرارِ سریع) // کنترلِ ضربانِ قلب: همیشه حداکثر یک ضربان هم‌زمان (بدون انباشت/تکرارِ سریع)
// و قابلِ توقف وقتی نوبت تمام می‌شود. // و قابلِ توقف وقتی نوبت تمام می‌شود.
@@ -31,6 +31,7 @@ class _GameScreenState extends State<GameScreen> {
late final HokmGame _game; late final HokmGame _game;
Timer? _introTimer; Timer? _introTimer;
bool _introHidden = false; bool _introHidden = false;
int _countdown = 0; // شمارشِ معکوسِ شروعِ بازی پس از یافتنِ حریفان (۳…۲…۱)
@override @override
void initState() { void initState() {
@@ -90,12 +91,23 @@ class _GameScreenState extends State<GameScreen> {
}, },
builder: (context, state) { builder: (context, state) {
if (state.state != null && _introTimer == null) { if (state.state != null && _introTimer == null) {
// کمی «حریفان پیدا شد» نشان بده، بعد اوورلی را کنار بزن و همان // حریفان پیدا شدند ⇒ شمارشِ معکوسِ ۳…۲…۱ با صدا تا کاربر بداند
// لحظه انیمیشنِ بُر زدن (با صدا) را اجرا کن. // بازی در حالِ شروع است، سپس اوورلی کنار می‌رود و بُر زدن اجرا می‌شود.
_introTimer = Timer(const Duration(milliseconds: 1000), () { _countdown = 3; // داخلِ build هستیم؛ همین build مقدار را نشان می‌دهد
if (!mounted) return; AppSounds.tick();
_introTimer = Timer.periodic(const Duration(seconds: 1), (t) {
if (!mounted) {
t.cancel();
return;
}
if (_countdown <= 1) {
t.cancel();
setState(() => _introHidden = true); setState(() => _introHidden = true);
_game.endIntro(); _game.endIntro();
} else {
setState(() => _countdown--);
AppSounds.tick();
}
}); });
} }
return Stack( return Stack(
@@ -286,6 +298,42 @@ class _GameScreenState extends State<GameScreen> {
'در حال یافتن حریفان…', 'در حال یافتن حریفان…',
style: TextStyle(color: Colors.white70, fontSize: 13), 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<double>(
// هر عدد با یک «پاپ» ظاهر می‌شود تا واضح و جلب‌توجه باشد.
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,
),
),
),
),
], ],
], ],
), ),
@@ -45,7 +45,7 @@ class HokmGame extends FlameGame {
double _shake = 0; double _shake = 0;
double _t = 0; double _t = 0;
List<String> _prevTrick = const []; List<String> _prevTrick = const [];
bool _cutThisTrick = false; // افکتِ بریدن فقط یک‌بار در هر دست int _bestTrumpRank = 0; // بالاترین رتبه‌ی حکمِ بازی‌شده در دستِ جاری (برای افکتِ بریدن)
int _prevHandSize = 0; // برای تشخیصِ پخشِ کارت (دستِ جدید) جهت صدای بُر زدن int _prevHandSize = 0; // برای تشخیصِ پخشِ کارت (دستِ جدید) جهت صدای بُر زدن
bool _silent = false; // هنگام خروج از میز، دیگر صدایی پخش نشود bool _silent = false; // هنگام خروج از میز، دیگر صدایی پخش نشود
bool _introActive = true; // تا پایانِ نمایشِ «جستجوی حریف» bool _introActive = true; // تا پایانِ نمایشِ «جستجوی حریف»
@@ -135,17 +135,19 @@ class HokmGame extends FlameGame {
} }
final addedOne = final addedOne =
now.length == _prevTrick.length + 1 && _isPrefix(_prevTrick, now); now.length == _prevTrick.length + 1 && _isPrefix(_prevTrick, now);
if (now.length <= 1) _cutThisTrick = false; // دستِ جدید ⇒ ریستِ افکتِ بریدن if (now.length <= 1) _bestTrumpRank = 0; // دستِ جدید ⇒ ریستِ بالاترین حکم
if (addedOne) { if (addedOne) {
final card = s.trick.last; final card = s.trick.last;
final isCut = // بریدن: خالِ راهبر حکم نیست و کارتِ بازی‌شده حکم است.
s.trump != null && final isTrump = s.trump != null &&
s.leadSuit != null && s.leadSuit != null &&
s.leadSuit != s.trump && s.leadSuit != s.trump &&
suitName(card.card) == s.trump; suitName(card.card) == s.trump;
// افکتِ بریدن فقط برای اولین بریدنِ هر دست (بریدن‌های بعدی فقط صدای گذاشتن). final rank = isTrump ? rankValue(card.card) : 0;
if (isCut && !_cutThisTrick) { // افکتِ بریدن فقط وقتی حکمِ بازی‌شده «دست را می‌برد» (بالاترین حکم تا کنون):
_cutThisTrick = true; // یعنی اولین بریدن یا روبریدنِ بالاتر. حکمِ پایین‌تر (بازنده) فقط صدای گذاشتن.
if (isTrump && rank > _bestTrumpRank) {
_bestTrumpRank = rank;
_shake = 1.0; _shake = 1.0;
add(Lightning()); add(Lightning());
AppSounds.cut(); // بریدن با حکم (شمشیر) AppSounds.cut(); // بریدن با حکم (شمشیر)
@@ -273,6 +275,8 @@ class HokmGame extends FlameGame {
_turnElapsed = 0; _turnElapsed = 0;
_beatPlayed = false; _beatPlayed = false;
_hbAccum = 0; _hbAccum = 0;
// صدای «نوبتِ شما» فقط هنگامِ بازیِ کارت (نه پخش/انتخابِ حکم).
if (s.phase == 'playing' && !_dealing) AppSounds.turn();
} }
_turnElapsed += dt; _turnElapsed += dt;