예제 #1
0
void Player::displayInventory() {
  if (!creature->isHumanoid()) {
    model->getView()->presentText("", "You can't use inventory.");
    return;
  }
  if (creature->getEquipment().isEmpty()) {
    model->getView()->presentText("", "Your inventory is empty.");
    return;
  }
  vector<Item*> item = chooseItem("Inventory:", alwaysTrue<const Item*>(), ActionId::SHOW_INVENTORY);
  if (item.size() == 0) {
    return;
  }
  vector<View::ListElem> options;
  if (creature->canEquip(item[0], nullptr)) {
    options.push_back("equip");
  }
  if (creature->canApplyItem(item[0])) {
    options.push_back("apply");
  }
  if (creature->canUnequip(item[0], nullptr))
    options.push_back("remove");
  else {
    options.push_back("throw");
    options.push_back("drop");
  }
  auto index = model->getView()->chooseFromList("What to do with " + getPluralName(item[0], item.size()) + "?", options);
  if (!index) {
    displayInventory();
    return;
  }
  if (options[*index].getText() == "drop") {
    creature->privateMessage("You drop " + getPluralName(item[0], item.size()));
    creature->drop(item);
  }
  if (options[*index].getText() == "throw") {
    throwItem(item);
  }
  if (options[*index].getText() == "apply") {
    applyItem(item);
  }
  if (options[*index].getText() == "remove") {
    creature->privateMessage("You remove " + getPluralName(item[0], item.size()));
    creature->unequip(getOnlyElement(item));
  }
  if (options[*index].getText() == "equip") {
    creature->privateMessage("You equip " + getPluralName(item[0], item.size()));
    creature->equip(item[0]);
  }
}
예제 #2
0
void testRange2() {
  vector<int> a;
  const vector<int> b {6,5,4,3,2,1,0};
  for (int x : Range(6, -1))
    a.push_back(x);
  CHECKEQ(a, b);
  a.clear();
  for (int x : Range(4, 0))
    a.push_back(x);
  CHECKEQ(getSubsequence(b, 2, 4), a);
  a.clear();
  for (int x : All(b)) {
    a.push_back(b[x]);
  }
  CHECKEQ(a, b);
  a.clear();
  for (int x : Range(4, 4))
    a.push_back(x);
  a.clear();
  for (int x : Range(4, 3))
    a.push_back(x);
  CHECK(getOnlyElement(a) == 4);
}