static void Main(string[] args)
{
string[,] QP = new string[17, 17]; //定义二维数组QP同时设置棋盘大小
while (true)
{
Console.Clear();
int left = 16;
int top = 8;
for (int i = 0; i < QP.GetLength(0); i++)
{
for (int j = 0; j < QP.GetLength(1); j++) //为数组QP每个元素赋初值 用“□”代替棋盘网格
{
QP[i, j] = "□";
}
}
for (int i = 0; i < QP.GetLength(0); i++)
{
for (int j = 0; j < QP.GetLength(1); j++)
{
Console.Write(QP[i, j]); //遍历数组QP 并将其打印在窗体 使界面看起来像是网格状
}
Console.WriteLine();
}
bool = true;
bool J = true;
while (J)
{
Console.SetCursorPosition(left, top); //设置光标初始位置
ConsoleKey key = Console.ReadKey(true).Key; //读取输入值
switch (key) //switch语句控制光标的移动,上下左右共4个方向 可同时由方向键和“W”“S”“A”“D”2组组合键控制
{
case ConsoleKey.UpArrow:
case ConsoleKey.W:
if (top > 0)
{
top--;
}
break;
case ConsoleKey.DownArrow:
case ConsoleKey.S:
if (top < 16)
{
top++;
}
break;
case ConsoleKey.LeftArrow:
case ConsoleKey.A:
if (left > 0)
{
left = left - 2;
}
break;
case ConsoleKey.RightArrow:
case ConsoleKey.D:
if (left < 32)
{
left = left + 2;
}
break;
default: //默认值设置 当按件不为定义的2组组合键时,若当前光标位置不是“□”,则不能操作,
if (QP[top, left / 2] != "□") //若是“□”,则判断值,为ture则打印"●",否则打印"○",同时数组相应位置的值发声替换
{
continue; //以实现两种棋子交替出现
}
if ()
{
Console.ForegroundColor = ConsoleColor.Blue;
Console.Write("●");
QP[top, left / 2] = "●";
}
else
{
Console.Write("○");
QP[top, left / 2] = "○";
}
if (SF(QP, top, left / 2)) //调用SF方法 判断输赢
{
J = false;
Console.Beep();
System.Threading.Thread.Sleep(2000);
}
= !;
break;
}
}
}
}
static bool SF(string[,] strarr, int x, int y) //自定义SF方法 判断获胜玩家
{
int xx = x;
int yy = y;
string ActChe = strarr[x, y];
int i = 1; //i表示目前相连的同色棋子数 默认为1
//第一种情况,x不动,y在变化 即判断y方向上是否获胜
while (true)
{
if (--yy >= 0)
{
if (ActChe == strarr[xx, yy])
{
i++;
if (i == 5)
{
return true;
}
}
else
{
break;
}
}
else
{
break;
}
}
xx = x;
yy = y;
while (true)
{
if (++yy < 17)
{
if (ActChe == strarr[xx, yy])
{
i++;
if (i == 5)
{
return true;
}
}
else
{
break;
}
}
else
{
break;
}
} //第二种情况,y不动,x在变化
i = 1;
xx = x;
yy = y;
while (true)
{
if (--xx >= 0)
{
if (ActChe == strarr[xx, yy])
{
i++;
if (i == 5)
{
return true;
}
}
else
{
break;
}
}
else
{
break;
}
}
xx = x;
yy = y;
while (true)
{
if (++xx < 17)
{
if (ActChe == strarr[xx, yy])
{
i++;
if (i == 5)
{
return true;
}
}
else
{
break;
}
}
else
{
break;
}
}
//第三种情况,x,y同增同减
i = 1;
xx = x;
yy = y;
while (true)
{
if (--xx >= 0 && --yy >= 0)
{
if (ActChe == strarr[xx, yy])
{
i++;
if (i == 5)
{
return true;
}
}
else
{
break;
}
}
else
{
break;
}
}
xx = x;
yy = y;
while (true)
{
if (++xx < 17 && ++yy < 17)
{
if (ActChe == strarr[xx, yy])
{
i++;
if (i == 5)
{
return true;
}
}
else
{
break;
}
}
else
{
break;
}
} //第四种情况 x加,y减,或y加,x减
i = 1;
xx = x;
yy = y;
while (true)
{
if (--xx >= 0 && ++yy < 17)
{
if (ActChe == strarr[xx, yy])
{
i++;
if (i == 5)
{
return true;
}
}
else
{
break;
}
}
else
{
break;
}
}
xx = x;
yy = y;
while (true)
{
if (++xx < 17 && --yy > 0)
{
if (ActChe == strarr[xx, yy])
{
i++;
if (i == 5)
{
return true;
}
}
else
{
break;
}
}
else
{
break;
}
}
return false;
}加红色的 在代码起什么作用
{
string[,] QP = new string[17, 17]; //定义二维数组QP同时设置棋盘大小
while (true)
{
Console.Clear();
int left = 16;
int top = 8;
for (int i = 0; i < QP.GetLength(0); i++)
{
for (int j = 0; j < QP.GetLength(1); j++) //为数组QP每个元素赋初值 用“□”代替棋盘网格
{
QP[i, j] = "□";
}
}
for (int i = 0; i < QP.GetLength(0); i++)
{
for (int j = 0; j < QP.GetLength(1); j++)
{
Console.Write(QP[i, j]); //遍历数组QP 并将其打印在窗体 使界面看起来像是网格状
}
Console.WriteLine();
}
bool = true;
bool J = true;
while (J)
{
Console.SetCursorPosition(left, top); //设置光标初始位置
ConsoleKey key = Console.ReadKey(true).Key; //读取输入值
switch (key) //switch语句控制光标的移动,上下左右共4个方向 可同时由方向键和“W”“S”“A”“D”2组组合键控制
{
case ConsoleKey.UpArrow:
case ConsoleKey.W:
if (top > 0)
{
top--;
}
break;
case ConsoleKey.DownArrow:
case ConsoleKey.S:
if (top < 16)
{
top++;
}
break;
case ConsoleKey.LeftArrow:
case ConsoleKey.A:
if (left > 0)
{
left = left - 2;
}
break;
case ConsoleKey.RightArrow:
case ConsoleKey.D:
if (left < 32)
{
left = left + 2;
}
break;
default: //默认值设置 当按件不为定义的2组组合键时,若当前光标位置不是“□”,则不能操作,
if (QP[top, left / 2] != "□") //若是“□”,则判断值,为ture则打印"●",否则打印"○",同时数组相应位置的值发声替换
{
continue; //以实现两种棋子交替出现
}
if ()
{
Console.ForegroundColor = ConsoleColor.Blue;
Console.Write("●");
QP[top, left / 2] = "●";
}
else
{
Console.Write("○");
QP[top, left / 2] = "○";
}
if (SF(QP, top, left / 2)) //调用SF方法 判断输赢
{
J = false;
Console.Beep();
System.Threading.Thread.Sleep(2000);
}
= !;
break;
}
}
}
}
static bool SF(string[,] strarr, int x, int y) //自定义SF方法 判断获胜玩家
{
int xx = x;
int yy = y;
string ActChe = strarr[x, y];
int i = 1; //i表示目前相连的同色棋子数 默认为1
//第一种情况,x不动,y在变化 即判断y方向上是否获胜
while (true)
{
if (--yy >= 0)
{
if (ActChe == strarr[xx, yy])
{
i++;
if (i == 5)
{
return true;
}
}
else
{
break;
}
}
else
{
break;
}
}
xx = x;
yy = y;
while (true)
{
if (++yy < 17)
{
if (ActChe == strarr[xx, yy])
{
i++;
if (i == 5)
{
return true;
}
}
else
{
break;
}
}
else
{
break;
}
} //第二种情况,y不动,x在变化
i = 1;
xx = x;
yy = y;
while (true)
{
if (--xx >= 0)
{
if (ActChe == strarr[xx, yy])
{
i++;
if (i == 5)
{
return true;
}
}
else
{
break;
}
}
else
{
break;
}
}
xx = x;
yy = y;
while (true)
{
if (++xx < 17)
{
if (ActChe == strarr[xx, yy])
{
i++;
if (i == 5)
{
return true;
}
}
else
{
break;
}
}
else
{
break;
}
}
//第三种情况,x,y同增同减
i = 1;
xx = x;
yy = y;
while (true)
{
if (--xx >= 0 && --yy >= 0)
{
if (ActChe == strarr[xx, yy])
{
i++;
if (i == 5)
{
return true;
}
}
else
{
break;
}
}
else
{
break;
}
}
xx = x;
yy = y;
while (true)
{
if (++xx < 17 && ++yy < 17)
{
if (ActChe == strarr[xx, yy])
{
i++;
if (i == 5)
{
return true;
}
}
else
{
break;
}
}
else
{
break;
}
} //第四种情况 x加,y减,或y加,x减
i = 1;
xx = x;
yy = y;
while (true)
{
if (--xx >= 0 && ++yy < 17)
{
if (ActChe == strarr[xx, yy])
{
i++;
if (i == 5)
{
return true;
}
}
else
{
break;
}
}
else
{
break;
}
}
xx = x;
yy = y;
while (true)
{
if (++xx < 17 && --yy > 0)
{
if (ActChe == strarr[xx, yy])
{
i++;
if (i == 5)
{
return true;
}
}
else
{
break;
}
}
else
{
break;
}
}
return false;
}加红色的 在代码起什么作用
解决方案 »
- C#怎么在局域网内把一个文件夹传到另一台电脑上的某个目录,需要用到什么技术,或者求贴代码,这方面我还没学过
- 请问各位高手,有谁知道怎么去掉Activereport6.2.3681.0的水印吗?
- 请问webBrowser使用代理时如何屏蔽弹出的用户名与密码输入对话框
- 关于默认浏览器的问题。。。
- 望高手指点 十块砖的问题
- 应用程序如果工具栏比较多,应该使用什么样的布局用户比较喜欢啊?
- 图片处理(半色调,点阵调色法,代数调色法)
- 关于Decimal的问题
- 《急求》用number类型,可不可以输入小数点是几位就保存几位。连零也保存。(挺高难度的)高分求救啊.up者有分啊。
- C# 多线程和界面交互问题
- c#如何播放远程计算机上的wav文件
- .NET序列化问题
是给QP[top, left / 2]赋值,分别为"●","○";SF(QP, top, left / 2)
sf(p1,p2,p3);这是调用了叫sf的方法,有3个参数,分别传入了QP,top,left/2
从他的位置看,这个方法的返回值是个布尔值(true 或者 false);