第9月第6天 push pop动画 生成器模式(BUILDER)
1.
https://github.com/MichaelHuyp/QQNews
2.生成器模式(BUILDER)
class MazeBuilder { public: virtual void BuildMaze() {} virtual void BuildRoom(int room) {} virtual void BuildDoor(int roomFrom, int roomTo) {} virtual Maze* GetMaze() { return 0;} protected: MazeBuilder(); } class StandardMazeBuilder : public MazeBuilder { public: StandardMazeBuilder(); /* */ virtual void BuildMaze(); virtual void BuildRoom(int); virtual void BuildDoor(int, int); /* */ virtual Maze* GetMaze(); private: Direction CommonWall(Room*, Room*); Maze* _currentMaze; };//StandardMazeBuilder是ConcreteBuilder,提供部件的具体构造代码 Maze* MazeGame::CreateMaze (MazeBuilder& builder) { builder.BuildMaze(); builder.BuildRoom(1); builder.BuildRoom(2); builder.BuildDoor(1, 2); return builder.GetMaze(); }//CreateMaze是导向器,调用生成器的抽象接口完成产品的构造过程。 //下面代码描述产品的构造过程 Maze* maze;//最终的产品 MazeGame game;//Director,导航者 StandardMazeBuilder builder;//ConcreteBuilder,实际的构造类 game.CreateMaze(builder);//开始装配 maze = builder.GetMaze();//获取装配后的产品
http://blog.csdn.net/zs634134578/article/details/17853433
StandardMazeBuilder::StandardMazeBuilder() : m_currentMaze(0) { } void StandardMazeBuilder::BuildMaze() { m_currentMaze = new Maze(); } void StandardMazeBuilder::BuildRoom(int roomNo) { if (m_currentMaze->RoomNo(roomNo) == NULL) { Room *room = new Room(roomNo); room->SetSide(Room::East, new Wall()); room->SetSide(Room::South, new Wall()); room->SetSide(Room::West, new Wall()); room->SetSide(Room::North, new Wall()); m_currentMaze->AddRoom(room); } } void StandardMazeBuilder::BuildDoor(int roomFrom, int roomTo) { Room *r1 = m_currentMaze->RoomNo(roomFrom); Room *r2 = m_currentMaze->RoomNo(roomTo); Door *door = new Door(r1, r2); r1->SetSide(CommononWall(r1, r2), door); r2->SetSide(CommononWall(r2, r1), door); } Room::Direction StandardMazeBuilder::CommononWall(Room *from, Room *to) { }
https://github.com/e5MaxSpace/DesignPatterns