From 7372c015c3d0dbe0f1bc9580c2f551268520fe06 Mon Sep 17 00:00:00 2001 From: tanglong <842690096@qq.com> Date: Mon, 20 Oct 2025 13:37:58 +0800 Subject: [PATCH] =?UTF-8?q?=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Views/JumpRope/GroupJumpRope.xaml.cs | 62 ++++++++++-------- .../Views/JumpRope/MusicJumpRope.xaml.cs | 63 +++++++++++-------- 2 files changed, 75 insertions(+), 50 deletions(-) diff --git a/Wpf_AiSportsMicrospace/Views/JumpRope/GroupJumpRope.xaml.cs b/Wpf_AiSportsMicrospace/Views/JumpRope/GroupJumpRope.xaml.cs index d2f8def..861350b 100644 --- a/Wpf_AiSportsMicrospace/Views/JumpRope/GroupJumpRope.xaml.cs +++ b/Wpf_AiSportsMicrospace/Views/JumpRope/GroupJumpRope.xaml.cs @@ -170,21 +170,33 @@ namespace Wpf_AiSportsMicrospace.Views switch (_currentGameState) { case GameState.NotStarted: // 未开始 - int rightWaving = DetectRightHandRaise(humans); - if (rightWaving >= 3) + int leftWaving = DetectLeftHandRaise(humans); + if (leftWaving == 5) { - switch (rightWaving) + _mainWin.HumanFrameUpdated -= OnHumanFrameUpdated; + _mainWin.WebcamClient.StopExtract(); + + // 举左手逻辑,例如结束动画或退出 + var newPage = new Home(); + _mainWin?.SwitchPageWithMaskAnimation(newPage, true); + } + else { + int rightWaving = DetectRightHandRaise(humans); + if (rightWaving >= 3) { - case (int)WavingAction.FirstHand: - StartCountdown(3); - break; - case (int)WavingAction.Raising: - UpdateCountdown(); - break; - case (int)WavingAction.RaiseHand: - FinishCountdown(); - _currentGameState = GameState.Running; // 倒计时完成 → 游戏开始 - break; + switch (rightWaving) + { + case (int)WavingAction.FirstHand: + StartCountdown(3); + break; + case (int)WavingAction.Raising: + UpdateCountdown(); + break; + case (int)WavingAction.RaiseHand: + FinishCountdown(); + _currentGameState = GameState.Running; // 倒计时完成 → 游戏开始 + break; + } } } break; @@ -196,18 +208,18 @@ namespace Wpf_AiSportsMicrospace.Views // if (CheckGameFinished()) _currentGameState = GameState.Finished; break; - case GameState.Finished: // 游戏完成 - int leftWaving = DetectLeftHandRaise(humans); - if (leftWaving == 5) - { - _mainWin.HumanFrameUpdated -= OnHumanFrameUpdated; - _mainWin.WebcamClient.StopExtract(); + //case GameState.Finished: // 游戏完成 + // int leftWaving = DetectLeftHandRaise(humans); + // if (leftWaving == 5) + // { + // _mainWin.HumanFrameUpdated -= OnHumanFrameUpdated; + // _mainWin.WebcamClient.StopExtract(); - // 举左手逻辑,例如结束动画或退出 - var newPage = new Home(); - _mainWin?.SwitchPageWithMaskAnimation(newPage, true); - } - break; + // // 举左手逻辑,例如结束动画或退出 + // var newPage = new Home(); + // _mainWin?.SwitchPageWithMaskAnimation(newPage, true); + // } + // break; } } catch (Exception ex) @@ -283,7 +295,7 @@ namespace Wpf_AiSportsMicrospace.Views ShowRankingBoard(RankingItemList); Utils.StopBackgroundMusic(); - _currentGameState = GameState.Finished; + _currentGameState = GameState.Running; _mainWin.HumanFrameUpdated += OnHumanFrameUpdated; _mainWin.WebcamClient.StartExtract(); } diff --git a/Wpf_AiSportsMicrospace/Views/JumpRope/MusicJumpRope.xaml.cs b/Wpf_AiSportsMicrospace/Views/JumpRope/MusicJumpRope.xaml.cs index d3365c3..e526149 100644 --- a/Wpf_AiSportsMicrospace/Views/JumpRope/MusicJumpRope.xaml.cs +++ b/Wpf_AiSportsMicrospace/Views/JumpRope/MusicJumpRope.xaml.cs @@ -171,21 +171,34 @@ namespace Wpf_AiSportsMicrospace.Views.JumpRope switch (_currentGameState) { case GameState.NotStarted: // 未开始 - int rightWaving = DetectRightHandRaise(humans); - if (rightWaving >= 3) + int leftWaving = DetectLeftHandRaise(humans); + if (leftWaving == 5) { - switch (rightWaving) + _mainWin.HumanFrameUpdated -= OnHumanFrameUpdated; + _mainWin.WebcamClient.StopExtract(); + + // 举左手逻辑,例如结束动画或退出 + var newPage = new Home(); + _mainWin?.SwitchPageWithMaskAnimation(newPage, true); + } + else + { + int rightWaving = DetectRightHandRaise(humans); + if (rightWaving >= 3) { - case (int)WavingAction.FirstHand: - StartCountdown(3); - break; - case (int)WavingAction.Raising: - UpdateCountdown(); - break; - case (int)WavingAction.RaiseHand: - FinishCountdown(); - _currentGameState = GameState.Running; // 倒计时完成 → 游戏开始 - break; + switch (rightWaving) + { + case (int)WavingAction.FirstHand: + StartCountdown(3); + break; + case (int)WavingAction.Raising: + UpdateCountdown(); + break; + case (int)WavingAction.RaiseHand: + FinishCountdown(); + _currentGameState = GameState.Running; // 倒计时完成 → 游戏开始 + break; + } } } break; @@ -197,18 +210,18 @@ namespace Wpf_AiSportsMicrospace.Views.JumpRope // if (CheckGameFinished()) _currentGameState = GameState.Finished; break; - case GameState.Finished: // 游戏完成 - int leftWaving = DetectLeftHandRaise(humans); - if (leftWaving == 5) - { - _mainWin.HumanFrameUpdated -= OnHumanFrameUpdated; - _mainWin.WebcamClient.StopExtract(); + //case GameState.Finished: // 游戏完成 + // int leftWaving = DetectLeftHandRaise(humans); + // if (leftWaving == 5) + // { + // _mainWin.HumanFrameUpdated -= OnHumanFrameUpdated; + // _mainWin.WebcamClient.StopExtract(); - // 举左手逻辑,例如结束动画或退出 - var newPage = new Home(); - _mainWin?.SwitchPageWithMaskAnimation(newPage, true); - } - break; + // // 举左手逻辑,例如结束动画或退出 + // var newPage = new Home(); + // _mainWin?.SwitchPageWithMaskAnimation(newPage, true); + // } + // break; } } catch (Exception ex) @@ -288,7 +301,7 @@ namespace Wpf_AiSportsMicrospace.Views.JumpRope // 更新游戏状态 - _currentGameState = GameState.Finished; + _currentGameState = GameState.Running; // 恢复视频流 Application.Current.Dispatcher.Invoke(() =>