卡点计数

This commit is contained in:
tanglong 2025-10-16 14:20:29 +08:00
parent 4d9f5d262a
commit b07c131ff6
3 changed files with 60 additions and 23 deletions

View File

@ -69,6 +69,7 @@ namespace Dto
public int Rank { get; set; }
public string Name { get; set; }
public int Number { get; set; }
public double Score { get; set; }
}
}

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using Wpf_AiSportsMicrospace.MyUserControl;
using Yztob.AiSports.Postures.Sports;
@ -14,7 +15,7 @@ namespace Dto
public List<(double XNorm, double YNorm)> CirclePositions { get; private set; }
public List<SportUserItem> UserList { 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<string> UseNameList { get; private set; } = new() { "一号位", "二号位" };
public List<int> UserBeatSyncList = new List<int>();
@ -53,13 +54,12 @@ namespace Dto
CirclePositions = new List<(double XNorm, double YNorm)>
{
(0.21, 0.88),
(0.78, 0.88),
(0.50, 0.88),
};
UserList = new List<SportUserItem>();
UserNumberList = new List<string>();
Sports = new List<SportBase>();
}
// 更新排行榜方法
@ -83,5 +83,33 @@ namespace Dto
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;
}
}
}

View File

@ -271,23 +271,31 @@ namespace Wpf_AiSportsMicrospace.Views.JumpRope
await Task.Delay(1000);
}
// 停止音乐
Utils.StopBackgroundMusic();
// 停止实时检测和视频流
countdownGrid.Visibility = Visibility.Hidden;
_musicJumpRopeContext.UserList.ForEach(x =>
{
x.ImageState = "1";
});
_mainWin.HumanFrameUpdated -= OnHumanFrameUpdated;
_mainWin.WebcamClient.StopExtract();
RankingItemList = _musicJumpRopeContext.UpdateRankList();
//ShowRankingBoard(RankingItemList);
Utils.StopBackgroundMusic();
// 计算排名
var rankList = _musicJumpRopeContext.UpdateRankList();
var scoreList = _musicJumpRopeContext.UpdateScoreRankList();
// 更新游戏状态
_currentGameState = GameState.Finished;
_mainWin.HumanFrameUpdated += OnHumanFrameUpdated;
_mainWin.WebcamClient.StartExtract();
// 恢复视频流
Application.Current.Dispatcher.Invoke(() =>
{
_mainWin.HumanFrameUpdated += OnHumanFrameUpdated;
_mainWin.WebcamClient.StartExtract();
// 更新 UI排行榜或分数板
// ShowRankingBoard(rankList);
});
}
private DateTime? _raiseStartTime;
@ -435,6 +443,8 @@ namespace Wpf_AiSportsMicrospace.Views.JumpRope
_musicJumpRopeContext.Sports.Clear();
_musicJumpRopeContext.UserList.Clear();
_musicJumpRopeContext.UserNumberList.Clear();
_musicJumpRopeContext.UserBeatSyncList.Clear();
_musicBeatTextBlock.Clear();
double imgWidth = userBox.ActualWidth;
double imgHeight = userBox.ActualHeight;
@ -472,11 +482,11 @@ namespace Wpf_AiSportsMicrospace.Views.JumpRope
bool isOnBeat = _musicBeats.Any(bt => Math.Abs(bt - _currentTime) <= _beatTolerance);
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(() =>
@ -536,10 +546,8 @@ namespace Wpf_AiSportsMicrospace.Views.JumpRope
}
// 推送计数
if (hasHuman)
_musicJumpRopeContext.Sports[i].Pushing(humanInCircle);
//if (hasHuman)
_musicJumpRopeContext.Sports[i].Pushing(humanInCircle);
}
}
private string GetJumpState(int circleIndex, bool humanInCircle)
@ -587,7 +595,7 @@ namespace Wpf_AiSportsMicrospace.Views.JumpRope
userItem.VerticalAlignment = VerticalAlignment.Top;
userItem.HorizontalAlignment = HorizontalAlignment.Left;
userItem.ImageState = "1";
userItem.Margin = new Thickness(centerX - 120, centerY - 700, 0, 0);
userItem.Margin = new Thickness(centerX + 120, centerY - 700, 0, 0);
// ----------- 创建上方 TextBlock ------------
var textBlock = new TextBlock