用C#开发智能手机软件:推箱子(七)2011-05-08在上篇文章“”中,我对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}