音乐
This commit is contained in:
parent
0dbf676ed0
commit
eb5df730d1
BIN
Wpf_AiSportsMicrospace/Resources/Music/whackamole.mp3
Normal file
BIN
Wpf_AiSportsMicrospace/Resources/Music/whackamole.mp3
Normal file
Binary file not shown.
@ -509,73 +509,100 @@ namespace Wpf_AiSportsMicrospace.Views
|
||||
|
||||
public void ShowRankingBoard(List<RankItem> list)
|
||||
{
|
||||
var scoreGrid = FindName("ScoreGrid") as Grid;
|
||||
name1.Text = list[0].Name;
|
||||
name2.Text = list[1].Name;
|
||||
name3.Text = list[2].Name;
|
||||
number1.Text = list[0].Number.ToString();
|
||||
number2.Text = list[1].Number.ToString();
|
||||
number3.Text = list[2].Number.ToString();
|
||||
foreach (var item in list)
|
||||
if (list == null || list.Count == 0) return;
|
||||
|
||||
// 排序(建议加上)
|
||||
list = list.OrderByDescending(x => x.Number).ToList();
|
||||
|
||||
// 清空旧UI
|
||||
ScoreGrid.Children.Clear();
|
||||
|
||||
// ===== 前三名(完全动态,永不越界)=====
|
||||
var nameControls = new[] { name1, name2, name3 };
|
||||
var numberControls = new[] { number1, number2, number3 };
|
||||
|
||||
for (int i = 0; i < nameControls.Length; i++)
|
||||
{
|
||||
var item = list.ElementAtOrDefault(i);
|
||||
|
||||
if (item != null)
|
||||
{
|
||||
nameControls[i].Text = item.Name;
|
||||
numberControls[i].Text = item.Number.ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
// 不够3个时填空
|
||||
nameControls[i].Text = "-";
|
||||
numberControls[i].Text = "-";
|
||||
}
|
||||
}
|
||||
|
||||
// ===== 榜单列表 =====
|
||||
for (int i = 0; i < list.Count; i++)
|
||||
{
|
||||
var item = list[i];
|
||||
|
||||
var grid = new Grid
|
||||
{
|
||||
Width = 1344,
|
||||
Height = 71,
|
||||
HorizontalAlignment = HorizontalAlignment.Center,
|
||||
VerticalAlignment = VerticalAlignment.Top,
|
||||
Margin = new Thickness(0, 69 * item.Rank, 0, 0)
|
||||
Margin = new Thickness(0, 69 * i, 0, 0)
|
||||
};
|
||||
|
||||
var border = new Border
|
||||
{
|
||||
Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#fff"))
|
||||
Background = new SolidColorBrush(
|
||||
(Color)ColorConverter.ConvertFromString("#FFFFFF"))
|
||||
};
|
||||
grid.Children.Add(border);
|
||||
var rankText = new TextBlock
|
||||
|
||||
// 排名
|
||||
grid.Children.Add(new TextBlock
|
||||
{
|
||||
Text = item.Rank.ToString(),
|
||||
Text = (i + 1).ToString(),
|
||||
FontSize = 24,
|
||||
FontWeight = FontWeights.Bold,
|
||||
Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#999999")),
|
||||
Foreground = new SolidColorBrush(
|
||||
(Color)ColorConverter.ConvertFromString("#999999")),
|
||||
HorizontalAlignment = HorizontalAlignment.Left,
|
||||
VerticalAlignment = VerticalAlignment.Center,
|
||||
TextAlignment = TextAlignment.Center,
|
||||
Width = 200
|
||||
};
|
||||
grid.Children.Add(rankText);
|
||||
Width = 200,
|
||||
TextAlignment = TextAlignment.Center
|
||||
});
|
||||
|
||||
var positionText = new TextBlock
|
||||
// 名字
|
||||
grid.Children.Add(new TextBlock
|
||||
{
|
||||
Text = item.Name,
|
||||
FontSize = 24,
|
||||
FontWeight = FontWeights.Bold,
|
||||
Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#999999")),
|
||||
Foreground = new SolidColorBrush(
|
||||
(Color)ColorConverter.ConvertFromString("#999999")),
|
||||
HorizontalAlignment = HorizontalAlignment.Center,
|
||||
VerticalAlignment = VerticalAlignment.Center
|
||||
};
|
||||
grid.Children.Add(positionText);
|
||||
});
|
||||
|
||||
var scoreText = new TextBlock
|
||||
// 分数
|
||||
grid.Children.Add(new TextBlock
|
||||
{
|
||||
Text = item.Number.ToString(),
|
||||
FontSize = 24,
|
||||
FontWeight = FontWeights.Bold,
|
||||
Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#999999")),
|
||||
Foreground = new SolidColorBrush(
|
||||
(Color)ColorConverter.ConvertFromString("#999999")),
|
||||
HorizontalAlignment = HorizontalAlignment.Right,
|
||||
VerticalAlignment = VerticalAlignment.Center,
|
||||
TextAlignment = TextAlignment.Center,
|
||||
Width = 200
|
||||
};
|
||||
grid.Children.Add(scoreText);
|
||||
Width = 200,
|
||||
TextAlignment = TextAlignment.Center
|
||||
});
|
||||
|
||||
ScoreGrid.Children.Add(grid);
|
||||
}
|
||||
showElement("RankingGrid");
|
||||
//var rankingGrid = FindName("RankingGrid") as Grid;
|
||||
//if (rankingGrid == null) return;
|
||||
|
||||
//rankingGrid.Visibility = Visibility.Visible;
|
||||
//var fadeIn = new DoubleAnimation(0, 1, TimeSpan.FromMilliseconds(600));
|
||||
//rankingGrid.BeginAnimation(UIElement.OpacityProperty, fadeIn);
|
||||
showElement("RankingGrid");
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@ -354,8 +354,6 @@ namespace Wpf_AiSportsMicrospace.Views.JumpRope
|
||||
// 停止实时检测和视频流
|
||||
|
||||
countdownGrid.Visibility = Visibility.Hidden;
|
||||
_mainWin.HumanFrameUpdated -= OnHumanFrameUpdated;
|
||||
_mainWin.WebcamClient.StopExtract();
|
||||
|
||||
// 计算排名
|
||||
var rankList = _musicJumpRopeContext.UpdateRankList();
|
||||
@ -366,15 +364,17 @@ namespace Wpf_AiSportsMicrospace.Views.JumpRope
|
||||
_currentGameState = GameState.NotStarted;
|
||||
_isCountdownStarted = false;
|
||||
|
||||
// 恢复视频流
|
||||
Application.Current.Dispatcher.Invoke(() =>
|
||||
{
|
||||
_mainWin.HumanFrameUpdated += OnHumanFrameUpdated;
|
||||
_mainWin.WebcamClient.StartExtract();
|
||||
showRank();
|
||||
// 更新 UI(排行榜或分数板)
|
||||
// ShowRankingBoard(rankList);
|
||||
});
|
||||
|
||||
// 恢复视频流
|
||||
//Application.Current.Dispatcher.Invoke(() =>
|
||||
//{
|
||||
// _mainWin.HumanFrameUpdated += OnHumanFrameUpdated;
|
||||
// _mainWin.WebcamClient.StartExtract();
|
||||
// showRank();
|
||||
// // 更新 UI(排行榜或分数板)
|
||||
// // ShowRankingBoard(rankList);
|
||||
//});
|
||||
}
|
||||
|
||||
public void showRank()
|
||||
|
||||
@ -103,67 +103,91 @@ namespace Views.JumpRope
|
||||
}
|
||||
public void ShowRankingBoard(List<RankItem> list)
|
||||
{
|
||||
|
||||
var scoreGrid = FindName("ScoreGrid") as Grid;
|
||||
if (list.Count <= 0) return;
|
||||
name1.Text = list[0].Name;
|
||||
name2.Text = list[1].Name;
|
||||
name3.Text = list[2].Name;
|
||||
number1.Text = list[0].Number.ToString();
|
||||
number2.Text = list[1].Number.ToString();
|
||||
number3.Text = list[2].Number.ToString();
|
||||
foreach (var item in list)
|
||||
if (scoreGrid == null || list == null || list.Count == 0) return;
|
||||
|
||||
// 排序(建议加)
|
||||
list = list.OrderByDescending(x => x.Number).ToList();
|
||||
|
||||
// 清空旧数据(必须)
|
||||
scoreGrid.Children.Clear();
|
||||
|
||||
// ===== 前三名(完全动态,不越界)=====
|
||||
var nameControls = new[] { name1, name2, name3 };
|
||||
var numberControls = new[] { number1, number2, number3 };
|
||||
|
||||
for (int i = 0; i < nameControls.Length; i++)
|
||||
{
|
||||
var item = list.ElementAtOrDefault(i);
|
||||
|
||||
nameControls[i].Text = item?.Name ?? "-";
|
||||
numberControls[i].Text = item?.Number.ToString() ?? "-";
|
||||
}
|
||||
|
||||
// ===== 榜单列表 =====
|
||||
for (int i = 0; i < list.Count; i++)
|
||||
{
|
||||
var item = list[i];
|
||||
|
||||
var grid = new Grid
|
||||
{
|
||||
Width = 1344,
|
||||
Height = 71,
|
||||
HorizontalAlignment = HorizontalAlignment.Center,
|
||||
VerticalAlignment = VerticalAlignment.Top,
|
||||
Margin = new Thickness(0, 69 * item.Rank, 0, 0)
|
||||
|
||||
// ❗不要用 item.Rank,改用 i
|
||||
Margin = new Thickness(0, 69 * i, 0, 0)
|
||||
};
|
||||
|
||||
var border = new Border
|
||||
{
|
||||
Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#fff"))
|
||||
Background = new SolidColorBrush(
|
||||
(Color)ColorConverter.ConvertFromString("#FFFFFF"))
|
||||
};
|
||||
grid.Children.Add(border);
|
||||
var rankText = new TextBlock
|
||||
|
||||
// 排名
|
||||
grid.Children.Add(new TextBlock
|
||||
{
|
||||
Text = item.Rank.ToString(),
|
||||
Text = (i + 1).ToString(), // 用 i+1
|
||||
FontSize = 24,
|
||||
FontWeight = FontWeights.Bold,
|
||||
Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#999999")),
|
||||
Foreground = new SolidColorBrush(
|
||||
(Color)ColorConverter.ConvertFromString("#999999")),
|
||||
HorizontalAlignment = HorizontalAlignment.Left,
|
||||
VerticalAlignment = VerticalAlignment.Center,
|
||||
TextAlignment = TextAlignment.Center,
|
||||
Width = 200
|
||||
};
|
||||
grid.Children.Add(rankText);
|
||||
});
|
||||
|
||||
var positionText = new TextBlock
|
||||
// 名字
|
||||
grid.Children.Add(new TextBlock
|
||||
{
|
||||
Text = item.Name,
|
||||
FontSize = 24,
|
||||
FontWeight = FontWeights.Bold,
|
||||
Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#999999")),
|
||||
Foreground = new SolidColorBrush(
|
||||
(Color)ColorConverter.ConvertFromString("#999999")),
|
||||
HorizontalAlignment = HorizontalAlignment.Center,
|
||||
VerticalAlignment = VerticalAlignment.Center
|
||||
};
|
||||
grid.Children.Add(positionText);
|
||||
});
|
||||
|
||||
var scoreText = new TextBlock
|
||||
// 分数
|
||||
grid.Children.Add(new TextBlock
|
||||
{
|
||||
Text = item.Number.ToString(),
|
||||
FontSize = 24,
|
||||
FontWeight = FontWeights.Bold,
|
||||
Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#999999")),
|
||||
Foreground = new SolidColorBrush(
|
||||
(Color)ColorConverter.ConvertFromString("#999999")),
|
||||
HorizontalAlignment = HorizontalAlignment.Right,
|
||||
VerticalAlignment = VerticalAlignment.Center,
|
||||
TextAlignment = TextAlignment.Center,
|
||||
Width = 200
|
||||
};
|
||||
grid.Children.Add(scoreText);
|
||||
ScoreGrid.Children.Add(grid);
|
||||
});
|
||||
|
||||
scoreGrid.Children.Add(grid);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -308,9 +308,6 @@ namespace Views.JumpingJack
|
||||
x.ImageState = "1";
|
||||
});
|
||||
|
||||
_mainWin.HumanFrameUpdated -= OnHumanFrameUpdated;
|
||||
_mainWin.WebcamClient.StopExtract();
|
||||
|
||||
RankingItemList = _groupJumpRopeContext.UpdateRankList();
|
||||
ShowRankingBoard(RankingItemList);
|
||||
Utils.StopBackgroundMusic();
|
||||
@ -318,8 +315,6 @@ namespace Views.JumpingJack
|
||||
_currentGameState = GameState.NotStarted;
|
||||
|
||||
_isCountdownStarted = false;
|
||||
_mainWin.HumanFrameUpdated += OnHumanFrameUpdated;
|
||||
_mainWin.WebcamClient.StartExtract();
|
||||
}
|
||||
|
||||
private DateTime? _raiseStartTime;
|
||||
|
||||
@ -113,7 +113,6 @@ namespace Views.SquatFu
|
||||
_mediaPlayer.MediaEnded += MediaPlayer_MediaEnded;
|
||||
//_mainWin.WebcamClient.StartExtract();
|
||||
_mediaPlayer.Play();
|
||||
_mainWin.HumanFrameUpdated += OnHumanFrameUpdated;
|
||||
|
||||
}
|
||||
private void ShowCenterTip(string imagePath, TimeSpan duration)
|
||||
@ -220,19 +219,6 @@ namespace Views.SquatFu
|
||||
case GameState.Running: // 游戏进行中
|
||||
UpdateCircleCounts(humans);
|
||||
break;
|
||||
//case GameState.Finished: // 游戏结束
|
||||
// int leftWave = sportOperate.VerifyLeftWavingAction(humans);
|
||||
// if (leftWave == 5)
|
||||
// {
|
||||
// _mainWin.HumanFrameUpdated -= OnHumanFrameUpdated;
|
||||
// _mainWin.WebcamClient.StopExtract();
|
||||
|
||||
// // 举左手逻辑,例如结束动画或退出
|
||||
// var newPage = new Home();
|
||||
// _mainWin?.SwitchPageWithMaskAnimation(newPage, true);
|
||||
// return; // 提前退出
|
||||
// }
|
||||
// break;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -245,9 +231,6 @@ namespace Views.SquatFu
|
||||
private DateTime _lastUpdateTime = DateTime.Now;
|
||||
private async void StartCountdown(int start = 3)
|
||||
{
|
||||
|
||||
//_currentGameState = GameState.Running;
|
||||
|
||||
_mainWin.ShowCountDownAnimation();
|
||||
|
||||
Utils.PlayBackgroundMusic("countdown_3.mp3", false);
|
||||
@ -287,23 +270,6 @@ namespace Views.SquatFu
|
||||
FinishCountdown();
|
||||
}
|
||||
|
||||
private void UpdateCountdown()
|
||||
{
|
||||
if ((DateTime.Now - _lastUpdateTime).TotalMilliseconds >= 600)
|
||||
{
|
||||
_lastUpdateTime = DateTime.Now;
|
||||
_currentCountdown -= 600;
|
||||
|
||||
if (_currentCountdown > 0)
|
||||
{
|
||||
countdownText.Text = _currentCountdown.ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
FinishCountdown();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private System.Timers.Timer _gameTimer;
|
||||
private Random _random = new Random();
|
||||
@ -381,18 +347,13 @@ namespace Views.SquatFu
|
||||
//x.TriggerValue = Tiggle;
|
||||
});
|
||||
|
||||
_mainWin.HumanFrameUpdated -= OnHumanFrameUpdated;
|
||||
_mainWin.WebcamClient.StopExtract();
|
||||
|
||||
RankingItemList = _WhackAMoleContext.UpdateWhackAMoleRankList();
|
||||
ShowRankingBoard(RankingItemList);
|
||||
Utils.StopBackgroundMusic();
|
||||
|
||||
_currentGameState = GameState.Finished;
|
||||
_currentGameState = GameState.NotStarted;
|
||||
|
||||
_isCountdownStarted = false;
|
||||
_mainWin.HumanFrameUpdated += OnHumanFrameUpdated;
|
||||
_mainWin.WebcamClient.StartExtract();
|
||||
}
|
||||
|
||||
private DateTime? _raiseStartTime;
|
||||
@ -545,77 +506,102 @@ namespace Views.SquatFu
|
||||
//return userItem; //
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void ShowRankingBoard(List<RankItem> list)
|
||||
{
|
||||
var scoreGrid = FindName("ScoreGrid") as Grid;
|
||||
name1.Text = list[0].Name;
|
||||
name2.Text = list[1].Name;
|
||||
name3.Text = list[2].Name;
|
||||
number1.Text = list[0].Number.ToString();
|
||||
number2.Text = list[1].Number.ToString();
|
||||
number3.Text = list[2].Number.ToString();
|
||||
foreach (var item in list)
|
||||
if (list == null || list.Count == 0) return;
|
||||
|
||||
// 排序(建议加上)
|
||||
list = list.OrderByDescending(x => x.Number).ToList();
|
||||
|
||||
// 清空旧UI
|
||||
ScoreGrid.Children.Clear();
|
||||
|
||||
// ===== 前三名(完全动态,永不越界)=====
|
||||
var nameControls = new[] { name1, name2, name3 };
|
||||
var numberControls = new[] { number1, number2, number3 };
|
||||
|
||||
for (int i = 0; i < nameControls.Length; i++)
|
||||
{
|
||||
var item = list.ElementAtOrDefault(i);
|
||||
|
||||
if (item != null)
|
||||
{
|
||||
nameControls[i].Text = item.Name;
|
||||
numberControls[i].Text = item.Number.ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
// 不够3个时填空
|
||||
nameControls[i].Text = "-";
|
||||
numberControls[i].Text = "-";
|
||||
}
|
||||
}
|
||||
|
||||
// ===== 榜单列表 =====
|
||||
for (int i = 0; i < list.Count; i++)
|
||||
{
|
||||
var item = list[i];
|
||||
|
||||
var grid = new Grid
|
||||
{
|
||||
Width = 1344,
|
||||
Height = 71,
|
||||
HorizontalAlignment = HorizontalAlignment.Center,
|
||||
VerticalAlignment = VerticalAlignment.Top,
|
||||
Margin = new Thickness(0, 69 * item.Rank, 0, 0)
|
||||
Margin = new Thickness(0, 69 * i, 0, 0)
|
||||
};
|
||||
|
||||
var border = new Border
|
||||
{
|
||||
Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#fff"))
|
||||
Background = new SolidColorBrush(
|
||||
(Color)ColorConverter.ConvertFromString("#FFFFFF"))
|
||||
};
|
||||
grid.Children.Add(border);
|
||||
var rankText = new TextBlock
|
||||
|
||||
// 排名
|
||||
grid.Children.Add(new TextBlock
|
||||
{
|
||||
Text = item.Rank.ToString(),
|
||||
Text = (i + 1).ToString(),
|
||||
FontSize = 24,
|
||||
FontWeight = FontWeights.Bold,
|
||||
Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#999999")),
|
||||
Foreground = new SolidColorBrush(
|
||||
(Color)ColorConverter.ConvertFromString("#999999")),
|
||||
HorizontalAlignment = HorizontalAlignment.Left,
|
||||
VerticalAlignment = VerticalAlignment.Center,
|
||||
TextAlignment = TextAlignment.Center,
|
||||
Width = 200
|
||||
};
|
||||
grid.Children.Add(rankText);
|
||||
Width = 200,
|
||||
TextAlignment = TextAlignment.Center
|
||||
});
|
||||
|
||||
var positionText = new TextBlock
|
||||
// 名字
|
||||
grid.Children.Add(new TextBlock
|
||||
{
|
||||
Text = item.Name,
|
||||
FontSize = 24,
|
||||
FontWeight = FontWeights.Bold,
|
||||
Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#999999")),
|
||||
Foreground = new SolidColorBrush(
|
||||
(Color)ColorConverter.ConvertFromString("#999999")),
|
||||
HorizontalAlignment = HorizontalAlignment.Center,
|
||||
VerticalAlignment = VerticalAlignment.Center
|
||||
};
|
||||
grid.Children.Add(positionText);
|
||||
});
|
||||
|
||||
var scoreText = new TextBlock
|
||||
// 分数
|
||||
grid.Children.Add(new TextBlock
|
||||
{
|
||||
Text = item.Number.ToString(),
|
||||
FontSize = 24,
|
||||
FontWeight = FontWeights.Bold,
|
||||
Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#999999")),
|
||||
Foreground = new SolidColorBrush(
|
||||
(Color)ColorConverter.ConvertFromString("#999999")),
|
||||
HorizontalAlignment = HorizontalAlignment.Right,
|
||||
VerticalAlignment = VerticalAlignment.Center,
|
||||
TextAlignment = TextAlignment.Center,
|
||||
Width = 200
|
||||
};
|
||||
grid.Children.Add(scoreText);
|
||||
Width = 200,
|
||||
TextAlignment = TextAlignment.Center
|
||||
});
|
||||
|
||||
ScoreGrid.Children.Add(grid);
|
||||
}
|
||||
showElement("RankingGrid");
|
||||
//var rankingGrid = FindName("RankingGrid") as Grid;
|
||||
//if (rankingGrid == null) return;
|
||||
|
||||
//rankingGrid.Visibility = Visibility.Visible;
|
||||
//var fadeIn = new DoubleAnimation(0, 1, TimeSpan.FromMilliseconds(600));
|
||||
//rankingGrid.BeginAnimation(UIElement.OpacityProperty, fadeIn);
|
||||
showElement("RankingGrid");
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@ -152,6 +152,7 @@
|
||||
<None Remove="Resources\Music\musicjumprope.mp3" />
|
||||
<None Remove="Resources\Music\musicjumprope1.mp3" />
|
||||
<None Remove="Resources\Music\raisehand.mp3" />
|
||||
<None Remove="Resources\Music\whackamole.mp3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@ -648,6 +649,9 @@
|
||||
<Resource Include="Resources\Music\raisehand.mp3">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Resource>
|
||||
<Resource Include="Resources\Music\whackamole.mp3">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Resource>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user