看动画

This commit is contained in:
w-mj committed 2017-12-25 15:25:45 +08:00
1 parent 76280e2025
commit aa0868d50d
4 files changed
+27 -9

No files matched your search

+15 -2
View File
@@ -57,6 +57,10 @@ ParkingLotManager::ParkingLotManager(QObject* objectParent, QGraphicsScene* scen
generatePool(true);
Adapter *adapter = new Adapter(objectParent, &m_all_cars); // 注册model
CarList::getInstance()->setAdapter(adapter);
QTimer *timer = new QTimer(this);
connect(timer, &QTimer::timeout, this, &ParkingLotManager::periodWork);
timer->start(1000); // 轮询
}
void ParkingLotManager::showParkingLot(uint pos)
@@ -227,8 +231,6 @@ void ParkingLotManager::addCar(int entry)
if (entry == -1)
entry = (rand() % m_num_of_entry);
entry = 0;
Car *car = new Car(this);
car->setEntryNum(entry + 1);
m_waitting[entry].append(car);
@@ -281,3 +283,14 @@ void ParkingLotManager::generatePool(bool sequence)
std::random_shuffle(m_pool.begin(), m_pool.end());
Log::i(QString("生成车位池成功,当前共有") + QString::number(m_pool.size()) + "个空车位");
}
void ParkingLotManager::periodWork()
{
int generateProbability = 80;
if (rand() % 100 + 1 < generateProbability)
addCar();
for (auto c: m_all_cars) {
if (c->getStatus() == Car::parking)
c->leaveProbability(2);
}
}