📄 form1.cs
字号:
if (x < m - 1 && y < n - 2&&style!=3)//---------------3
{
if (S[x + 1, y + 2] < 0)
{
S[x + 1, y + 2] = 1;
PIX pix = new PIX();
pix.x = x +1;
pix.y = y + 2;
mystack.Push(pix);
tag =tryget(x + 1, y + 2);
}
}
if (x < m - 2 && y < n - 1&&style!=4)//---------------4
{
if (S[x + 2, y + 1] < 0)
{
S[x + 2, y + 1] = 1;
PIX pix = new PIX();
pix.x = x + 2;
pix.y = y + 1;
mystack.Push(pix);
tag = tryget(x + 2, y + 1);
}
}
if (x < m - 2 && y >=1&&style!=5)//-------------------5
{
if (S[x + 2, y - 1] < 0)
{
S[x + 2, y - 1] = 1;
PIX pix = new PIX();
pix.x = x + 2;
pix.y = y - 1;
mystack.Push(pix);
tag =tryget(x + 2, y - 1);
}
}
if (x < m - 1 && y >= 2&&style!=6)//------------------6
{
if (S[x + 1, y - 2] < 0)
{
S[x + 1, y - 2] = 1;
PIX pix = new PIX();
pix.x = x +1;
pix.y = y-2;
mystack.Push(pix);
tag =tryget(x + 1, y - 2);
}
}
if (x > 0 && y >= 2&&style!=7)//----------------------7
{
if (S[x - 1, y - 2] < 0)
{
S[x - 1, y - 2] = 1;
PIX pix = new PIX();
pix.x = x - 1;
pix.y = y -2;
mystack.Push(pix);
tag =tryget(x - 1, y - 2);
}
}
if (x >= 2 && y >= 1&&style!=8)//---------------------8
{
if (S[x - 2, y - 1] < 0)
{
S[x - 2, y - 1] = 1;
PIX pix = new PIX();
pix.x = x - 2;
pix.y = y - 1;
mystack.Push(pix);
tag =tryget(x - 2, y - 1);
}
}
if (!tag)
{
PIX pix = new PIX();
pix = mystack.Pop();
S[pix.x, pix.y] = -1;
return false;
}
else
{
return true;
}
}
private bool testS()
{
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
{
if (S[i, j] < 0)
{
return false;
}
}
}
return true;
}
private void button1_Click(object sender, EventArgs e)
{
huitu = true;
panel1.Size = new Size(n * size + 50, m * size + 50);
this.panel1.Refresh();
//for (int i = path.Length - 1; i >= 0; i--)
//{
// listBox1.Items.Add(i.ToString() + ": (" + path[i].x.ToString() + "," + path[i].y.ToString() + ")");
//}
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
//绘制坐标
int a = 10;
int b = 10;
int intervel = 20;
Pen mypen = new Pen(Color.Black, 1f);
Point o1 = new Point( a,b+intervel);
Point e1 = new Point(a, b+m*size);
Point e10 = new Point(a-5, b + m * size-5);//形成下箭头
Point e12 = new Point(a+5, b + m * size-5);
e.Graphics.DrawLine(mypen, e10, e1);
e.Graphics.DrawLine(mypen, e12, e1);
e.Graphics.DrawString("X", new Font("隶书", 10f), Brushes.Black, e1);
//形成坐标
for (int i = 0; i < m; i++)
{
Point tp = new Point(a, b + intervel+i*size);
Point tp1 = new Point(a+ 5, b + intervel + i * size );
e.Graphics.DrawLine(mypen, tp, tp1);
e.Graphics.DrawString(i.ToString(), new Font("隶书", 10f), Brushes.Black, tp1);
}
//------------------------------------------------------------------------
Point o2 = new Point(a+intervel,b);
Point e2 = new Point(a+n*size, b);
Point e20 = new Point(a + n * size-5, b+5);//形成右箭头
Point e22 = new Point(a + n * size-5, b-5);
e.Graphics.DrawLine(mypen, e20, e2);
e.Graphics.DrawLine(mypen, e22, e2);
e.Graphics.DrawString("Y", new Font("隶书", 10f), Brushes.Black, e2);
//形成坐标
for (int i = 0; i < n; i++)
{
Point tp = new Point(a + intervel+ i * size, b);
Point tp1 = new Point(a + intervel+ i * size, b +5);
e.Graphics.DrawLine(mypen, tp, tp1);
e.Graphics.DrawString(i.ToString(), new Font("隶书", 10f), Brushes.Black, tp1);
}
e.Graphics.DrawLine(mypen, o1, e1);
e.Graphics.DrawLine(mypen, o2, e2);
mydrawpix myp = new mydrawpix();
myp.baseX = a + intervel;
myp.baseY = b + intervel;
myp.size = size;
myp.drawpix(sender, e, m, n);
if (huitu)
{
myp.drawPIXarrayline(sender, e, path);
}
}
private void Form1_Load(object sender, EventArgs e)
{
button1.Enabled = false;
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
style = comboBox1.SelectedIndex + 1;
}
}
struct PIX
{
public int x;
public int y;
}
class mydrawpix
{
public int size = 50;
public int baseX = 10;
public int baseY = 10;
Pen p = new Pen(Color.Red, 1f);
Pen pen2 = new Pen(Color.Blue, 1f);
public void drawpix(object sender, PaintEventArgs e,int m, int n)
{
//首先连M条横线
for (int i = 0; i < m; i++)
{
Point p1 = new Point(baseY, baseX + i * size);
Point p2 = new Point(baseY+(n - 1) * size, baseX + i * size);
e.Graphics.DrawLine(p, p1, p2);
}
//再连N条竖线
for (int i = 0; i < n; i++)
{
Point p1 = new Point(baseY+i*size,baseX );
Point p2 = new Point(baseY + i * size,baseX+(m - 1) * size );
e.Graphics.DrawLine(p, p1, p2);
}
}
public void drawPIXarrayline(object sender, PaintEventArgs e, PIX[] A)
{
int s = 1;
Font f = new Font("隶书", 10f);
e.Graphics.DrawString(s.ToString(), f, Brushes.Green,baseX+ A[A.Length - 1].y * size,baseY+ A[A.Length - 1].x * size);
if (File.Exists("ma.bmp"))
{
Bitmap bmp = new Bitmap("ma.bmp");
e.Graphics.DrawImage(bmp, baseX + A[A.Length - 1].y * size - 15, baseY + A[A.Length - 1].x * size - 15, 20, 20);
}
int endx = 0;
int endy = 0;
for (int i = A.Length-1; i > 0; i--)
{
s++;
PIX pix = A[i];
int x =baseY+ pix.x*size;
int y =baseX+ pix.y * size;
PIX pix2 = A[i-1];
int x2 =baseY+ pix2.x * size;
int y2 =baseX+ pix2.y * size;
Point p1=new Point(y,x);
Point p2=new Point(y2,x2);
e.Graphics.DrawLine(pen2, p1, p2);
e.Graphics.DrawString(s.ToString(),f , Brushes.Green, y2, x2);
endx = y2;
endy = x2;
}
if (File.Exists("ma.bmp"))
{
Bitmap bmp = new Bitmap("ma.bmp");
e.Graphics.DrawImage(bmp, endx- 15,endy - 15, 20, 20);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -