梦幻之旅
来源:互联网 发布:常用的js兼容性问题 编辑:程序博客网 时间:2024/04/27 17:45
首先,我的地图编辑器是十分简单的,但是网上一个像样的例子也没有,很是无奈,或许是我没有找到吧,不喜欢的勿拍。接下来进入正题。我的地图就比较简单,就是简单的1和0。1表示可走,0表示不可走。接下来先看看软件的截图吧
首先需要一个panel ,也就是一个画板,画板的背景是一张地图图片,接下来就是往画板上话虚线 那么 贴上代码(里面代码注释已经很详细了)
1 private void panel1_Paint(object sender, PaintEventArgs e) 2 { 3 4 Rectangle rect = this.Bounds; // 获取当前窗体的坐标 5 int col = 320 / 32; // 网格的列数 6 int row = 240 / 24; // 网格的行数 7 int drawRow = 0; 8 int drawCol = 0; 9 Pen p = new Pen(Brushes.Blue); // 实例化画笔。10 p.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDot; // 设置画笔的样式(虚线)。11 for (int i = 0; i <= row; i++) // 画水平线12 {13 e.Graphics.DrawLine(p, 0, drawCol, 320, drawCol);14 drawCol += 24;15 }16 for (int j = 0; j <= col; j++)// 画垂直线17 {18 e.Graphics.DrawLine(p, drawRow, 0, drawRow, 240);19 drawRow += 32;20 }21 }
其次是 当鼠标在panel 上移动的时候 也要触发一个事件 ,用来显示当前移动到哪个单元格上了 ,那么 贴上代码
1 private void panel1_MouseMove(object sender, MouseEventArgs e)2 {3 int x = e.X / 32;//当前坐标的x坐标,除以32 是因为那些 小方格是以32*24 大小的4 int y = e.Y / 24;//当前坐标的x坐标5 label1.Text = "第" + x + "×" + y + "个矩形 " + "坐标为:(" + e.X + "," + e.Y + ")";6 7 }
还有 鼠标移动到某个小方格上的鼠标点击事件
1 public Color[] mycolor = new Color[] { Color.Black, Color.Brown }; 2 public Point mypoint; 3 public Pen mypen = new Pen(Brushes.Black); 4 private void panel1_MouseClick(object sender, MouseEventArgs e) 5 { 6 if (e.Button == MouseButtons.Left) 7 { 8 Graphics g = this.panel1.CreateGraphics(); 9 GraphicsPath gp = new GraphicsPath();10 int x = (e.X / 32) * 32;11 int y = (e.Y / 24) * 24;12 a[x / 32, y / 24] = 0;13 Rectangle rec = new Rectangle(new Point(x, y), new Size(32, 24));14 gp.AddRectangle(rec);15 SolidBrush pb = new SolidBrush(Color.Red);16 pb.Color = Color.Red;17 g.DrawRectangle(mypen, rec);18 g.FillPath(pb, gp);19 }20 else21 {22 Graphics g = this.panel1.CreateGraphics();23 GraphicsPath gp = new GraphicsPath();24 int x = (e.X / 32) * 32;25 int y = (e.Y / 24) * 24;26 a[x / 32, y / 24] = 1;27 Rectangle rec = new Rectangle(new Point(x, y), new Size(32, 24));28 gp.AddRectangle(rec);29 SolidBrush pb = new SolidBrush(Color.Green);30 pb.Color = Color.Green;31 g.DrawRectangle(mypen, rec);32 g.FillPath(pb, gp);33 }34 }
还有 打开一个新的 背景, 只需要单机打开新的地图按钮
1 private void button1_Click(object sender, EventArgs e)2 {3 openFileDialog1.ShowDialog();4 panel1.BackgroundImage = Image.FromFile(openFileDialog1.FileName);5 }
点击保存按钮,保存对应地图的地图状态信息。
1 private void button2_Click(object sender, EventArgs e) 2 { 3 4 SaveFileDialog sfd = new SaveFileDialog(); 5 sfd.Filter = "(*.txt)|*.txt|(*.*)|*.*"; 6 sfd.AddExtension = true; 7 sfd.RestoreDirectory = true; 8 if (sfd.ShowDialog() == DialogResult.OK) 9 {10 FileStream fs = new FileStream(sfd.FileName, FileMode.Create);11 StreamWriter sw = new StreamWriter(fs);12 try13 {14 StringBuilder sb = new StringBuilder();15 for (int i = 0; i <= 9; i++)16 {17 for (int j = 0; j <=9; j++)18 {19 sb.Append(i+" ");20 sb.Append(j + " ");21 sb.AppendLine(a[i,j] + " ");22 }23 }24 sw.Write(sb.ToString());25 sw.Flush();26 }27 catch (Exception ex)28 {29 MessageBox.Show(ex.Message.ToString());30 }31 finally32 {33 sw.Close();34 fs.Close();35 }36 }37 38 39 }
总结起来 这个地图编辑器是非常简单的,他只是实现了地图基础数据的整合,但是就是这样一个简单的小工具,却能省去大量的时间。一般一张地图五分钟,总共设计这样一个游戏的地图时间在半个小时就能搞定。 那个下面就上传,地图包和地图编辑器工具。仅供大家参考。其实我的成长,也有你们的帮助。我会努力把这个项目讲完的。
http://pan.baidu.com/share/link?shareid=3075606904&uk=1345361952
http://pan.baidu.com/share/link?shareid=3107346913&uk=1345361952
<script type="text/javascript"><!--google_ad_client = "ca-pub-1944176156128447";/* cnblogs 首页横幅 */google_ad_slot = "5419468456";google_ad_width = 728;google_ad_height = 90;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
- 梦幻之旅
- 开启梦幻般的webrtc之旅
- 开启梦幻般webrtc之旅
- 开启梦幻般的webrtc之旅
- 开启梦幻般的webrtc之旅
- 开启梦幻般的webrtc之旅
- 开启梦幻般的webrtc之旅
- 开启梦幻般的webrtc之旅
- 开启梦幻般的webrtc之旅
- 开启梦幻般的webrtc之旅
- NYOJ C : zqw的梦幻之旅
- WV梦幻之旅国际俱乐部 --WV梦幻之旅奖金制度剖析
- 梦幻成仙,诛灭外挂——《梦幻诛仙手游》的阻击外挂之旅
- 梦幻之旅--深入大规模芯片设计全过程
- Windows Mobile 7(Photon) 梦幻之旅系列-前言
- Eclipse开启你的J2ME的梦幻之旅。
- 《高原之旅》之一《回望青海湖》1梦幻西行
- 『HTML5梦幻之旅』 - 动感圆圈
- HDU 4627 The Unsolvable Problem 解题报告
- 迪杰斯特拉算法
- 系统运维技巧(一)——chattr和lsattr命令
- 屌丝职场记
- 用JavaScript玩转游戏编程(一)掉宝类型概率
- 梦幻之旅
- 点菜
- linux终端中输出彩色字体
- UVA11538Chess Queen
- 为什么要注册窗口
- 次小生成树 倍增 LCA
- ASP.NET MVC实现仪表程序
- The Hound of the Baskervilles——12、The Man on the Moor
- 使用U-boot安装openwrt镜像(wr703n)