Compare commits
No commits in common. "3057f34cdab3e43ef3a085e744d9d5e720a59289" and "c992593be144d0aa8b110be2912ae491bd6bad0f" have entirely different histories.
3057f34cda
...
c992593be1
@ -8,7 +8,6 @@ namespace Enum
|
|||||||
{
|
{
|
||||||
NotStarted, // 游戏未开始
|
NotStarted, // 游戏未开始
|
||||||
Running, // 游戏进行中
|
Running, // 游戏进行中
|
||||||
Finished, // 游戏完成
|
Finished // 游戏完成
|
||||||
RaiseHand
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -162,19 +162,14 @@ namespace Wpf_AiSportsMicrospace.Views
|
|||||||
// 可在这里绑定抽帧事件
|
// 可在这里绑定抽帧事件
|
||||||
_mainWin.HumanFrameUpdated += OnHumanFrameUpdated;
|
_mainWin.HumanFrameUpdated += OnHumanFrameUpdated;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool _isCountdownStarted = false; // 新增标记
|
|
||||||
private void OnHumanFrameUpdated(object sender, List<Human> humans)
|
private void OnHumanFrameUpdated(object sender, List<Human> humans)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (humans == null || humans.Count == 0) return;
|
if (humans == null || humans.Count == 0) return;
|
||||||
|
|
||||||
switch (_currentGameState)
|
switch (_currentGameState)
|
||||||
{
|
{
|
||||||
case GameState.NotStarted: // 未开始
|
case GameState.NotStarted: // 未开始
|
||||||
if (!_isCountdownStarted) // 只有倒计时未开始才检测左手
|
|
||||||
{
|
|
||||||
int leftWaving = DetectLeftHandRaise(humans);
|
int leftWaving = DetectLeftHandRaise(humans);
|
||||||
if (leftWaving == 5)
|
if (leftWaving == 5)
|
||||||
{
|
{
|
||||||
@ -184,10 +179,8 @@ namespace Wpf_AiSportsMicrospace.Views
|
|||||||
// 举左手逻辑,例如结束动画或退出
|
// 举左手逻辑,例如结束动画或退出
|
||||||
var newPage = new Home();
|
var newPage = new Home();
|
||||||
_mainWin?.SwitchPageWithMaskAnimation(newPage, true);
|
_mainWin?.SwitchPageWithMaskAnimation(newPage, true);
|
||||||
return; // 提前退出
|
|
||||||
}
|
}
|
||||||
}
|
else {
|
||||||
|
|
||||||
int rightWaving = DetectRightHandRaise(humans);
|
int rightWaving = DetectRightHandRaise(humans);
|
||||||
if (rightWaving >= 3)
|
if (rightWaving >= 3)
|
||||||
{
|
{
|
||||||
@ -195,7 +188,6 @@ namespace Wpf_AiSportsMicrospace.Views
|
|||||||
{
|
{
|
||||||
case (int)WavingAction.FirstHand:
|
case (int)WavingAction.FirstHand:
|
||||||
StartCountdown(3);
|
StartCountdown(3);
|
||||||
_isCountdownStarted = true; // 倒计时开始,停止左手检测
|
|
||||||
break;
|
break;
|
||||||
case (int)WavingAction.Raising:
|
case (int)WavingAction.Raising:
|
||||||
UpdateCountdown();
|
UpdateCountdown();
|
||||||
@ -206,11 +198,28 @@ namespace Wpf_AiSportsMicrospace.Views
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GameState.Running: // 游戏进行中
|
case GameState.Running: // 游戏进行中
|
||||||
UpdateCircleCounts(humans);
|
UpdateCircleCounts(humans);
|
||||||
|
|
||||||
|
// 可选:判断游戏结束条件,将状态切换到 Finished
|
||||||
|
// if (CheckGameFinished()) _currentGameState = GameState.Finished;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
//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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -287,8 +296,6 @@ namespace Wpf_AiSportsMicrospace.Views
|
|||||||
Utils.StopBackgroundMusic();
|
Utils.StopBackgroundMusic();
|
||||||
|
|
||||||
_currentGameState = GameState.NotStarted;
|
_currentGameState = GameState.NotStarted;
|
||||||
|
|
||||||
_isCountdownStarted = false;
|
|
||||||
_mainWin.HumanFrameUpdated += OnHumanFrameUpdated;
|
_mainWin.HumanFrameUpdated += OnHumanFrameUpdated;
|
||||||
_mainWin.WebcamClient.StartExtract();
|
_mainWin.WebcamClient.StartExtract();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,7 +25,7 @@
|
|||||||
<Grid Width="260" Height="130" VerticalAlignment="Top" HorizontalAlignment="Center" Margin="00,830,00,0" Visibility="Visible" x:Name="countdownGrid">
|
<Grid Width="260" Height="130" VerticalAlignment="Top" HorizontalAlignment="Center" Margin="00,830,00,0" Visibility="Visible" x:Name="countdownGrid">
|
||||||
<Border Background="#9e4ff9" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Opacity="0.5" CornerRadius="30" />
|
<Border Background="#9e4ff9" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Opacity="0.5" CornerRadius="30" />
|
||||||
<TextBlock x:Name="countdownText"
|
<TextBlock x:Name="countdownText"
|
||||||
Text="00"
|
Text="100"
|
||||||
FontSize="120"
|
FontSize="120"
|
||||||
FontWeight="Bold"
|
FontWeight="Bold"
|
||||||
Foreground="#fff"
|
Foreground="#fff"
|
||||||
|
|||||||
@ -162,18 +162,14 @@ namespace Wpf_AiSportsMicrospace.Views.JumpRope
|
|||||||
// 可在这里绑定抽帧事件
|
// 可在这里绑定抽帧事件
|
||||||
_mainWin.HumanFrameUpdated += OnHumanFrameUpdated;
|
_mainWin.HumanFrameUpdated += OnHumanFrameUpdated;
|
||||||
}
|
}
|
||||||
private bool _isCountdownStarted = false; // 新增标记
|
|
||||||
private void OnHumanFrameUpdated(object sender, List<Human> humans)
|
private void OnHumanFrameUpdated(object sender, List<Human> humans)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (humans == null || humans.Count == 0) return;
|
if (humans == null || humans.Count == 0) return;
|
||||||
|
|
||||||
switch (_currentGameState)
|
switch (_currentGameState)
|
||||||
{
|
{
|
||||||
case GameState.NotStarted: // 未开始
|
case GameState.NotStarted: // 未开始
|
||||||
if (!_isCountdownStarted) // 只有倒计时未开始才检测左手
|
|
||||||
{
|
|
||||||
int leftWaving = DetectLeftHandRaise(humans);
|
int leftWaving = DetectLeftHandRaise(humans);
|
||||||
if (leftWaving == 5)
|
if (leftWaving == 5)
|
||||||
{
|
{
|
||||||
@ -183,10 +179,9 @@ namespace Wpf_AiSportsMicrospace.Views.JumpRope
|
|||||||
// 举左手逻辑,例如结束动画或退出
|
// 举左手逻辑,例如结束动画或退出
|
||||||
var newPage = new Home();
|
var newPage = new Home();
|
||||||
_mainWin?.SwitchPageWithMaskAnimation(newPage, true);
|
_mainWin?.SwitchPageWithMaskAnimation(newPage, true);
|
||||||
return; // 提前退出
|
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
|
{
|
||||||
int rightWaving = DetectRightHandRaise(humans);
|
int rightWaving = DetectRightHandRaise(humans);
|
||||||
if (rightWaving >= 3)
|
if (rightWaving >= 3)
|
||||||
{
|
{
|
||||||
@ -194,7 +189,6 @@ namespace Wpf_AiSportsMicrospace.Views.JumpRope
|
|||||||
{
|
{
|
||||||
case (int)WavingAction.FirstHand:
|
case (int)WavingAction.FirstHand:
|
||||||
StartCountdown(3);
|
StartCountdown(3);
|
||||||
_isCountdownStarted = true; // 倒计时开始,停止左手检测
|
|
||||||
break;
|
break;
|
||||||
case (int)WavingAction.Raising:
|
case (int)WavingAction.Raising:
|
||||||
UpdateCountdown();
|
UpdateCountdown();
|
||||||
@ -205,11 +199,28 @@ namespace Wpf_AiSportsMicrospace.Views.JumpRope
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GameState.Running: // 游戏进行中
|
case GameState.Running: // 游戏进行中
|
||||||
UpdateCircleCounts(humans);
|
UpdateCircleCounts(humans);
|
||||||
|
|
||||||
|
// 可选:判断游戏结束条件,将状态切换到 Finished
|
||||||
|
// if (CheckGameFinished()) _currentGameState = GameState.Finished;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
//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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -218,14 +229,13 @@ namespace Wpf_AiSportsMicrospace.Views.JumpRope
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private int _currentCountdown = 3;
|
private int _currentCountdown = 3;
|
||||||
private DateTime _lastUpdateTime = DateTime.Now;
|
private DateTime _lastUpdateTime = DateTime.Now;
|
||||||
private void StartCountdown(int start = 4)
|
private void StartCountdown(int start = 4)
|
||||||
{
|
{
|
||||||
_currentCountdown = start;
|
_currentCountdown = start;
|
||||||
//countdownText.Text = _currentCountdown.ToString();
|
countdownText.Text = _currentCountdown.ToString();
|
||||||
//countdownGrid.Visibility = Visibility.Visible;
|
countdownGrid.Visibility = Visibility.Visible;
|
||||||
_lastUpdateTime = DateTime.Now;
|
_lastUpdateTime = DateTime.Now;
|
||||||
_mainWin.ShowCountDownAnimation();
|
_mainWin.ShowCountDownAnimation();
|
||||||
Utils.PlayBackgroundMusic("countdown_3.mp3", false);
|
Utils.PlayBackgroundMusic("countdown_3.mp3", false);
|
||||||
@ -254,7 +264,7 @@ namespace Wpf_AiSportsMicrospace.Views.JumpRope
|
|||||||
countdownText.Text = "GO!";
|
countdownText.Text = "GO!";
|
||||||
countdownGrid.Visibility = Visibility.Hidden;
|
countdownGrid.Visibility = Visibility.Hidden;
|
||||||
// 启动60秒倒计时(独立任务)
|
// 启动60秒倒计时(独立任务)
|
||||||
StartGameCountdown(108);
|
StartGameCountdown(105);
|
||||||
ShowMusicAnimation();
|
ShowMusicAnimation();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -291,7 +301,6 @@ namespace Wpf_AiSportsMicrospace.Views.JumpRope
|
|||||||
|
|
||||||
// 更新游戏状态
|
// 更新游戏状态
|
||||||
_currentGameState = GameState.NotStarted;
|
_currentGameState = GameState.NotStarted;
|
||||||
_isCountdownStarted = false;
|
|
||||||
|
|
||||||
// 恢复视频流
|
// 恢复视频流
|
||||||
Application.Current.Dispatcher.Invoke(() =>
|
Application.Current.Dispatcher.Invoke(() =>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user