D_MOBILE *get_char(D_MOBILE * ch, char *argument) { D_MOBILE *wch; ITERATOR *pIter; char arg[MIL]; // char buf[MSL]; pIter = AllocIterator(dmobile_list); while ((wch = (D_MOBILE *) NextInList(pIter)) != NULL) { if (wch == ch) continue; else if (str_cmp(arg,wch->name)) return wch; else return NULL; } FreeIterator(pIter); return NULL; }
void do_movement(D_MOBILE *dMob, int dir) { D_MOBILE *xMob; ITERATOR *pIter; bool leftr = FALSE; pIter = AllocIterator(dmobile_list); while ((xMob = (D_MOBILE *) NextInList(pIter)) != NULL) { if (xMob == dMob) continue; if ((dMob->coordx != xMob->coordx) && (dMob->coordz != xMob->coordz) && (dMob->coordy != xMob->coordy)) leftr = TRUE; } switch (dir) { case NORTH: /* North */ stcf(dMob, "You leave for the north.\n\r"); dMob->coordy++; break; case SOUTH: /* South */ stcf(dMob, "You leave for the south.\n\r"); dMob->coordy--; break; case EAST: /* East */ stcf(dMob, "You head eastward.\n\r"); dMob->coordx++; break; case WEST: /* West */ stcf(dMob, "You head westward.\n\r"); dMob->coordx--; break; case UP: /* Up */ stcf(dMob, "You fly upwards.\n\r"); dMob->coordz++; break; case DOWN: /* Down */ stcf(dMob, "You you head downwards.\n\r"); dMob->coordz--; break; case NORTHEAST: /* NorthEast */ dMob->coordy++; dMob->coordx++; break; case SOUTHEAST: /* SouthEast */ dMob->coordy--; dMob->coordx++; break; case SOUTHWEST: /* SouthWest */ dMob->coordy--; dMob->coordx--; break; case NORTHWEST: /* NorthWest */ dMob->coordy++; dMob->coordx--; break; } if (dMob->coordx > HI_XLIMIT) { dMob->coordx--; text_to_mobile(dMob, "You can't move there!\n\r"); return; } if (dMob->coordy > HI_YLIMIT) { dMob->coordy--; text_to_mobile(dMob, "You can't move there!\n\r"); return; } if (dMob->coordz > HI_ZLIMIT) { dMob->coordz--; text_to_mobile(dMob, "You can't move there!\n\r"); return; } if (dMob->coordx < LO_XLIMIT) { dMob->coordx++; text_to_mobile(dMob, "You can't move there!\n\r"); return; } if (dMob->coordy < LO_YLIMIT) { dMob->coordy++; text_to_mobile(dMob, "You can't move there!\n\r"); return; } if (dMob->coordz < LO_ZLIMIT) { dMob->coordz++; text_to_mobile(dMob, "You can't move there!\n\r"); return; } if (leftr) stcf(xMob, "%s has left the room.\n\r",dMob->name); cmd_look(dMob, NULL); return; }
int main(int argc, char** argv) { TREE pTree = AllocTree(NULL); void *pContents; ITERATOR pIter; int nChoice = 0, nKey; while (nChoice != -1) { printf("1: Insert\n"); printf("2: Remove\n"); printf("3: Print\n"); printf("4: Print all keys\n"); printf("5: Print all keys reverse\n"); printf("6: Mass insert\n"); printf("7: Mass remove\n"); printf("Else: Quit\n\n"); BTSCAN("%d", &nChoice); switch(nChoice) { case 1: printf("Key: "); BTSCAN("%d", &nKey); Insert(nKey, "temp", pTree); break; case 2: printf("Key: "); BTSCAN("%d", &nKey); Remove(nKey, pTree); break; case 3: printf("Key: " ); BTSCAN("%d", &nKey); pContents = Search(nKey, pTree); if (pContents != NULL) { printf("Contents: %s\n", pContents); } else { printf("Not found\n"); } break; case 4: pIter = AllocIterator(); Attach(pIter, pTree); while ((pContents = Next(pIter)) != NULL) { printf("Contents: %d\n", pContents); } Detach(pIter); FreeIterator(pIter); break; case 5: pIter = AllocIterator(); AttachEnd(pIter, pTree); while ((pContents = Next(pIter)) != NULL) { printf("Contents: %d\n", pContents); } Detach(pIter); FreeIterator(pIter); break; case 6: for (nKey = 100; nKey > 0; nKey--) { Insert(nKey, "temp", pTree); } break; case 7: for (nKey = 100; nKey > 0; nKey--) { Remove(nKey, pTree); } break; default: nChoice = -1; break; } printf("\n"); } return 0; }