コード例 #1
0
int InventoryController::launch(Character &character) {
	//Juste display the inventory until you press I, Escape or Close
	inventoryScreen.display(character);
	GameInput input = this->inventoryScreen.recupInput();
	while (input.getValue() != I_INPUT) {
		if (input.getValue() == ESCAPE_INPUT)
			return I_INPUT;
		if (input.getValue() == CLOSE_INPUT)
			return input.getValue();
		input = this->inventoryScreen.recupInput();
	}
	return input.getValue();
}
コード例 #2
0
int SessionController::launch(Character &character, Interface &interface) {
	//Initialization
	Map map = SaveUtils::loadMap(character.getName(), character.getMap());
	SessionScreen sessionScreen;
	character.checkView(map);
	sessionScreen.display(character, interface, map);
	GameInput input;
	//Game Loop
	while (input.getValue() != CLOSE_INPUT) {
		//To know if we have to count the current turn.
		bool played = false;
		//To know if we have to refresh the screen.
		bool toRefresh = true;
		//To know if the player have changed his position.
		bool moved = false;
		input = sessionScreen.recupInput();
		switch (input.getValue()) {
			moved = false;
			//Quit Game
			case ESCAPE_INPUT : {
				interface.write("Return to the menu (y or n)?");
				sessionScreen.display(character, interface, map);
				GameInput tmpInput;
				int tmpValue;
				do {
					tmpInput = sessionScreen.recupInput();
					tmpValue = tmpInput.getValue();
				} while ((tmpValue != N_INPUT) && (tmpValue != Y_INPUT));
				if (tmpValue == N_INPUT)
					interface.write("Okay then.");
				else {
					SaveUtils::save(character, interface);
					SaveUtils::saveMap(character.getName(), character.getMap(), map);
					return TO_MAIN_MENU;
				}
				break;
			}
			//Display Map
			case M_INPUT : {
				MapController mapController(map, character);
				input.setValue(mapController.launch(map, character));
				break;
			}
			//Display Inventory
			case I_INPUT : {
				InventoryController inventoryController;
				input.setValue(inventoryController.launch(character));
				break;
			}
			//Pick Item
			case P_INPUT : {
				/*if (map.cell[character.getX()][character.getY()].drops.empty())
					interface.write("There's nothing here.");
				else {
					//character.equipement.legs = &map.cell[character.getX()][character.getY()].drops.front();
				}*/
				break;
			}
			//Change map
			case Q_INPUT : {
				if (changeMap(character, map, interface)) {
					SaveUtils::save(character, interface);
					return REDO;
				}
				else
					interface.write("You cannot exit from here !");
				break;
			}
			//Moving inputs
			case UP_INPUT : {
				moved = character.move(0,-1,map);
				played = true;
				break;
			}
			case DOWN_INPUT : {
				moved = character.move(0,1,map);
				played = true;
				break;
			}
			case RIGHT_INPUT : {
				moved = character.move(1,0,map);
				played = true;
				break;
			}
			case LEFT_INPUT : {
				moved = character.move(-1,0,map);
				played = true;
				break;
			}
			default:
				toRefresh = false;
		}
		if (moved) {
			interface.showItems(map.cell[character.getX()][character.getY()]);
			interface.showDestination(map.cell[character.getX()][character.getY()]);
		}
		if (played) {
			map.refreshCells(character.getX(), character.getY());
			character.checkView(map);
		}
		if (toRefresh)
			sessionScreen.display(character, interface, map);
	}
	SaveUtils::save(character, interface);
	SaveUtils::saveMap(character.getName(), character.getMap(), map);
	return CLOSE_INPUT;
}