static void Main(string[] args) { IgoChessman black1, black2, black3, white1, white2; IgoChessmanFactory factory; //获取享元工厂对象 // factory = IgoChessmanFactory.getInstance(); //通过享元工厂获取三颗黑子 black1 = IgoChessmanFactory.getIgoChessman("b"); black2 = IgoChessmanFactory.getIgoChessman("b"); black3 = IgoChessmanFactory.getIgoChessman("b"); Console.WriteLine("判断两颗黑子是否相同:" + (black1 == black2)); //通过享元工厂获取两颗白子 white1 = IgoChessmanFactory.getIgoChessman("w"); white2 = IgoChessmanFactory.getIgoChessman("w"); Console.WriteLine("判断两颗白子是否相同:" + (white1 == white2)); //显示棋子 black1.display(); black2.display(); black3.display(); white1.display(); white2.display(); //显示棋子,同时设置棋子的坐标位置 black1.display(new Coordinates(1, 2)); black2.display(new Coordinates(3, 4)); black3.display(new Coordinates(1, 3)); white1.display(new Coordinates(2, 5)); white2.display(new Coordinates(2, 4)); Console.Read(); }
static void Main(string[] args) { // 获取享元工厂 IgoChessmanFactory chessFactory = IgoChessmanFactory.GetInstance(); // 通过享元工厂获取3颗黑子 IgoChessman blackChess1 = chessFactory.GetIgoChessman("b"); IgoChessman blackChess2 = chessFactory.GetIgoChessman("b"); IgoChessman blackChess3 = chessFactory.GetIgoChessman("b"); Console.WriteLine("判断两颗黑子是否相同:{0}", object.ReferenceEquals(blackChess1, blackChess2)); // 通过享元工厂获取2颗白子 IgoChessman whiteChess1 = chessFactory.GetIgoChessman("w"); IgoChessman whiteChess2 = chessFactory.GetIgoChessman("w"); Console.WriteLine("判断两颗白子是否相同:{0}", object.ReferenceEquals(whiteChess1, whiteChess2)); // 显示棋子 blackChess1.Display(new Coordinates(1, 2)); blackChess2.Display(new Coordinates(3, 4)); blackChess3.Display(new Coordinates(1, 3)); whiteChess1.Display(new Coordinates(2, 5)); whiteChess2.Display(new Coordinates(2, 4)); Console.ReadKey(); }