C#绘制飞行棋地图小程序
作者:电杆 时间:2021-11-20 23:19:10
1、 初始化地图,在绘制时可先将地图进行初始化,用数组来存储关卡的位置,然后利用循环给地图中 关卡所在处赋予代表关卡的值。
关键代码如下
/// <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、检查坐标的值,在将地图进行初始化之后,便可开始进行绘制地图的操作了,地图绘制可使用 在程序设计时所讲的分布绘制,在绘制地图时应检验该该坐标点的值,在根据该点的值绘制相应的图案,在检查时根据值 返回相应的图案 ,在利用循环绘制出即可,检查坐标的值代码如下:
/// <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、绘制地图,在得到 返回的图案后,便可进行地图的绘制,这里给出绘制第一行的代码
/// <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
标签:c,飞行棋,地图
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
c#中Linq to Sql 增删除的实例
2022-08-24 02:15:34
IDEA Error:java:无效的源发行版:13的解决过程
2023-11-25 10:07:19
![](https://img.aspxhome.com/file/2023/8/59578_0s.png)
利用C#实现绘制出地球旋转效果
2022-10-01 14:21:27
![](https://img.aspxhome.com/file/2023/5/88315_0s.jpg)
Java数据类型的全面剖析
2022-07-09 06:51:38
![](https://img.aspxhome.com/file/2023/1/63061_0s.png)
Java运行时数据区概述详解
2023-10-08 07:00:10
![](https://img.aspxhome.com/file/2023/0/69130_0s.png)
spring mvc中@PathVariable / 带斜杠方式获取
2022-09-15 04:47:27
深入了解java内存分配和回收策略
2023-02-27 15:16:58
使用Linq注意事项避免报错的方法
2023-08-28 21:22:41
![](https://img.aspxhome.com/file/2023/7/82157_0s.png)
事务在c#中的使用
2021-11-27 23:30:29
Java Object类中的常用API介绍
2023-11-09 01:51:00
使用java执行定时任务示例
2022-09-16 21:23:22
C#定时关闭窗体实例
2023-07-09 22:53:25
Java线程创建的四种方式总结
2023-10-29 19:36:03
![](https://img.aspxhome.com/file/2023/7/58697_0s.png)
Java Web项目中解决中文乱码方法总结(三种最新方法)
2023-07-18 18:13:22
![](https://img.aspxhome.com/file/2023/7/65337_0s.png)
Spring Boot ActiveMQ连接池配置过程解析
2023-11-08 23:08:02
C#对Word文档的创建、插入表格、设置样式等操作实例
2021-10-24 23:13:46
Java Web实现文件下载和乱码处理方法
2022-03-14 20:28:38
基于Java代码实现支付充值的通用流程
2021-09-04 00:48:45
C#中使用资源的方法分析
2022-01-16 16:27:02
学习Android自定义Spinner适配器
2022-12-15 01:28:31
![](https://img.aspxhome.com/file/2023/6/88116_0s.jpg)