This commit is contained in:
tanglong 2026-03-30 16:50:42 +08:00
parent 2bad6bedd2
commit 1bec6bbb84

View File

@ -42,8 +42,6 @@ namespace Views.SquatFu
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
private GameState _currentGameState = GameState.NotStarted;
private readonly object _updateLock = new object();
private readonly Dictionary<int, (string lastNumber, DateTime lastChangeTime, string currentState)> _jumpStatus = new Dictionary<int, (string, DateTime, string)>();
private WhackAMoleContext _WhackAMoleContext;
Image tipImage;
@ -80,11 +78,14 @@ namespace Views.SquatFu
_WhackAMoleContext.CirclePositions = Utils.GetPointsList(pointCount, cfg);
DrawCirclesWithText();
// 播放音乐
PlayMusic("raisehand.mp3");
_mainWin.HumanFrameUpdated += OnHumanFrameUpdated;
_mainWin.WebcamClient.StartExtract();
DrawCirclesWithText();
// 播放音乐
PlayMusic("raisehand.mp3");
}
private void UserControl_Unloaded(object sender, RoutedEventArgs e)
@ -180,61 +181,51 @@ namespace Views.SquatFu
private bool _isCountdownStarted = false; // 新增标记
private void OnHumanFrameUpdated(object sender, List<Human> humans)
{
try
if (humans == null || humans.Count == 0) return;
switch (_currentGameState)
{
if (humans == null || humans.Count == 0) return;
switch (_currentGameState)
{
case GameState.NotStarted: // 未开始
if (!_isCountdownStarted) // 只有倒计时未开始才检测左手
case GameState.NotStarted: // 未开始
if (!_isCountdownStarted) // 只有倒计时未开始才检测左手
{
int leftWaving = sportOperate.VerifyLeftWavingAction(humans);
if (leftWaving == 5)
{
int leftWaving = sportOperate.VerifyLeftWavingAction(humans);
if (leftWaving == 5)
{
_isCountdownStarted = true;
_mainWin.HumanFrameUpdated -= OnHumanFrameUpdated;
_isCountdownStarted = true;
_mainWin.HumanFrameUpdated -= OnHumanFrameUpdated;
// 举左手逻辑,例如结束动画或退出
var newPage = new Home();
_mainWin?.SwitchPageWithMaskAnimation(newPage, true);
return; // 提前退出
}
// 举左手逻辑,例如结束动画或退出
var newPage = new Home();
_mainWin?.SwitchPageWithMaskAnimation(newPage, true);
return; // 提前退出
}
}
int rightWaving = sportOperate.VerifyRightWavingAction(humans);
if (rightWaving >= 3 && RankingGrid.Visibility != Visibility.Visible)
int rightWaving = sportOperate.VerifyRightWavingAction(humans);
if (rightWaving >= 3 && RankingGrid.Visibility != Visibility.Visible)
{
switch (rightWaving)
{
switch (rightWaving)
{
case (int)WavingAction.FirstHand:
_currentGameState = GameState.Running;
StartCountdown(3);
_isCountdownStarted = true; // 倒计时开始,停止左手检测
break;
}
case (int)WavingAction.FirstHand:
_currentGameState = GameState.Running;
StartCountdown(3);
_isCountdownStarted = true; // 倒计时开始,停止左手检测
break;
}
break;
}
break;
case GameState.Running: // 游戏进行中
UpdateCircleCounts(humans);
break;
}
}
catch (Exception ex)
{
Console.WriteLine("OnFrameExtracted error: " + ex.Message);
case GameState.Running: // 游戏进行中
UpdateCircleCounts(humans);
break;
}
}
private double _currentCountdown = 3600;
private DateTime _lastUpdateTime = DateTime.Now;
private async void StartCountdown(int start = 3)
{
_mainWin.ShowCountDownAnimation();
Utils.PlayBackgroundMusic("whackamole.mp3", false);
Utils.PlayBackgroundMusic("countdown_3.mp3", false);
//开始人脸识别 =============================================
//Action < VideoFrame > handler = null;
@ -279,9 +270,10 @@ namespace Views.SquatFu
countdownText.Text = "GO!";
countdownGrid.Visibility = Visibility.Hidden;
// 播放背景音乐(循环)
Utils.PlayBackgroundMusic("homeprojectselected1.mp3", true);
Utils.PlayBackgroundMusic("whackamole.mp3", false);
// 启动60秒倒计时(独立任务)
StartGameCountdown(60);