void LField::Sync() { if (((GetCond() > 3) && (GetCond() < 7)) || ((GetCond() > 11) && (GetCond() < 15))) { GetPlant()->kurangiUmur(1); if (IsSiram()) { GetPlant()->tambahHappyMeter(1); } } Siram = 0; }
/// Print power plant market info void CardStack::PrintInfo() { std::cout << std::endl; std::cout << "Current plants: " << std::endl; for (int i = 0; i < futureMarketIndex; i++) std::cout << "[" << i << "] " << *GetPlant(i) << std::endl; std::cout << std::endl; std::cout << "Future plants: " << std::endl; for (int i = futureMarketIndex; i < visibleCards; i++) std::cout << "[" << i << "] " << *GetPlant(i) << std::endl; std::cout << std:: endl; }
Fruit* Orchard::GetBestFruit(int i, int j, int *fruitID) { //goes to DS and gets Fruit with lowest ripe rating, min is 1. if (!legalInput(i, j)) { throw InvalidInput(); } Plant* plant = GetPlant(i, j); return plant->GetBestFruit(); }
void Orchard::RemoveFruit(int fruitID) { if (!legalFruitID(fruitID)) { throw InvalidInput(); } //we need to remove from both DS's try { Fruit* fruit = GetFruit(fruitID); Plant* plant = GetPlant(fruit->getLocation().msi, fruit->getLocation().lsi); plant->RemoveFruit(fruitID); // deleting the fruit Fruits.Remove(fruitID); //delete fruit; } catch (KeyDoesNotExist& e) { throw Failure(); } }
void Orchard::AddFruit(int i, int j, Fruit* fruit) { if (!fruit) { throw InvalidInput(); } if (!legalInput(i, j)) { throw InvalidInput(); } //we need to add to both DS's if (!DoesExist(i, j)) throw PlantDoesNotExist(); if (DoesExist(fruit->getID())) throw FruitAlreadyExist(); fruit->setLocation(PairID(i, j)); Plant* temp = GetPlant(i, j); temp->AddFruit(fruit); Fruits.Insert(fruit->getID(), fruit); }
void Orchard::RateFruit(int id, int ripeness) { if (id < 0 || ripeness <= 0) { throw InvalidInput(); } //we need to add to both DS's try { Fruit* fruit = GetFruit(id); Plant* plant = GetPlant(fruit->getLocation().msi, fruit->getLocation().lsi); Fruit* copy = new Fruit(*fruit); copy->setRipeRate(ripeness); plant->RemoveFruit(id); plant->AddFruit(copy); Fruits.Remove(id); Fruits.Insert(id, copy); } catch (KeyDoesNotExist& e) { throw Failure(); } }
// TODO: delete void* Orchard::GetAllFruitsByRate(int i, int j, int **fruits, int *numOfFruits) { return GetPlant(i, j)->GetAllFruitsByRate(); }