Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
L
Lottery
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
李静
Lottery
Commits
807db791
Commit
807db791
authored
Oct 23, 2019
by
李静
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
解决窗口最小化后再还原时内容会错乱的问题;
优化结果输出逻辑
parent
ba6fb711
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
51 deletions
+45
-51
Screen.cs
Lottery/Lottery/Screen.cs
+45
-51
No files found.
Lottery/Lottery/Screen.cs
View file @
807db791
...
@@ -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
>
{
"排名"
,
"人名"
,
"金币"
};
for
(
int
i
=
0
;
i
<
titles
.
Count
;
i
++)
{
Console
.
SetCursorPosition
(
i
*
width
,
5
);
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
}
"
);
int
colGap
=
(
int
)(
Console
.
WindowWidth
*
0.05
);
}
//每列宽度
Console
.
ForegroundColor
=
ConsoleColor
.
Yellow
;
int
colWidth
=
(
Console
.
WindowWidth
-
colGap
*
(
colCount
-
1
))
/
colCount
;
for
(
int
i
=
1
;
i
<=
titles
.
Count
;
i
++)
//每列中分为多个表头,每个表头的宽度
{
int
titleWidth
=
colWidth
/
titles
.
Count
();
Console
.
SetCursorPosition
((
i
-
1
)
*
width
+
width
*
4
-
4
,
5
);
Console
.
Write
(
titles
[
i
-
1
]);
//添加表头
}
for
(
int
colIndex
=
0
;
colIndex
<
colCount
;
colIndex
++)
var
list2
=
people
.
Skip
(
people
.
Count
/
3
).
Take
(
people
.
Count
/
3
).
ToList
();
for
(
int
i
=
0
;
i
<
list2
.
Count
;
i
++)
{
Console
.
ForegroundColor
=
index
<=
highlight
?
ConsoleColor
.
Yellow
:
ConsoleColor
.
White
;
Console
.
SetCursorPosition
(
0
+
width
*
4
-
4
,
i
+
6
);
Console
.
Write
(
$"
{
index
++}
"
);
Console
.
SetCursorPosition
(
width
+
width
*
4
-
4
,
i
+
6
);
Console
.
Write
(
$"
{
list2
[
i
].
Name
}
"
);
Console
.
SetCursorPosition
(
width
*
2
+
width
*
4
-
4
,
i
+
6
);
Console
.
Write
(
$"
{
list2
[
i
].
NewGrade
}
"
);
}
Console
.
ForegroundColor
=
ConsoleColor
.
Yellow
;
for
(
int
i
=
1
;
i
<=
titles
.
Count
;
i
++)
{
{
Console
.
SetCursorPosition
((
i
-
1
)
*
width
+
width
*
8
-
4
,
5
);
for
(
int
i
=
0
;
i
<
titles
.
Count
;
i
++)
Console
.
Write
(
titles
[
i
-
1
]);
{
Console
.
SetCursorPosition
((
colWidth
+
colGap
)
*
colIndex
+
titleWidth
*
i
,
4
);
Console
.
Write
(
titles
[
i
]);
}
}
}
var
list3
=
people
.
Skip
(
people
.
Count
/
3
).
Skip
(
people
.
Count
/
3
).
ToList
();
Console
.
Write
(
Environment
.
NewLine
);
for
(
int
i
=
0
;
i
<
list3
.
Count
;
i
++)
//按照从上到下、从左到右的顺序分多列输出结果
int
rowCount
=
(
int
)
Math
.
Ceiling
((
double
)
person
.
Count
()
/
colCount
);
for
(
int
i
=
0
;
i
<
people
.
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
*
8
-
4
,
i
+
6
);
Console
.
SetCursorPosition
((
colWidth
+
colGap
)
*
colIndex
+
0
,
rowIndex
+
5
);
Console
.
Write
(
$"
{
index
++}
"
);
Console
.
Write
(
index
);
Console
.
SetCursorPosition
(
width
+
width
*
8
-
4
,
i
+
6
);
Console
.
SetCursorPosition
((
colWidth
+
colGap
)
*
colIndex
+
titleWidth
,
rowIndex
+
5
);
Console
.
Write
(
$"
{
list3
[
i
].
Name
}
"
);
Console
.
Write
(
people
[
i
].
Name
);
Console
.
SetCursorPosition
(
width
*
2
+
width
*
8
-
4
,
i
+
6
);
Console
.
SetCursorPosition
((
colWidth
+
colGap
)
*
colIndex
+
titleWidth
*
2
,
rowIndex
+
5
);
Console
.
Write
(
$"
{
list3
[
i
].
NewGrade
}
"
);
Console
.
Write
(
people
[
i
].
NewGrade
);
if
(
colIndex
==
colCount
-
1
||
index
==
people
.
Count
)
{
//每行的最后一列
Console
.
Write
(
Environment
.
NewLine
);
}
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment