c#菜鸟:(迷宫)控制台小程序(参考大师作品)
来源:互联网 发布:matlab 优化工具箱 编辑:程序博客网 时间:2024/04/29 18:36
class Program
{
//游戏迷宫设置数组
private static int[,] maze = {
{2,0,2,2,2,2,2,2,2,2,2,2,2,2},
{2,0,0,0,0,0,2,2,0,0,0,2,2,2},
{2,0,2,0,2,0,0,0,0,2,0,0,0,2},
{2,0,0,2,0,2,2,2,2,2,2,2,0,2},
{2,2,0,2,0,2,2,0,0,0,0,0,0,2},
{2,0,0,0,0,0,2,0,2,2,2,2,2,2},
{2,2,2,2,0,2,2,0,2,0,0,0,0,2},
{2,0,0,0,0,0,0,0,2,0,2,2,0,2},
{2,0,2,2,2,2,2,2,2,0,2,0,0,2},
{2,0,2,0,0,0,0,0,2,0,2,0,2,2},
{2,0,2,0,2,0,2,0,2,0,2,0,2,2},
{2,0,0,0,0,0,0,0,0,0,2,0,0,0},
{2,0,2,2,0,2,0,2,2,2,2,2,2,2},
{2,2,2,2,2,2,2,2,2,2,2,2,2,2}};
static void Main(string[] args)
{
int x = 0;
int y = 1;
games(x, y);
//键盘按键读取
while (true)
{
char input=Console.ReadKey().KeyChar;
switch (input.ToString().ToUpper())
{
case "W"://向上移动
x--;
if (justfy(x, y)==false)
{
x++;
}
break;
case "S"://向下移动
x++;
if (justfy(x, y) == false)
{
x--;
}
break;
case "A"://向左移动
y--;
if (justfy(x, y) == false)
{
y++;
}
break;
case "D"://向右移动
y++;
if (justfy(x, y) == false)
{
y--;
}
break;
case "E"://退出程序
return;
}
}
}
//判断移动方向是否有阻挡物
public static bool justfy(int x,int y)
{
if (y>13)
{
Console.WriteLine("successful");
return false;
}
if (x < 0 || (int)maze.GetValue(x, y) == 2)
{
Console.WriteLine("there is no way");
return false;
}
Console.Clear();
games(x, y);
return true;
}
//画迷宫
public static void games(int x,int y)
{
for (int i = 0; i < 14; i++)
{
for (int j = 0; j < 14; j++)
{
if ((int)maze.GetValue(i, j) == 2)
{
Console.Write("■");
}
else if(i==x && j==y)
{
Console.Write("◇");
}
else
{
Console.Write(" ");
}
}
Console.Write("/n");
}
}
}
- c#菜鸟:(迷宫)控制台小程序(参考大师作品)
- javaScript菜鸟:学习js继承后的总结(参考大师示例)
- javaScript菜鸟:学习js的Sort()排序的总结(参考大师示例)
- C# 小程序之新手练习(一)控制台动态输出当前时间
- c#控制台读取文件小程序
- C#简易聊天机器人(控制台程序)
- C#初学界面参考小程序
- 简单C# 猜数程序(控制台程序)
- 加中实训答辩作品(走迷宫) - 2013.6.2
- 迷宫小程序
- 迷宫小程序
- 迷宫程序(1)
- 迷宫程序(2)
- 迷宫程序(4)
- 迷宫程序(5)
- 迷宫程序(6)
- 小鑫的城堡(参考的小希的迷宫写的代码)并查集
- C#控制台程序启动后最小化或者隐藏小黑板
- CSS字体
- Java线程: 优先级
- vim ruby 缩进设置
- 根据已知条件,查找该条件出现在那张表中
- 一个结构体长度的问题
- c#菜鸟:(迷宫)控制台小程序(参考大师作品)
- JS控件
- 连接不变色
- C++虚函数表解析(转)
- aria2一个不错的muti-thread 下载工具 for linux
- PKU 1065,1548,3636解题报告
- Lunar
- WPF中使用BitmapImage处理图片文件
- 偶尔有感