📄 resulthelper.cs
字号:
using System;
using System.Text;
using System.Collections;
namespace WinHRD
{
public class ResultHelper
{
//===========================================================
// 根据布局整数,显示图形表示
//===========================================================
public static void MakeLayout(string[] s, int n)
{
string s1 = "";
Stack _stack = new Stack();
string[,] map = new string[4,5];
int[,] mark = new int[4,5]; // 用来判断下一个棋子应当放在什么位置的标记数组
string[] line = {"+---+---+---+---+",
"+---+---+---+---+",
"+---+---+---+---+",
"+---+---+---+---+",
"+---+---+---+---+"};
string[] split = {"||||","||||","||||","||||","||||"};
int a = 3; // 二进制的 “11”
int b, c, d, x = 0, y = 0, j = 1;
// 将棋子位置压入堆栈,以备反排序
for(int i = 0; i<11; i++)
{
b = a<<(i*2);
c = (n & b)>>(i*2);
_stack.Push(c);
}
int aPosition = n >> 22; //找到 A 的位置
for(int i = 0; i<12; i++)
{
// 获取下一个棋子的位置
GetNextPosition(ref x, ref y, mark);
if(i == aPosition - 1) // 曹操
{
MarkAPosition(x, y, map, mark, "A", line, split);
}
else
{
d = (int)_stack.Pop();
switch(d)
{
case 0: // 空格
MarkBPosition(x, y, map, mark, " ", line, split);
break;
case 1: // 卒
MarkSPosition(x, y, map, mark, j.ToString(), line, split);
j += 1;
break;
case 2: // 竖放
MarkVPosition(x, y, map, mark, j.ToString(), line, split);
j += 1;
break;
case 3: // 横放
MarkHPosition(x, y, map, mark, j.ToString(), line, split);
j += 1;
break;
}
}
}
// 输出
s[1] = "+---+---+---+---+";
for(j = 0; j<5; j++)
{
s1 = "| ";
for(int i = 0; i<4; i++)
s1 += String.Format(map[i,j] + " " + split[j].Substring(i,1) + " ");
s[j*2 + 2] = s1;
s[j*2 + 3] = line[j];
}
return;
}
#region Private Methods
private static void MarkAPosition(int x, int y, string[,] map, int[,] mark, string c, string[] line, string[] split)
{
map[x, y] = c;
map[x + 1, y + 1] = c;
map[x + 1, y] = c;
map[x, y + 1] = c;
mark[x, y] = 1;
mark[x + 1, y + 1] = 1;
mark[x + 1, y] = 1;
mark[x, y + 1] = 1;
string s = line[y].Remove(4*x+1,7);
line[y] = s.Insert(4*x+1," ");
s = split[y].Remove(x,1);
split[y] = s.Insert(x," ");
s = split[y+1].Remove(x,1);
split[y+1] = s.Insert(x," ");
}
private static void MarkHPosition(int x, int y, string[,] map, int[,] mark, string c, string[] line, string[] split)
{
map[x, y] = c;
map[x + 1, y] = c;
mark[x, y] = 1;
mark[x + 1, y] = 1;
string s = split[y].Remove(x,1);
split[y] = s.Insert(x," ");
}
private static void MarkVPosition(int x, int y, string[,] map, int[,] mark, string c, string[] line, string[] split)
{
map[x, y] = c;
map[x, y + 1] = c;
mark[x, y] = 1;
mark[x, y + 1] = 1;
string s = line[y].Remove(4*x+1,3);
line[y] = s.Insert(4*x+1," ");
}
private static void MarkSPosition(int x, int y, string[,] map, int[,] mark, string c, string[] line, string[] split)
{
map[x, y] = c;
mark[x, y] = 1;
}
private static void MarkBPosition(int x, int y, string[,] map, int[,] mark, string c, string[] line, string[] split)
{
map[x, y] = c;
mark[x, y] = 1;
}
private static void GetNextPosition(ref int x, ref int y, int[,] mark)
{
for(int j=0; j<5; j++)
for(int i=0; i<4; i++)
if(mark[i,j]==0)
{
x = i;
y = j;
return;
}
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -