1、 初始化地图,在绘制时可先将地图进行初始化,用数组来存储关卡的位置,然后利用循环给地图中 关卡所在处赋予代表关卡的值。
关键代码如下
?| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
/// <summary>
/// 初始化游戏地图
/// </summary>
static void initialmap()
{
for (int i=0;i<map.length;i++)
{
map[i] =0;
}
//用于存储关卡位置
int[] luckyturn = { 6, 23, 40, 55, 69, 83,98 };//幸运转盘 1
int[] landmine = { 5, 13, 17, 33, 38, 50, 64, 80, 94 };//地雷 2
int[] pause = { 9, 27, 60, 93 };//暂停 3
int[] timetunnel = { 20, 25, 45, 63, 72, 88, 90};//时空隧道 4
for (int i=0;i<luckyturn.length;i++)
{
int pos = luckyturn[i];
map[pos] = 1;
}
for (int i=0;i<landmine.length;i++)
{
map[landmine[i]] = 2;
}
for (int i=0;i<pause.length;i++)
{
int pos = pause[i];
map[pos] = 3;
}
for(int i=0;i<timetunnel.length;i++)
{
int pos = timetunnel[i];
map[pos] =4;
}
}
|
2、检查坐标的值,在将地图进行初始化之后,便可开始进行绘制地图的操作了,地图绘制可使用 在程序设计时所讲的分布绘制,在绘制地图时应检验该该坐标点的值,在根据该点的值绘制相应的图案,在检查时根据值 返回相应的图案 ,在利用循环绘制出即可,检查坐标的值代码如下:
?| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
/// <summary>
/// 获得要绘制的坐标
/// </summary>
/// <param name="i"> 要绘制的坐标</param>
/// <returns></returns>
static string getmapstring(int i)
{
string result="";//用于返回 给一个坐标相应的图案
if (playerpos[0] == i && playerpos[1] == i)//判断是否是对战双方所在此处
{
console.foregroundcolor = consolecolor.yellow;//设置图案的前景色为黄色
result = "<>";//得到两人均在图案
}
else if (playerpos[0] == i)
{
console.foregroundcolor = consolecolor.yellow;
result = "a";//得到a均在图案
}
else if (playerpos[1] == i)
{
console.foregroundcolor = consolecolor.yellow;
result = "b";//得到b均在图案
}
else
{
switch (map[i])
{
case 0:
console.foregroundcolor = consolecolor.white;
result = "□";//得到普通均在图案
break;
case 1:
console.foregroundcolor = consolecolor.red;
result = "○";//得转盘图案
break;
case 2:
console.foregroundcolor = consolecolor.blue;
result = "☆";
break;
case 3:
console.foregroundcolor = consolecolor.green;
result = "▲";
break;
case 4:
console.foregroundcolor = consolecolor.darkblue;
result = "卍";
break;
}
}
return result; //返回图案
}
|
3、绘制地图,在得到 返回的图案后,便可进行地图的绘制,这里给出绘制第一行的代码
?| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
/// <summary>
/// 绘制游戏地图
/// </summary>
static void drownmap()
{
console.writeline("图例:幸运转盘 ○ 地雷 ☆ 暂停 ▲ 时空隧道 卍");
//画第一行 下标0-29 的地图
for(int i=0;i<30;i++)//循环坐标得到 第一行每个点的图案
{
console.write(getmapstring(i)); //调用函数得到每个坐标的图案
}
console.write("\n");
console.resetcolor();//重置前景色
}
|
以上所述是小编给大家介绍的c#绘制飞行棋地图小程序,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对服务器之家网站的支持!
原文链接:http://www.cnblogs.com/lovelei/archive/2016/09/09/5856014.html








发表评论
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。