Esempio n. 1
0
Store* City::robStore() {
	REQUIRE(properlyInitialized(), "Object 'City' was not properly properlyInitializedialized when calling robStore()");

	bool success = false;
	Store* ptr;
	int loops = 0;

	while (!success) {
		std::list<Store>::iterator it = stores.begin();
		int randomInt = rand()% stores.size();
		for (int i = 0; i < randomInt; i++) {
			it++;
		}

		ptr = &(*it);
		if (ptr->getState() == normal) {
			success = true;
		}
		if (loops == 100){
			return NULL;
		}
		loops++;
	}

	ptr->setState(beingrobbed);

	ENSURE(ptr->getState() == beingrobbed, "robStore() did not cause a robbery.");

	return ptr;
}
Esempio n. 2
0
Store* City::robStore(int x, int y){
	REQUIRE(properlyInitialized(), "Object 'City' was not properly properlyInitializedialized when calling robStore(int, int)");

	CityObjects* ptr;
	ptr = matrix.getObject(x, y);
	Store* storeptr = dynamic_cast<Store*>(ptr);
	if (storeptr->getState() != normal || storeptr->getType() != store){
		return NULL;
	}

	storeptr->setState(beingrobbed);

	ENSURE(storeptr->getState() == beingrobbed, "setFire() did not correctly set fire to the given house.");

	return storeptr;
}