win.cs
来自「visual c# 网络编程技术与实践实例包括几个源码」· CS 代码 · 共 101 行
CS
101 行
using System;
namespace 五子棋
{
/// <summary>
/// IsWin 的摘要说明。
/// </summary>
public class Win
{
int[,] pos;
public Win(int[,]p)
{
pos=p;
}
public int winchess( int cellx,int celly)
{
for(int i=0;i<5;i++)
{
int xtotal=Wfive(cellx-i,celly);
if(Math.Abs(xtotal)==5)
return xtotal;
int ytotal=Hfive(cellx,celly-i);
if(Math.Abs(ytotal)==5)
return ytotal;
int xytotal=Piefive(cellx+i,celly-i);
if(Math.Abs(xytotal)==5)
return xytotal;
xytotal=Lafive(cellx-i,celly-i);
if(Math.Abs(xytotal)==5)
return xytotal;
}
return 0;
}
private int Wfive(int xbegin,int y)
{
int total=0;
for(int i=0;i<5;i++)
{
try
{
total=total+pos[xbegin+i,y];
}
catch
{
return 0;
}
}
return total;
}
private int Hfive(int x,int ybegin)
{
int total=0;
for(int i=0;i<5;i++)
{
try
{
total=total+pos[x,ybegin+i];
}
catch
{
return 0;
}
}
return total;
}
private int Piefive(int x,int y)
{
int total=0;
for(int i=0;i<5;i++)
{
try
{
total=total+pos[x-i,y+i];
}
catch
{
return 0;
}
}
return total;
}
private int Lafive(int x,int y)
{
int total=0;
for(int i=0;i<5;i++)
{
try
{
total=total+pos[x+i,y+i];
}
catch
{
return 0;
}
}
return total;
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?