网络版多人扫雷游戏开发手记(一)

就在前天,玩SINA的连连看时突然想到,是不是能把经典的扫雷游戏也做成类似的呢,
呵呵,当然这是可能的(前提是我能坚持到把这个做完),因此就开始了这个程序的制作,
到今天为止基本已经把单人游戏的60%做出来了,
 

在这阶段中经历了两个不同处理版本
一种是用Lable做控制单元
第二种是直接用Image画上去,然后再处理各种事件,

就代码处理上来讲,第一种明显比第二种要方便的多,但问题是其处理效率太低,
而第二种则处理效率大大提高,只不过在代码上要处理的稍稍麻烦一点,

在已经完程的过程中发现一个不容易查觉的问题,也可能是我第一次用GDI+吧,
即在Grapics.DrawImage方法上的不同

DrawImage(System.Drawing.Image, System.Drawing.Point[])

方法,在系统画图的时候会将图片尺寸自动调整到物理大小,
引自MSDN:
This method draws an image using its physical size, so the image will have its correct size in inches regardless of the resolution (dots per inch) of the display device. For example, suppose an image has a pixel width of 216 and a horizontal resolution of 72 dots per inch. If you call this method to draw that image on a device that has a resolution of 96 dots per inch, the pixel width of the rendered image will be (216/72)*96 = 288.
由于这样我因为为这个问题搞了一个晚上,直到看到MSDN上的这段话,呵呵,
但下面的这方法则没有这个问题,只不过我觉得如果用下面这个方法在别的地方会不会有些不方便呢?目前还没有发现,但心里总有点不是滋味。。。

DrawImage(System.Drawing.Image image, System.Drawing.Point[] destPoints, System.Drawing.Rectangle srcRect, System.Drawing.GraphicsUnit srcUnit);


在做此程序的过程中还测试了一下事件处理顺序,(第一次这种在C#中这么做当然要先试一把,嘿嘿,别笑我
我在类中有几个事件是内部封装的,通过测试可以看出事件处理过程还是先处理外部过程,再处理类内的过程

      Control.FromHandle(_ctrl).MouseDown +=MouseDownProc;
      Control.FromHandle(_ctrl).MouseUp 
+= MouseUpProc;
      Control.FromHandle(_ctrl).MouseMove 
+= MouseMoveProc;
      Control.FromHandle(_ctrl).Paint
+=new PaintEventHandler(PaintProc);

 上面的代码是将指定控件的几个事件引入到自己的类中进行处理,

要比较完美的做完这个东西,还要解决网络处理上的问题,这个对我来说又是一个新区域,做起来可能有点头痛。。。


这次小结就到这里,over~~

原文地址:https://www.cnblogs.com/pvistely/p/77660.html