-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMapCoder.cpp
More file actions
115 lines (108 loc) · 2.99 KB
/
Copy pathMapCoder.cpp
File metadata and controls
115 lines (108 loc) · 2.99 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include <list>
#include <iostream>
#include <sstream>
#include "object.h"
#include "buff.cpp"
#include "rolling_wall.h"
#include "wall.cpp"
#include "shortwall.cpp"
#include "midwall.cpp"
#include "movableblock.cpp"
#include "tank.h"
#include "triangle.h"
#ifndef MAPCODER_CPP
#define MAPCODER_CPP
namespace MapCoder {
/*
ID|X|Y|Direction|SpecialArg
*/
struct Point {
double x, y,dir;
};
struct Map {
std::list<object*> objs;
std::list<Point> spawns;
};
std::string encode(Map m) {
std::ostringstream oss("");
oss << m.objs.size() + m.spawns.size() << '\n';
for (auto i = m.objs.begin(); i != m.objs.end(); i++) {
if (wall* p = dynamic_cast<wall*>(*i)) {
oss << 1 << ' ' << p->get_x() << ' ' << p->get_y() << ' ' << p->get_direction() << '\n';
}
else if (rolling_wall* p = dynamic_cast<rolling_wall*>(*i)) {
oss << 2 << ' ' << p->get_x() << ' ' << p->get_y() << ' ' << p->get_direction()<<' ' << p->rolling_speed << '\n';
}
else if (buff* p = dynamic_cast<buff*>(*i)) {
oss << 3 << ' ' << p->get_x() << ' ' << p->get_y() << ' ' << p->get_direction()<<' ' << p->buff_state << '\n';
}
else if (shortwall* p = dynamic_cast<shortwall*>(*i)) {
oss << 10 << ' ' << p->get_x() << ' ' << p->get_y() << ' ' << p->get_direction() << '\n';
}
else if (midwall* p = dynamic_cast<midwall*>(*i)) {
oss << 11 << ' ' << p->get_x() << ' ' << p->get_y() << ' ' << p->get_direction() << '\n';
}
else if (movableblock* p = dynamic_cast<movableblock*>(*i)) {
oss << 12 << ' ' << p->get_x() << ' ' << p->get_y() << ' ' << p->get_direction() << '\n';
}
else if (triangle* p = dynamic_cast<triangle*>(*i)) {
oss << 13 << ' ' << p->get_x() << ' ' << p->get_y() << ' ' << p->get_direction() << ' ' << p->rolling_speed << '\n';
}
}
for (auto i = m.spawns.begin(); i != m.spawns.end(); i++) {
oss << 4 << ' ' << i->x << ' ' << i->y << ' ' << i->dir << '\n';
}
return oss.str();
}
Map decode(std::string code) {
std::istringstream iss(code);
Map ret;
int n = 0, id;
double x, y, dir, sa;
iss >> n;
while (n--) {
iss >> id;
switch (id)
{
case 1:
iss >> x >> y >> dir;
ret.objs.push_back(new wall(x, y, dir));
break;
case 2:
iss >> x >> y >> dir >> sa;
ret.objs.push_back(new rolling_wall(x, y, dir, sa));
break;
case 3:
iss >> x >> y >> dir >> sa;
ret.objs.push_back(new buff(x, y, dir, sa));
break;
case 4:
iss >> x >> y >> dir;
Point t;
t.x = x, t.y = y, t.dir = dir;
ret.spawns.push_back(t);
break;
case 10:
iss >> x >> y >> dir;
ret.objs.push_back(new shortwall(x, y, dir));
break;
case 11:
iss >> x >> y >> dir;
ret.objs.push_back(new midwall(x, y, dir));
break;
case 12:
iss >> x >> y >> dir;
ret.objs.push_back(new movableblock(x, y, dir));
break;
case 13:
iss >> x >> y >> dir >> sa;
ret.objs.push_back(new triangle(x, y, dir, sa));
break;
default:
break;
}
}
return ret;
}
}
#endif // !MAPDECODER_CPP