-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevent.cpp
More file actions
44 lines (37 loc) · 916 Bytes
/
event.cpp
File metadata and controls
44 lines (37 loc) · 916 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <iostream>
#include <deque>
#include <algorithm>
#include "event.h"
using namespace std;
deque<Event *> *Event::events;
GrassLand *Event::land;
Event::Event() {
if (!events) {
events = new deque<Event *>;
}
events->push_back(this);
}
int Event::selfProcess() {
cout << "update|cells|";
int size = land->size * land->size;
for (int k = 0; k < size; k++) {
land->g[k].growGrass();
cout << land->g[k].getGrassLevel() << ";";
}
// this needed to make queue more randomized;
random_shuffle(events->begin(), events->end());
cout << endl;
}
void Event::setGrassland(GrassLand *l) {
Event::land = l;
}
void Event::processNext() {
Event *e = Event::events->front();
Event::events->pop_front();
if (e->selfProcess() != 1) {
Event::events->push_back(e);
}
}
GrassLand *Event::getGrassland() {
return Event::land;
}