29 The Power of Inheritance and Polymorphism
29 The Power of Inheritance and Polymorphism
29 The Power of Inheritance and Polymorphism
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Implementation: class Dungeon 1051}cout MAXHEIGHT)) {cout ch;while(ch != 'q') {switch(ch) {case 'h':if(fPlayer != NULL) {cout Read(in);fInhabitants.Append(m);break;case 'g':m = new Ghost(this);m->Read(in);fInhabitants.Append(m);break;case 'p':m = new Patrol(this);m->Read(in);fInhabitants.Append(m);break;case '*':case '=':case '$':Collectable *prop = new Collectable(this, ch);prop->Read(in);fProps.Append(prop);Create Player objectCreate differentspecialized MonsterobjectsCreate Collectableitems