用C#开发智能手机软件:推箱子(七)

2007-10-15 10:49:27 来源:博客园 作者:银河 点击:
在上篇文章“使用 C# 开发智能手机软件:推箱子(六)”中,我对Common/Pub.cs 源程序文件进行了介绍。在这篇文章中介绍 Common/Step.cs 源程序文件。



  在上篇文章“使用 C# 开发智能手机软件推箱子(六)”中,我对Common/Pub.cs 源程序文件进行了介绍。在这篇文章中介绍 Common/Step.cs 源程序文件。

以下是引用片段:
  1namespace Skyiv.Ben.PushBox.Common
  2{
  3 enum Direction { None, East, South, West, North } // 方向: 无 东 南 西 北
  4 public enum Action { None, Create, Edit, Delete } // 设计: 无 创建 编辑 删除
  5
  6 /**//// 
  7 /// 走法步骤
  8 /// 
  9 struct Step
  10 {
  11 Direction direct; // 前进方向
  12 bool isBox; // 是否推着箱子一起前进
  13 bool isStop; // “撤销”时是否停留
  14
  15 public Direction Direct { get { return direct; } }
  16 public bool IsBox { get { return isBox; } }
  17 public bool IsStop { get { return isStop; } }
  18
  19 public Step(Direction direct, bool isBox, bool isStop)
  20 {
  21 this.direct = direct;
  22 this.isBox = isBox;
  23 this.isStop = isStop;
  24 }
  25
  26 // isBox isStop None East South West North
  27 // A B C D E
  28 // x F G H I J
  29 // x K L M N O
  30 // x x P Q R S T
  31
  32 public static implicit operator char(Step step)
  33 {
  34 char c = "ABCDE"[step.direct - Direction.None];
  35 if (step.isBox) c = (char)(c + 5);
  36 if (step.isStop) c = (char)(c + 10);
  37 return c;
  38 }
  39
  40 public static implicit operator Step(char c)
  41 {
  42 int n = c - 'A';
  43 return new Step((Direction)(n % 5), (n % 10 >= 5), (n >= 10));
  44 }
  45 }
  46}

  这个源程序文件中包含两个枚举(Direction 和 Action) 和一个结构(Step)的定义。

  枚举 Direction 用来表示工人和箱子移动的方向,

9 7 3 1 2 4 8 :


本类最新行业评测技巧教程学院
本类热点本日本周本月
本类推荐本日本周本月
广告信息

广告联系 | 版权说明 | 意见建议 | 加入收藏 | 军网站群 [ 军软件园 - 军软件商城 - 军软件园论坛 ]

电信与信息服务业务经营许可证:京ICP证050203