diff --git a/Wpf_AiSportsMicrospace/Dto/GroupJumpRopeContext.cs b/Wpf_AiSportsMicrospace/Dto/GroupJumpRopeContext.cs index 1f08581..3a6e077 100644 --- a/Wpf_AiSportsMicrospace/Dto/GroupJumpRopeContext.cs +++ b/Wpf_AiSportsMicrospace/Dto/GroupJumpRopeContext.cs @@ -9,6 +9,8 @@ namespace Dto { public class GroupJumpRopeContext { + // 静态字段,保存排名列表 + public static List RankList { get; set; } = new List(); public List<(double XNorm, double YNorm)> CirclePositions { get; private set; } public List UserList { get; private set; } public List UserNumberList { get; private set; } @@ -34,5 +36,33 @@ namespace Dto Sports = new List(); } + + // 更新排行榜方法 + public void UpdateRankList() + { + RankList = UserNumberList + .Select((numStr, index) => new + { + Index = index, + Name = UseNameList[index], + Number = int.TryParse(numStr, out var n) ? n : 0 + }) + .OrderByDescending(x => x.Number) + .Select((x, rank) => new RankItem + { + Rank = rank + 1, + Name = x.Name, + Number = x.Number + }) + .ToList(); + } + } + + // 排名项 + public class RankItem + { + public int Rank { get; set; } + public string Name { get; set; } + public int Number { get; set; } } } diff --git a/Wpf_AiSportsMicrospace/Views/JumpRope/GroupJumpRope.xaml.cs b/Wpf_AiSportsMicrospace/Views/JumpRope/GroupJumpRope.xaml.cs index 61790e2..707300b 100644 --- a/Wpf_AiSportsMicrospace/Views/JumpRope/GroupJumpRope.xaml.cs +++ b/Wpf_AiSportsMicrospace/Views/JumpRope/GroupJumpRope.xaml.cs @@ -263,6 +263,8 @@ namespace Wpf_AiSportsMicrospace.Views x.ImageState = "1"; }); + _groupJumpRopeContext.UpdateRankList(); + IsGameStarted = false; Utils.StopBackgroundMusic(); }