卡点计数
This commit is contained in:
parent
4d9f5d262a
commit
b07c131ff6
@ -69,6 +69,7 @@ namespace Dto
|
|||||||
public int Rank { get; set; }
|
public int Rank { get; set; }
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
public int Number { get; set; }
|
public int Number { get; set; }
|
||||||
|
public double Score { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Wpf_AiSportsMicrospace.MyUserControl;
|
using Wpf_AiSportsMicrospace.MyUserControl;
|
||||||
using Yztob.AiSports.Postures.Sports;
|
using Yztob.AiSports.Postures.Sports;
|
||||||
@ -14,7 +15,7 @@ namespace Dto
|
|||||||
public List<(double XNorm, double YNorm)> CirclePositions { get; private set; }
|
public List<(double XNorm, double YNorm)> CirclePositions { get; private set; }
|
||||||
public List<SportUserItem> UserList { get; private set; }
|
public List<SportUserItem> UserList { get; private set; }
|
||||||
public List<string> UserNumberList { get; private set; }
|
public List<string> UserNumberList { get; private set; }
|
||||||
public List<string> UserScoreList { get; private set; }
|
public List<double> UserScoreList { get; private set; }
|
||||||
public List<SportBase> Sports { get; private set; }
|
public List<SportBase> Sports { get; private set; }
|
||||||
public List<string> UseNameList { get; private set; } = new() { "一号位", "二号位" };
|
public List<string> UseNameList { get; private set; } = new() { "一号位", "二号位" };
|
||||||
public List<int> UserBeatSyncList = new List<int>();
|
public List<int> UserBeatSyncList = new List<int>();
|
||||||
@ -53,13 +54,12 @@ namespace Dto
|
|||||||
CirclePositions = new List<(double XNorm, double YNorm)>
|
CirclePositions = new List<(double XNorm, double YNorm)>
|
||||||
{
|
{
|
||||||
(0.21, 0.88),
|
(0.21, 0.88),
|
||||||
(0.78, 0.88),
|
(0.50, 0.88),
|
||||||
};
|
};
|
||||||
|
|
||||||
UserList = new List<SportUserItem>();
|
UserList = new List<SportUserItem>();
|
||||||
UserNumberList = new List<string>();
|
UserNumberList = new List<string>();
|
||||||
Sports = new List<SportBase>();
|
Sports = new List<SportBase>();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更新排行榜方法
|
// 更新排行榜方法
|
||||||
@ -83,5 +83,33 @@ namespace Dto
|
|||||||
|
|
||||||
return rankList;
|
return rankList;
|
||||||
}
|
}
|
||||||
|
public List<RankItem> UpdateScoreRankList()
|
||||||
|
{
|
||||||
|
int totalBeats = MusicBeats.Count; // 总节拍数
|
||||||
|
const double maxScore = 100.0; // 满分 100
|
||||||
|
|
||||||
|
var rankList = UserBeatSyncList
|
||||||
|
.Select((beatCount, index) => new
|
||||||
|
{
|
||||||
|
Index = index,
|
||||||
|
Name = UseNameList[index],
|
||||||
|
BeatCount = beatCount,
|
||||||
|
// 按照 100 分制计算得分
|
||||||
|
Score = Math.Round((beatCount / (double)totalBeats) * maxScore, 1)
|
||||||
|
})
|
||||||
|
.OrderByDescending(x => x.Score)
|
||||||
|
.Select((x, rank) => new RankItem
|
||||||
|
{
|
||||||
|
Rank = rank + 1,
|
||||||
|
Name = x.Name,
|
||||||
|
Number = x.BeatCount, // 卡点个数
|
||||||
|
Score = x.Score // 总分(百分制)
|
||||||
|
})
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
// 同步更新 UserScoreList
|
||||||
|
UserScoreList = rankList.Select(x => x.Score).ToList();
|
||||||
|
return rankList;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -271,23 +271,31 @@ namespace Wpf_AiSportsMicrospace.Views.JumpRope
|
|||||||
await Task.Delay(1000);
|
await Task.Delay(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 停止音乐
|
||||||
|
Utils.StopBackgroundMusic();
|
||||||
|
// 停止实时检测和视频流
|
||||||
|
|
||||||
countdownGrid.Visibility = Visibility.Hidden;
|
countdownGrid.Visibility = Visibility.Hidden;
|
||||||
|
|
||||||
_musicJumpRopeContext.UserList.ForEach(x =>
|
|
||||||
{
|
|
||||||
x.ImageState = "1";
|
|
||||||
});
|
|
||||||
|
|
||||||
_mainWin.HumanFrameUpdated -= OnHumanFrameUpdated;
|
_mainWin.HumanFrameUpdated -= OnHumanFrameUpdated;
|
||||||
_mainWin.WebcamClient.StopExtract();
|
_mainWin.WebcamClient.StopExtract();
|
||||||
|
|
||||||
RankingItemList = _musicJumpRopeContext.UpdateRankList();
|
// 计算排名
|
||||||
//ShowRankingBoard(RankingItemList);
|
var rankList = _musicJumpRopeContext.UpdateRankList();
|
||||||
Utils.StopBackgroundMusic();
|
var scoreList = _musicJumpRopeContext.UpdateScoreRankList();
|
||||||
|
|
||||||
|
|
||||||
|
// 更新游戏状态
|
||||||
_currentGameState = GameState.Finished;
|
_currentGameState = GameState.Finished;
|
||||||
|
|
||||||
|
// 恢复视频流
|
||||||
|
Application.Current.Dispatcher.Invoke(() =>
|
||||||
|
{
|
||||||
_mainWin.HumanFrameUpdated += OnHumanFrameUpdated;
|
_mainWin.HumanFrameUpdated += OnHumanFrameUpdated;
|
||||||
_mainWin.WebcamClient.StartExtract();
|
_mainWin.WebcamClient.StartExtract();
|
||||||
|
|
||||||
|
// 更新 UI(排行榜或分数板)
|
||||||
|
// ShowRankingBoard(rankList);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private DateTime? _raiseStartTime;
|
private DateTime? _raiseStartTime;
|
||||||
@ -435,6 +443,8 @@ namespace Wpf_AiSportsMicrospace.Views.JumpRope
|
|||||||
_musicJumpRopeContext.Sports.Clear();
|
_musicJumpRopeContext.Sports.Clear();
|
||||||
_musicJumpRopeContext.UserList.Clear();
|
_musicJumpRopeContext.UserList.Clear();
|
||||||
_musicJumpRopeContext.UserNumberList.Clear();
|
_musicJumpRopeContext.UserNumberList.Clear();
|
||||||
|
_musicJumpRopeContext.UserBeatSyncList.Clear();
|
||||||
|
_musicBeatTextBlock.Clear();
|
||||||
|
|
||||||
double imgWidth = userBox.ActualWidth;
|
double imgWidth = userBox.ActualWidth;
|
||||||
double imgHeight = userBox.ActualHeight;
|
double imgHeight = userBox.ActualHeight;
|
||||||
@ -472,11 +482,11 @@ namespace Wpf_AiSportsMicrospace.Views.JumpRope
|
|||||||
bool isOnBeat = _musicBeats.Any(bt => Math.Abs(bt - _currentTime) <= _beatTolerance);
|
bool isOnBeat = _musicBeats.Any(bt => Math.Abs(bt - _currentTime) <= _beatTolerance);
|
||||||
if (isOnBeat)
|
if (isOnBeat)
|
||||||
{
|
{
|
||||||
_musicJumpRopeContext.UserBeatSyncList[i]++;
|
_musicJumpRopeContext.UserBeatSyncList[indexCopy]++;
|
||||||
|
|
||||||
if (_musicJumpRopeContext.UserBeatSyncList[i] < count)
|
if (_musicJumpRopeContext.UserBeatSyncList[indexCopy] < count)
|
||||||
{
|
{
|
||||||
_musicBeatTextBlock[i].Text = $"卡点 x{_musicJumpRopeContext.UserBeatSyncList[i]}";
|
_musicBeatTextBlock[indexCopy].Text = $"卡点 x{_musicJumpRopeContext.UserBeatSyncList[indexCopy]}";
|
||||||
}
|
}
|
||||||
|
|
||||||
//Application.Current.Dispatcher.BeginInvoke(() =>
|
//Application.Current.Dispatcher.BeginInvoke(() =>
|
||||||
@ -536,10 +546,8 @@ namespace Wpf_AiSportsMicrospace.Views.JumpRope
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 推送计数
|
// 推送计数
|
||||||
if (hasHuman)
|
//if (hasHuman)
|
||||||
_musicJumpRopeContext.Sports[i].Pushing(humanInCircle);
|
_musicJumpRopeContext.Sports[i].Pushing(humanInCircle);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private string GetJumpState(int circleIndex, bool humanInCircle)
|
private string GetJumpState(int circleIndex, bool humanInCircle)
|
||||||
@ -587,7 +595,7 @@ namespace Wpf_AiSportsMicrospace.Views.JumpRope
|
|||||||
userItem.VerticalAlignment = VerticalAlignment.Top;
|
userItem.VerticalAlignment = VerticalAlignment.Top;
|
||||||
userItem.HorizontalAlignment = HorizontalAlignment.Left;
|
userItem.HorizontalAlignment = HorizontalAlignment.Left;
|
||||||
userItem.ImageState = "1";
|
userItem.ImageState = "1";
|
||||||
userItem.Margin = new Thickness(centerX - 120, centerY - 700, 0, 0);
|
userItem.Margin = new Thickness(centerX + 120, centerY - 700, 0, 0);
|
||||||
|
|
||||||
// ----------- 创建上方 TextBlock ------------
|
// ----------- 创建上方 TextBlock ------------
|
||||||
var textBlock = new TextBlock
|
var textBlock = new TextBlock
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user