Stone.cs
资源名称:Visual.rar [点击查看]
上传用户:yiyuerguo
上传日期:2014-09-27
资源大小:3781k
文件大小:1k
源码类别:
C#编程
开发平台:
Others
- using System;
- using System.Drawing;
- namespace FiveStones
- {
- /// <summary>
- /// Stone(棋子类) 的摘要说明。
- /// 提供棋子相关的属性,方法,事件
- /// </summary>
- public class Stone
- {
- private Graphics mg;
- //从文件获取
- private Image imgBlackStone; //黑子图片
- private Image imgWhiteStone; //白子图片
- public Stone(Graphics g)
- {
- //读取黑子,白子图片
- //从资源中获取
- System.Reflection.Assembly thisExe;
- thisExe = System.Reflection.Assembly.GetExecutingAssembly();
- System.IO.Stream wfile = thisExe.GetManifestResourceStream("FiveStones.whitestone.gif");
- System.IO.Stream bfile = thisExe.GetManifestResourceStream("FiveStones.blackstone.gif");
- imgBlackStone = System.Drawing.Image.FromStream(bfile);
- imgWhiteStone = System.Drawing.Image.FromStream(wfile);
- bfile.Close();
- wfile.Close();
- //从文件获取
- //imgBlackStone = System.Drawing.Image.FromFile("blackstone.gif"); //黑子图片
- //imgWhiteStone = System.Drawing.Image.FromFile("whitestone.gif"); //白子图片
- mg = g;
- }
- /// <summary>
- /// 绘制棋子
- /// </summary>
- /// <param name="m"></param>
- /// <param name="n"></param>
- /// <param name="flag">判断是黑棋(true)还是白棋(false)</param>
- public void DrawStone(int m,int n,bool flag)
- {
- if (flag)
- {
- mg.DrawImage(imgBlackStone,m*40,n*40,imgBlackStone.Width,imgBlackStone.Height);
- }
- else
- {
- mg.DrawImage(imgWhiteStone,m*40,n*40,imgWhiteStone.Width,imgWhiteStone.Height);
- }
- }
- }
- }