#include <iostream>using namespacestd;enumDirection {n, East, South, West,};classMapSite { Public: Virtual voidEnter () =0;};class: PublicMapSite { Public: (intRoomno): _roomnumber (Roomno) {}; MapSite*getside (Direction)Const; Virtual voidSetside (Direction Direction, MapSite *) {cout<<"Set the"<<_roomnumber<<" the"<<direction<<"side."<<Endl; }; intGetroomno () {return_roomnumber; }; Virtual voidEnter () {cout<<"Enter the hostel."<<Endl; };Private: MapSite*_sides[4]; int_roomnumber;};classBombroom: PublicThe hostel { Public: Bombroom (intnum): Guest (num) {_roomnum=num; }; Virtual voidSetside (Direction Direction, MapSite *) {cout<<"Set the"<<_roomnum<<"Bomb"<<direction<<"side."<<Endl; };Private: int_roomnum;};classWall: PublicMapSite { Public: Wall () {}; Virtual voidEnter () {cout<<"Enter the wall."<<Endl; };};classDoor: PublicMapSite { Public: Door (* =0, room* =0) {}; Virtual voidEnter () {cout<<"Enter the door."<<Endl; }; the*othersidefrom (room*) {};Private: the*_room1; the*_room2; BOOL_isopen;};classMaze { Public: Maze () {}; voidAddroom (room*Guest) {cout<<"Add the"<< Room->getroomno () <<"."<<Endl; }; the* ROOMNO (int)Const{};};classMazefactory { Public: Mazefactory () {}; Virtualmaze* Makemaze ()Const { return NewMaze; }; Virtualwall* Makewall ()Const { return NewWall; }; Virtualroom* Makeroom (intNConst { return New(n); }; Virtualdoor* Makedoor (room* R1, room* R2)Const { return NewDoor (R1, r2); };};classBombmazefactory: PublicMazefactory { Public: Virtualroom* Makeroom (intNConst { return Newbombroom (n); };};classMazegame { Public: Maze* Createmaze (Mazefactory &Factory) {Maze* Amaze =Factory. Makemaze (); the* R1 = factory. Makeroom (1); the* R2 = factory. Makeroom (2); Door* Thedoor =Factory. Makedoor (R1, r2); Amaze-Addroom (R1); Amaze-Addroom (R2); R1-Setside (North, Factory. Makewall ()); R1-setside (East, Thedoor); R1-Setside (South, Factory. Makewall ()); R1-Setside (West, factory. Makewall ()); R2-Setside (North, Factory. Makewall ()); R2-Setside (East, factory. Makewall ()); R2-Setside (South, Factory. Makewall ()); R2-setside (West, Thedoor); returnAmaze; };};intMain () {Mazegame mygame; //Mazefactory Factory;Bombmazefactory Factory; Mygame. Createmaze (Factory); System ("Pause"); return 0;}
View Code
Add Bomb Room Maze Factory mode modification has been compiled