2025-10-21 15:31:09 +08:00

138 lines
5.7 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows.Shapes;
using Wpf_AiSportsMicrospace.MyUserControl;
using Yztob.AiSports.Postures.Sports;
namespace Dto
{
public class MusicJumpRopeContext
{
// 静态字段,保存排名列表
public static List<RankItem> RankList { get; set; } = new List<RankItem>();
public List<(double XNorm, double YNorm)> CirclePositions { get; private set; }
public List<MusicUserItem> UserList { get; private set; }
public List<string> UserNumberList { 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>();
public Dictionary<string, List<double>> MusicBeats { get; private set; } = new()
{
{
"1", new List<double>
{
0.545,1.09,1.635,2.18,2.725,3.27,3.815,4.36,4.905,5.45,
5.995,6.54,7.085,7.63,8.175,8.72,9.265,9.81,10.355,10.9,
11.445,11.99,12.535,13.08,13.625,14.17,14.715,15.26,15.805,16.35,
16.895,17.44,17.985,18.53,19.075,19.62,20.165,20.71,21.255,21.8,
22.345,22.89,23.435,23.98,24.525,25.07,25.615,26.16,26.705,27.25,
27.795,28.34,28.885,29.43,29.975,30.52,31.065,31.61,32.155,32.7,
33.245,33.79,34.335,34.88,35.425,35.97,36.515,37.06,37.605,38.15,
38.695,39.24,39.785,40.33,40.875,41.42,41.965,42.51,43.055,43.6,
44.145,44.69,45.235,45.78,46.325,46.87,47.415,47.96,48.505,49.05,
49.595,50.14,50.685,51.23,51.775,52.32,52.865,53.41,53.955,54.5,
55.045,55.59,56.135,56.68,57.225,57.77,58.315,58.86,59.405,59.95,
60.495,61.04,61.585,62.13,62.675,63.22,63.765,64.31,64.855,65.4,
65.945,66.49,67.035,67.58,68.125,68.67,69.215,69.76,70.305,70.85,
71.395,71.94,72.485,73.03,73.575,74.12,74.665,75.21,75.755,76.3,
76.845,77.39,77.935,78.48,79.025,79.57,80.115,80.66,81.205,81.75,
82.295,82.84,83.385,83.93,84.475,85.02,85.565,86.11,86.655,87.2,
87.745,88.29,88.835,89.38,89.925,90.47,91.015,91.56,92.105,92.65,
93.195,93.74,94.285,94.83,95.375,95.92,96.465,97.01,97.555,98.1,
98.645,99.19,99.735,100.28,100.825,101.37,101.915,102.46,103.005,103.55,
104.095,104.64,105.185,105.73,106.275,106.82,107.365,107.91
}
}
};
public Dictionary<int, List<double>> MusicBeatsDic;
public MusicJumpRopeContext()
{
CirclePositions = new List<(double XNorm, double YNorm)>
{
(0.50, 0.88),
(0.78, 0.88),
};
MusicBeatsDic = MusicBeats["1"].GroupBy(b => (int)Math.Ceiling(b) - 1).ToDictionary(g => g.Key, g => g.ToList());
UserList = new List<MusicUserItem>();
UserNumberList = new List<string>();
Sports = new List<SportBase>();
}
// 更新排行榜方法
public List<RankItem> UpdateRankList()
{
var 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();
RankList = 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;
}
}
public class UserBeatBar
{
public Canvas Canvas { get; set; } // 用于显示节拍条的 Canvas
public List<Ellipse> BeatPoints { get; set; } // 每个节拍点
public List<double> BeatTimes { get; set; }
public bool IsLeftToRight { get; set; } // 滑动方向
public double BarWidth { get; set; } // 横杠宽度
public double BarHeight { get; set; } // 横杠高度
public UserBeatBar()
{
BeatPoints = new List<Ellipse>();
}
}
}