Ejemplo n.º 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]);
  }
}
Ejemplo n.º 2
0
void graphics_display(building_st* buildArr, int selX, int selY, inventory_st* inv)
{
	werase(win);	
	for (int i = 0; i < GRID_SIZE_X; i++){
		for (int j = 0; j < GRID_SIZE_Y; j++){	
			int index = (i*GRID_SIZE_Y)+j;	
			if(buildArr[index].exist)
				drawBuilding(&(buildArr[index]));
		}
	}
	mvwprintw(win, 1+selY*(GRID_SCALE_Y), 1+(selX*GRID_SCALE_X), "*");
	wrefresh(win);

	//TODO: if updated inv included in entity list update tempInv
	tempInv = inv;
	displayInventory();
}
Ejemplo n.º 3
0
void Player::makeMove() {
  vector<Vec2> squareDirs = creature->getConstSquare()->getTravelDir();
  const vector<Creature*>& creatures = creature->getLevel()->getAllCreatures();
  if (creature->isAffected(Creature::HALLU))
    ViewObject::setHallu(true);
  else
    ViewObject::setHallu(false);
  MEASURE(
      model->getView()->refreshView(creature),
      "level render time");
  if (Options::getValue(OptionId::HINTS) && displayTravelInfo && creature->getConstSquare()->getName() == "road") {
    model->getView()->presentText("", "Use ctrl + arrows to travel quickly on roads and corridors.");
    displayTravelInfo = false;
  }
  static bool greeting = false;
  if (Options::getValue(OptionId::HINTS) && displayGreeting) {
    CHECK(creature->getFirstName());
    model->getView()->presentText("", "Dear " + *creature->getFirstName() + ",\n \n \tIf you are reading this letter, then you have arrived in the valley of " + NameGenerator::worldNames.getNext() + ". There is a band of dwarves dwelling in caves under a mountain. Find them, talk to them, they will help you. Let your sword guide you.\n \n \nYours, " + NameGenerator::firstNames.getNext() + "\n \nPS.: Beware the goblins!");
    model->getView()->presentText("", "Every settlement that you find has a leader, and they may have quests for you."
        "\n \nYou can turn these messages off in the options (press F2).");
    displayGreeting = false;
    model->getView()->refreshView(creature);
  }
  for (const Creature* c : creature->getVisibleEnemies()) {
    if (c->isSpecialMonster() && !contains(specialCreatures, c)) {
      privateMessage(MessageBuffer::important(c->getDescription()));
      model->getView()->refreshView(creature);
      specialCreatures.push_back(c);
    }
  }
  if (travelling)
    travelAction();
  else if (target)
    targetAction();
  else {
    Action action = model->getView()->getAction();
  vector<Vec2> direction;
  bool travel = false;
  switch (action.getId()) {
    case ActionId::FIRE: fireAction(action.getDirection()); break;
    case ActionId::TRAVEL: travel = true;
    case ActionId::MOVE: direction.push_back(action.getDirection()); break;
    case ActionId::MOVE_TO: if (action.getDirection().dist8(creature->getPosition()) == 1) {
                              Vec2 dir = action.getDirection() - creature->getPosition();
                              if (const Creature* c = creature->getConstSquare(dir)->getCreature()) {
                                if (!creature->isEnemy(c)) {
                                  chatAction(dir);
                                  break;
                                }
                              }
                              direction.push_back(dir);
                            } else
                            if (action.getDirection() != creature->getPosition()) {
                              target = action.getDirection();
                              target = Vec2(min(creature->getLevel()->getBounds().getKX() - 1, max(0, target->x)),
                                  min(creature->getLevel()->getBounds().getKY() - 1, max(0, target->y)));
                              // Just in case
                              if (!target->inRectangle(creature->getLevel()->getBounds()))
                                target = Nothing();
                            }
                            else
                              pickUpAction(false);
                            break;
    case ActionId::SHOW_INVENTORY: displayInventory(); break;
    case ActionId::PICK_UP: pickUpAction(false); break;
    case ActionId::EXT_PICK_UP: pickUpAction(true); break;
    case ActionId::DROP: dropAction(false); break;
    case ActionId::EXT_DROP: dropAction(true); break;
    case ActionId::WAIT: creature->wait(); break;
    case ActionId::APPLY_ITEM: applyAction(); break; 
    case ActionId::THROW: throwAction(); break;
    case ActionId::THROW_DIR: throwAction(action.getDirection()); break;
    case ActionId::EQUIPMENT: equipmentAction(); break;
    case ActionId::HIDE: hideAction(); break;
    case ActionId::PAY_DEBT: payDebtAction(); break;
    case ActionId::CHAT: chatAction(); break;
    case ActionId::SHOW_HISTORY: messageBuffer.showHistory(); break;
    case ActionId::UNPOSSESS: if (creature->canPopController()) {
                                creature->popController();
                                return;
                              } break;
    case ActionId::CAST_SPELL: spellAction(); break;
    case ActionId::DRAW_LEVEL_MAP: model->getView()->drawLevelMap(creature); break;
    case ActionId::EXIT: model->exitAction(); break;
    case ActionId::IDLE: break;
  }
  if (creature->isAffected(Creature::SLEEP) && creature->canPopController()) {
    if (model->getView()->yesOrNoPrompt("You fell asleep. Do you want to leave your minion?"))
      creature->popController();
    return;
  }
  for (Vec2 dir : direction)
    if (travel) {
      vector<Vec2> squareDirs = creature->getConstSquare()->getTravelDir();
      if (findElement(squareDirs, dir)) {
        travelDir = dir;
        lastLocation = creature->getLevel()->getLocation(creature->getPosition());
        travelling = true;
        travelAction();
      }
    } else
    if (creature->canMove(dir)) {
      creature->move(dir);
      itemsMessage();
      break;
    } else {
      const Creature *c = creature->getConstSquare(dir)->getCreature();
      if (creature->canBumpInto(dir)) {
        creature->bumpInto(dir);
        break;
      } else 
      if (creature->canDestroy(dir)) {
        privateMessage("You bash the " + creature->getSquare(dir)->getName());
        creature->destroy(dir);
        break;
      }
    }
  }
  for (Vec2 pos : creature->getLevel()->getVisibleTiles(creature)) {
    ViewIndex index = creature->getLevel()->getSquare(pos)->getViewIndex(creature);
    (*levelMemory)[creature->getLevel()].clearSquare(pos);
    for (ViewLayer l : { ViewLayer::ITEM, ViewLayer::FLOOR_BACKGROUND, ViewLayer::FLOOR, ViewLayer::LARGE_ITEM})
      if (index.hasObject(l))
        remember(pos, index.getObject(l));
  }
}
Ejemplo n.º 4
0
// @author Andre Allan Ponce
// @author Computergeek01
// url: http://www.cplusplus.com/forum/beginner/75529/
void Game::getKeyInput(WORD key, Location* currRoom){
	switch(key)
    {
	case VK_ESCAPE:{
		break;
	}
    case VK_LEFT:
	case VK_NUMPAD4:{
		activeText = "left!\n";
		movePlayer(MOVE_LEFT, currRoom);
		break;
	}
	case VK_UP:
	case VK_NUMPAD8:{
		activeText = "up!\n";
		movePlayer(MOVE_UP, currRoom);
		break;
	}
	case VK_RIGHT:
	case VK_NUMPAD6:{
		activeText =  "right!\n";
		movePlayer(MOVE_RIGHT, currRoom);
		break;
	}
	case VK_DOWN:
	case VK_NUMPAD2:{
		activeText =  "down!\n";
		movePlayer(MOVE_DOWN, currRoom);
		break;
	}
	case 0x41: // a key // this was steve
		{
			activeText = "ea \n";
			int i = 0;
			int id = detectItemID();
			if(id >= 0){
				Item* thisItem = retrieveItem(id);
				thisItem->setDescription(itemData.getItemDesc(id));
				thisItem->action();
				int check = 0;
				while(check == 0 && i<8)
				{
					activeText = "orb\n";
					int run = rand()%orbProb[i];
					cout << run;
					if( run == 1)
					{
						orbInventory[i] = true;
						updateOrbProbability();
						check++;
					}
				i++;
				}
			}
			break;
		}


			
	case 0x49: // this was steve as well
		{
			displayInventory();
			break;

		}
	default :{
		// we dont move.
		break;
	}
    } 
}
Ejemplo n.º 5
0
//main function
int main()
{
	//set up the game	
	Room SupplyRoom;
	SupplyRoom.filename = "SupplyRoom.txt";
	Room HallA;
	HallA.filename = "HallwayA.txt";
	Room HallB;
	HallB.filename = "HallwayB.txt";
	Room BoxRoom;
	BoxRoom.filename = "BoxRoom.txt";
	Room CatRoom;
	CatRoom.filename = "CatRoom.txt";
	Room ParrotRoom;
	ParrotRoom.filename = "ParrotRoom.txt";
	Room Foyer;
	Foyer.filename = "Foyer.txt";
	//set up the interactive objects
	Container Parrot;
	if (Parrot.bContainsItem == true)
	{
		Parrot.filename = "Parrot.txt";
	}
	else
	{
		Parrot.filename = "ParrotEmpty.txt";
	}
	Container Cat;
	if (Cat.bContainsItem == true)
	{
		Cat.filename = "Cat.txt";
	}
	else
	{
		Cat.filename = "CatEmpty.txt";
	}
	Container Box;
	if (Box.bContainsItem == true)
	{
		Box.filename = "Box.txt";
	}
	else
	{
		Box.filename = "BoxEmpty.txt";
	}
	Container Trash;
	if (Trash.bContainsItem == true)
	{
		Trash.filename = "Trash.txt";
	}
	else
	{
		Trash.filename = "TrashEmpty.txt";
	}
	Container Computer;
	if (Computer.bContainsItem == true)
	{
		Computer.filename = "Computer.txt";
	}
	else
	{
		Computer.filename = "ComputerEmpty.txt";
	}

	if (bGameStart == true)
	{
		system("cls");

		std::fstream fMyFile;

		fMyFile.open("Opening.txt", std::ios::in);
		if (fMyFile.is_open())
		{
			std::cout << fMyFile.rdbuf();
			fMyFile.close();
			fMyFile.clear();
		}
		system("pause");
		displayMenu();
		bGameStart = false;
		SupplyRoom.bActive = true;
		bGameOn = true;
	}
	//START IN SUPPLY ROOM
	
	//START GAME LOOP
	while (bGameOn == true)
	{
		//while games active MENU, INV, INSTRUCTIONS
		
		//SUPPLY ROOM
		while (SupplyRoom.bActive == true)
		{
			system("cls");
			SupplyRoom.DisplayDescription();
			GetInput();
			//can only go NORTH in supply room
			if (command == moveNorth)
			{
				SupplyRoom.bActive = false;
				HallA.bActive = true;
			}	
			else if (command == "inv")
			{
				displayInventory();
			}
			else if (command == "menu")
			{
				displayMenu();
			}
			else 
			{
				std::cout << "Sorry, I didn't understand that." << std::endl;
				system("pause");
			}
		
		}
		//if HALL A active
		while (HallA.bActive == true)
		{
			system("cls");
			HallA.DisplayDescription();
			GetInput();
			//can go NORTH, SOUTH, WEST in HallA & trash
			if (command == moveNorth)
			{
				HallA.bActive = false;
				CatRoom.bActive = true;
			}
			else if (command == moveSouth)
			{
				HallA.bActive = false;
				SupplyRoom.bActive = true;
			}
			else if (command == moveWest)
			{
				HallA.bActive = false;
				HallB.bActive = true;
			}
			else if (command == "look trash")
			{
				HallA.bActive = false;
				Trash.bActive = true;
			}
			else if (command == "inv")
			{
				displayInventory();
			}
			else if (command == "menu")
			{
				displayMenu();
			}
			else
			{
				std::cout << "Sorry, I didn't understand that." << std::endl;
				system("pause");
			}
		}
		//while HALLB active
		while (HallB.bActive == true)
		{
			system("cls");
			HallB.DisplayDescription();
			GetInput();
			//can go N, S, E, W
			if (command == moveNorth)
			{
				HallB.bActive = false;
				BoxRoom.bActive = true;
			}
			else if (command == moveSouth)
			{
				HallB.bActive = false;
				ParrotRoom.bActive = true;
			}
			else if (command == moveEast)
			{
				HallB.bActive = false;
				HallA.bActive = true;
			}
			else if (command == moveWest)
			{
				HallB.bActive = false;
				Foyer.bActive = true;
			}
			else if (command == "inv")
			{
				displayInventory();
			}
			else if (command == "menu")
			{
				displayMenu();
			}
			else
			{
				std::cout << "Sorry, I didn't understand that." << std::endl;
				system("pause");
			}
		}
		//while in CAT ROOM
		while (CatRoom.bActive == true)
		{
			system("cls");
			CatRoom.DisplayDescription();
			GetInput();
			//can only go S and cat
			if (command == "look cat")
			{
				CatRoom.bActive = false;
				Cat.bActive = true;
			}
			else if (command == moveSouth)
			{
				CatRoom.bActive = false;
				HallA.bActive = true;
			}
			else if (command == "inv")
			{
				displayInventory();
			}
			else if (command == "menu")
			{
				displayMenu();
			}
			else
			{
				std::cout << "Sorry, I didn't understand that." << std::endl;
				system("pause");
			}
		}
		//while in BOX ROOM
		while (BoxRoom.bActive == true)
		{
			system("cls");
			BoxRoom.DisplayDescription();
			GetInput();
			//can only go S and box
			if (command == "look box")
			{
				BoxRoom.bActive = false;
				Box.bActive = true;
			}
			else if (command == moveSouth)
			{
				BoxRoom.bActive = false;
				HallB.bActive = true;
			}
			else if (command == "inv")
			{
				displayInventory();
			}
			else if (command == "menu")
			{
				displayMenu();
			}
			else
			{
				std::cout << "Sorry, I didn't understand that." << std::endl;
				system("pause");
			}
		}
		//while in PARROT ROOM
		while (ParrotRoom.bActive == true)
		{
			system("cls");
			ParrotRoom.DisplayDescription();
			GetInput();
			//can only go N and PARROT
			if (command == moveNorth)
			{
				ParrotRoom.bActive = false;
				HallB.bActive = true;
			}
			else if (command == "look parrot")
			{
				ParrotRoom.bActive = false;
				Parrot.bActive = true;
			}
			else if (command == "inv")
			{
				displayInventory();
			}
			else if (command == "menu")
			{
				displayMenu();
			}
			else
			{
				std::cout << "Sorry, I didn't understand that." << std::endl;
				system("pause");
			}
			

		}
		//while in FOYER
		while (Foyer.bActive == true)
		{
			system("cls");
			Foyer.DisplayDescription();
			GetInput();
			//only go E, comp, exit
			if (command == "look computer")
			{
				Foyer.bActive = false;
				Computer.bActive = true;
			}
			else if (command == moveEast)
			{
				Foyer.bActive = false;
				HallB.bActive = true;
			}
			else if (command == "inv")
			{
				displayInventory();
			}
			else if (command == "menu")
			{
				displayMenu();
			}
			else
			{
				std::cout << "Sorry, I didn't understand that." << std::endl;
				system("pause");
			}
		}

		//containers trash cat parrot box
		while (Trash.bActive == true)
		{
			system("cls");
			Trash.DisplayDescription();
			GetInput();
			//interact with mirror, walk north south west
			if (command == "use mirror" || 
				command == "get mirror" ||
				command == "look mirror")
			{
				system("cls");
				std::cout << "You pick up the MIRROR. It is now in your INV." << std::endl;
				system("pause");
				Trash.bContainsItem = false;
				Trash.filename = "TrashEmpty.txt";
				Inv.bMirror = true;
			}
			else if (command == moveNorth)
			{
				Trash.bActive = false;
				CatRoom.bActive = true;
			}
			else if (command == moveSouth)
			{
				Trash.bActive = false;
				SupplyRoom.bActive = true;
			}
			else if (command == moveWest)
			{
				Trash.bActive = false;
				HallB.bActive = true;
			}
			else if (command == "inv")
			{
				displayInventory();
			}
			else if (command == "menu")
			{
				displayMenu();
			}
			else
			{
				std::cout << "Sorry, I didn't understand that." << std::endl;
				system("pause");
			}
		}
		//while PARROT active
		while (Parrot.bActive == true)
		{
			system("cls");
			Parrot.DisplayDescription();
			GetInput();
			//can only move north and interact with parrot
			if (Parrot.bContainsItem == true &&
				command == "use mirror")
			{
				system("cls");
				std::cout << "You give the MIRROR to the PARROT. He is particularly enamoured with his reflection. The brass KEY clatters to the floor. You decide to keep the KEY. The KEY is now in your INV." << std::endl;
				system("pause");
				Inv.bMirror = false;
				Parrot.bContainsItem = false;
				Parrot.filename = "ParrotEmpty.txt";
				Inv.bKey = true;
			}
			else if (command == moveNorth)
			{
				Parrot.bActive = false;
				HallB.bActive = true;
			}
			else if (command == "inv")
			{
				displayInventory();
			}
			else if (command == "menu")
			{
				displayMenu();
			}
			else
			{
				std::cout << "Sorry, I didn't understand that." << std::endl;
				system("pause");
			}
		}
		//while BOX active
		while (Box.bActive == true)
		{
			system("cls");
			Box.DisplayDescription();
			GetInput();
			//open box, move south
			if (Box.bContainsItem == true && command == "use key")
			{
				system("cls");
				std::cout << "You use the KEY in the keyhole. It fits perfectly. As you feel the lock click open, the KEY disintegrates in your hand. The BOX swings open. There is a small KITTEN in the box. You decide to take it. The KITTEN is now in your INV." << std::endl;
				system("pause");
				Inv.bKey = false;
				Box.bContainsItem = false;
				Box.filename = "BoxEmpty.txt";
				Inv.bKitten = true;
			}
			else if (command == moveSouth)
			{
				Box.bActive = false;
				HallB.bActive = true;
			}
			else if (command == "inv")
			{
				displayInventory();
			}
			else if (command == "menu")
			{
				displayMenu();
			}
			else
			{
				std::cout << "Sorry, I didn't understand that." << std::endl;
				system("pause");
			}
		}
		//WHILE CAT ACTIVE
		while (Cat.bActive == true)
		{
			system("cls");
			Cat.DisplayDescription();
			GetInput();
			//move south, give cat kitten
			if (Cat.bContainsItem == true && 
				command == "use kitten")
			{
				system("cls");
				std::cout << "You pull the KITTEN out of your INV. The CAT immediately ceases screaming. You slowly place the KITTEN next to the CAT. The CAT gets up and moves to the KITTEN, giggling intensely." << std::endl;
				std::cout << "There is an ID CARD where the CAT used to be. You decide to keep it. The ID CARD is now in your INV." << std::endl;
				system("pause");
				Inv.bKitten = false;
				Cat.bContainsItem = false;
				Cat.filename = "CatEmpty.txt";
				Inv.bIdCard = true;
			}
			else if (command == moveSouth)
			{
				Cat.bActive = false;
				HallA.bActive = true;
			}
			else if (command == "inv")
			{
				displayInventory();
			}
			else if (command == "menu")
			{
				displayMenu();
			}
			else
			{
				std::cout << "Sorry, I didn't understand that." << std::endl;
				system("pause");
			}
		}
		while (Computer.bActive == true)
		{
			system("cls");
			Computer.DisplayDescription();
			GetInput();
			//move south, give cat kitten
			if (Computer.bContainsItem == true &&
				command == "use id card" ||
				command == "use idcard")
			{
				system("cls");
				std::cout << "You swipe the ID CARD. The COMPUTER switches to the login screen." << std::endl;
				system("pause");
				Computer.bContainsItem = false;
				Computer.filename = "ComputerEmpty.txt";
			}
			else if (command == moveEast)
			{
				Computer.bActive = false;
				HallB.bActive = true;
			}
			else if (command == "inv")
			{
				displayInventory();
			}
			else if (command == "menu")
			{
				displayMenu();
			}
			else if (Computer.bContainsItem == false &&
				command == "error")
			{
				//uwin
				system("cls");
				std::cout << "You heave a sigh of relief as the computer boots up, and the only application \"DOOR UNLOCK\" becomes available. You double click with anticipation. Slowly, but surely, the automatic glass doors slide open and you are finally free to go HOME." << std::endl;
				system("pause");
				Computer.bActive = false;
				bGameOn = false;
				//return 0;
				bGameOver = true;
			}
			else
			{
				std::cout << "Sorry, I didn't understand that." << std::endl;
				system("pause");
			}
		}
		while (bGameOver == true)
		{
			system("cls");
			std::fstream fMyFile;
			fMyFile.open("Closing.txt", std::ios::in);
			if (fMyFile.is_open())
			{
				std::cout << fMyFile.rdbuf();
				fMyFile.close();
				fMyFile.clear();
			}
			system("pause");
			return 0;
		}
	}
	
	return 0;
}