lab2
程序员文章站
2022-07-12 17:02:54
...
-
在ZorkUL.h文件中设置vector型room变量,存储类型为room *指针型,为了和房间号匹配
vector<Room *> room;
-
新建房间 ,并且把房间号存入room数组中,使用push_back函数;
-
修改房间相关变量,走向和地图
void ZorkUL::createRooms() { Room *a, *b, *c, *d, *e, *f, *g, *h, *i,*j,*k; a = new Room("a"); a->addItem(new Item("x", 1, 11)); a->addItem(new Item("y", 2, 22)); b = new Room("b"); b->addItem(new Item("xx", 3, 33)); b->addItem(new Item("yy", 4, 44)); c = new Room("c"); d = new Room("d"); e = new Room("e"); f = new Room("f"); g = new Room("g"); h = new Room("h"); i = new Room("i"); j = new Room("j"); j->addItem(new Item("xxx",111, 111)); j->addItem(new Item("yyy",222, 222)); k = new Room("k"); // (N, E, S, W) a->setExits(f, b, d, c); b->setExits(NULL, NULL, NULL, a); c->setExits(NULL, a, NULL, NULL); d->setExits(a, e, j, i); e->setExits(NULL, NULL, NULL, d); f->setExits(NULL, g, a, h); g->setExits(NULL, NULL, NULL, f); h->setExits(NULL, f, NULL, NULL); i->setExits(NULL, d, NULL, NULL); j->setExits(d, k, NULL, NULL); k->setExits(NULL, NULL, NULL, j); room.push_back(a); room.push_back(b); room.push_back(c); room.push_back(d); room.push_back(e); room.push_back(f); room.push_back(g); room.push_back(h); room.push_back(i); room.push_back(j); room.push_back(k); currentRoom = a; }
- 添加teleport命令,修改currentroom的值,使用random函数随机生成房间号下标,跳转到随机房间
CommandWords::CommandWords() {
// Populate the vector if we haven't already.
if (validCommands.empty()) {
validCommands.push_back("go");
validCommands.push_back("quit");
validCommands.push_back("info");
validCommands.push_back("map");
validCommands.push_back("take");
validCommands.push_back("put");
validCommands.push_back("teleport");
}
}
else if(commandWord.compare("teleport") == 0){
int r=rand()%11;
currentRoom=room[r];
cout << currentRoom->longDescription() << endl;
}
上一篇: 事务处理
下一篇: Hibernate中的事务处理流程详解