Merge branch 'master' into 'master'

persons[j].GetHashCode()在特定的电脑和运行环境下的值是固定的,会导致部分人在指定电脑上的得分比较高

See merge request !9
parents 62bdbf88 807db791
...@@ -52,7 +52,7 @@ namespace Lottery ...@@ -52,7 +52,7 @@ namespace Lottery
//计分方式3:随机加上一个人的金币,看能否逆袭 //计分方式3:随机加上一个人的金币,看能否逆袭
//其他方式:可在下方对NewGrade属性进行操作 //其他方式:可在下方对NewGrade属性进行操作
persons[j].NewGrade += (randoms[j] + persons[j].NewGrade += (randoms[j] +
(Math.Abs(persons[j].GetHashCode() << 1) % persons.Count) + //(Math.Abs(persons[j].GetHashCode() << 1) % persons.Count) +
persons[randoms[j] - 1].OldGrade); persons[randoms[j] - 1].OldGrade);
if (i == 3 && persons[j].BaseGrade > 0) if (i == 3 && persons[j].BaseGrade > 0)
......
...@@ -13,11 +13,14 @@ namespace Lottery ...@@ -13,11 +13,14 @@ namespace Lottery
public static void ShowTitle(string title) public static void ShowTitle(string title)
{ {
Console.ForegroundColor = ConsoleColor.Cyan; Console.ForegroundColor = ConsoleColor.Cyan;
Enumerable.Range(0, Console.LargestWindowWidth - 3).ToList().ForEach(p => Console.Write("$")); Enumerable.Range(0, Console.WindowWidth - 3).ToList().ForEach(p => Console.Write("$"));
Console.SetCursorPosition(Console.LargestWindowWidth / 2, 1); Console.Write(Environment.NewLine);
Console.SetCursorPosition(Console.WindowWidth / 2, 1);
title.ToList().ForEach(p => Console.Write(p)); title.ToList().ForEach(p => Console.Write(p));
Console.Write(Environment.NewLine);
Console.SetCursorPosition(0, 2); Console.SetCursorPosition(0, 2);
Enumerable.Range(0, Console.LargestWindowWidth - 3).ToList().ForEach(p => Console.Write("$")); Enumerable.Range(0, Console.WindowWidth - 3).ToList().ForEach(p => Console.Write("$"));
Console.Write(Environment.NewLine);
} }
public static void Show(int i, IReadOnlyList<Person> persons, IReadOnlyList<Lottery> lotteries) public static void Show(int i, IReadOnlyList<Person> persons, IReadOnlyList<Lottery> lotteries)
...@@ -43,61 +46,52 @@ namespace Lottery ...@@ -43,61 +46,52 @@ namespace Lottery
public static void ShowGradeList(IReadOnlyList<Person> person, int highlight) public static void ShowGradeList(IReadOnlyList<Person> person, int highlight)
{ {
Console.Write(Environment.NewLine);
int colCount = 3;
var titles = new List<string> { "排名", "人名", "金币" };
var people = person.OrderByDescending(p => p.NewGrade).ToList(); var people = person.OrderByDescending(p => p.NewGrade).ToList();
int width = ((Console.LargestWindowWidth - 6) / 3 - 6) / 3;
Console.ForegroundColor = ConsoleColor.Yellow; Console.ForegroundColor = ConsoleColor.Yellow;
var titles = new List<string> { "排名", "人名", "金币" };
//将结果分为多列输出,每列间隔
int colGap = (int)(Console.WindowWidth * 0.05);
//每列宽度
int colWidth = (Console.WindowWidth - colGap * (colCount-1)) / colCount;
//每列中分为多个表头,每个表头的宽度
int titleWidth = colWidth / titles.Count();
//添加表头
for (int colIndex = 0; colIndex < colCount; colIndex++)
{
for (int i = 0; i < titles.Count; i++) for (int i = 0; i < titles.Count; i++)
{ {
Console.SetCursorPosition(i * width, 5); Console.SetCursorPosition((colWidth + colGap) * colIndex + titleWidth * i, 4);
Console.Write(titles[i]); Console.Write(titles[i]);
} }
var list1 = people.Take(people.Count / 3).ToList();
int index = 1;
for (int i = 0; i < list1.Count; i++)
{
Console.ForegroundColor = index <= highlight ? ConsoleColor.Yellow : ConsoleColor.White;
Console.SetCursorPosition(0, i + 6);
Console.Write($"{index++}");
Console.SetCursorPosition(width, i + 6);
Console.Write($"{list1[i].Name}");
Console.SetCursorPosition(width * 2, i + 6);
Console.Write($"{list1[i].NewGrade}");
} }
Console.ForegroundColor = ConsoleColor.Yellow; Console.Write(Environment.NewLine);
for (int i = 1; i <= titles.Count; i++)
{ //按照从上到下、从左到右的顺序分多列输出结果
Console.SetCursorPosition((i - 1) * width + width * 4 - 4, 5); int rowCount = (int)Math.Ceiling((double)person.Count() / colCount);
Console.Write(titles[i - 1]); for (int i = 0; i < people.Count; i++)
}
var list2 = people.Skip(people.Count / 3).Take(people.Count / 3).ToList();
for (int i = 0; i < list2.Count; i++)
{ {
int rowIndex = i % rowCount;
int colIndex = i / rowCount;
int index = i + 1;
Console.ForegroundColor = index <= highlight ? ConsoleColor.Yellow : ConsoleColor.White; Console.ForegroundColor = index <= highlight ? ConsoleColor.Yellow : ConsoleColor.White;
Console.SetCursorPosition(0 + width * 4 - 4, i + 6); Console.SetCursorPosition((colWidth + colGap) * colIndex + 0, rowIndex + 5);
Console.Write($"{index++}"); Console.Write(index);
Console.SetCursorPosition(width + width * 4 - 4, i + 6); Console.SetCursorPosition((colWidth + colGap) * colIndex + titleWidth, rowIndex + 5);
Console.Write($"{list2[i].Name}"); Console.Write(people[i].Name);
Console.SetCursorPosition(width * 2 + width * 4 - 4, i + 6); Console.SetCursorPosition((colWidth + colGap) * colIndex + titleWidth * 2, rowIndex + 5);
Console.Write($"{list2[i].NewGrade}"); Console.Write(people[i].NewGrade);
}
Console.ForegroundColor = ConsoleColor.Yellow; if (colIndex == colCount - 1 || index == people.Count)
for (int i = 1; i <= titles.Count; i++)
{ {
Console.SetCursorPosition((i - 1) * width + width * 8 - 4, 5); //每行的最后一列
Console.Write(titles[i - 1]); Console.Write(Environment.NewLine);
} }
var list3 = people.Skip(people.Count / 3).Skip(people.Count / 3).ToList();
for (int i = 0; i < list3.Count; i++)
{
Console.ForegroundColor = index <= highlight ? ConsoleColor.Yellow : ConsoleColor.White;
Console.SetCursorPosition(0 + width * 8 - 4, i + 6);
Console.Write($"{index++}");
Console.SetCursorPosition(width + width * 8 - 4, i + 6);
Console.Write($"{list3[i].Name}");
Console.SetCursorPosition(width * 2 + width * 8 - 4, i + 6);
Console.Write($"{list3[i].NewGrade}");
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment