Repository navigation
Expand file tree
/
Copy pathItem.cpp
More file actions
70 lines (58 loc) · 1.42 KB
/
Copy pathItem.cpp
File metadata and controls
70 lines (58 loc) · 1.42 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "Item.h"
using namespace std;
void Item::addTotalItem() {
total_item++;
}
void Item::minusTotalItem() {
total_item--;
}
Item::Item() {
total_item = 0;
}
void Item::produceItem() {
if (total_item < 3) {
int newItem =0;
if (rand() % 3 == 0){ //rand()%3 은 0,1,2 중 하나임
newItem = 8;
}else{
newItem = (rand() % 2) + 5;
}
clock_t now = clock();
int y = rand() % MAP_SIZE;
int x = rand() % MAP_SIZE;
if (map[y][x] == 0) {
map[y][x] = newItem;
total_item++;
for (int i = 0; i < 3; i++) {
if (iv[i].y == -1) {
iv[i].y = y;
iv[i].x = x;
iv[i].time = now;
break;
}
}
}
}
}
void Item::removeItem(int y, int x) {
if (total_item > 0) {
for (int i = 0; i < 3; i++) {
if (iv[i].y == y && iv[i].x == x) {
iv[i].y = -1;
total_item--;
}
}
}
}
void Item::removeItem() {
if (total_item > 0) {
clock_t now = clock();
for (int i = 0; i < 3; i++) {
if ((float(now - iv[i].time) / CLOCKS_PER_SEC > 5) && (iv[i].y > 0)) {
map[iv[i].y][iv[i].x] = 0;
iv[i].y = -1;
total_item--;
}
}
}
}