回答編集履歴

2

編集終了

2018/05/12 15:52

投稿

asm
asm

スコア15147

test CHANGED
@@ -1 +1,141 @@
1
+ 自殺するオブジェクトが自分が住んでるビルをハードコーディングして部屋ごと爆破するのは
2
+
3
+ なんというか迷惑な気がする。
4
+
5
+
6
+
7
+ 案1. 死体掃除業者を呼ぶ
8
+
9
+
10
+
11
+ ```c++
12
+
13
+ #include<iostream>
14
+
15
+ #include<list>
16
+
17
+
18
+
19
+ class cEnemy {
20
+
21
+ bool alive = true;
22
+
23
+ public:
24
+
25
+ bool isAlive() const;
26
+
27
+ void F();
28
+
29
+ };
30
+
31
+
32
+
33
+ std::list<cEnemy> TestList;
34
+
35
+
36
+
1
- 途中送信してしまいました
37
+ int main() {
38
+
39
+ TestList.push_back(cEnemy());
40
+
41
+ TestList.push_back(cEnemy());
42
+
43
+ TestList.push_back(cEnemy());
44
+
45
+
46
+
47
+ for (auto IT = TestList.begin(); IT != TestList.end(); IT++) {
48
+
49
+ IT->F(); // 殺す
50
+
51
+ }
52
+
53
+ std::cout << TestList.size() << std::endl;
54
+
55
+ // お片付け
56
+
57
+ TestList.remove_if([](const cEnemy& e){return !e.isAlive();});
58
+
59
+ std::cout << TestList.size() << std::endl;
60
+
61
+ return 0;
62
+
63
+ }
64
+
65
+
66
+
67
+ void cEnemy::F() {
68
+
69
+ //画面外に出たら、殺す
70
+
71
+ if (true) {
72
+
73
+ alive = false; // 死にました
74
+
75
+ }
76
+
77
+ }
78
+
79
+ bool cEnemy::isAlive() const{return alive;}
80
+
81
+ ```
82
+
83
+
84
+
85
+ 案2. ビル(list)に管理人を雇ってそいつに命令する。
86
+
87
+ ```c++
88
+
89
+ class cEnemy {
90
+
91
+ bool alive = true;
92
+
93
+ public:
94
+
95
+ bool isAlive() const;
96
+
97
+ bool F();
98
+
99
+ };
100
+
101
+
102
+
103
+ class cEnemyManager {
104
+
105
+ public:
106
+
107
+ std::list<cEnemy> TestList;
108
+
109
+ void remove_if_F();
110
+
111
+ }
112
+
113
+
114
+
115
+ void cEnemyManager::remove_if_F(){
116
+
117
+ TestList.remove_if(
118
+
119
+ [](cEnemy& e){return e.F();}
120
+
121
+ );
122
+
123
+ }
124
+
125
+ bool cEnemy::F() {
126
+
127
+ //画面外に出たら、殺す
128
+
129
+ if (true) {
130
+
131
+ alive = false; // 死にました
132
+
133
+ return true;
134
+
135
+ }
136
+
137
+ return false;
138
+
139
+ }
140
+
141
+ ```

1

途中

2018/05/12 15:52

投稿

asm
asm

スコア15147

test CHANGED
@@ -1,61 +1 @@
1
- ```c++
2
-
3
- #include<iostream>
4
-
5
- #include<list>
6
-
7
-
8
-
9
- class cEnemy {
10
-
11
- bool isAlive = true;
12
-
13
- public:
14
-
15
- void F();
16
-
17
- };
18
-
19
-
20
-
21
- std::list<cEnemy> TestList;
22
-
23
-
24
-
25
- int main() {
1
+ 途中送信してしまいました
26
-
27
- TestList.push_back(cEnemy());
28
-
29
- TestList.push_back(cEnemy());
30
-
31
- TestList.push_back(cEnemy());
32
-
33
-
34
-
35
- for (auto IT = TestList.begin(); IT != TestList.end(); IT++) {
36
-
37
- IT->F();
38
-
39
- }
40
-
41
- TestList.remove_if([](const auto& e){return !e.isAlive;});
42
-
43
- return 0;
44
-
45
- }
46
-
47
-
48
-
49
- void cEnemy::F() {
50
-
51
- //画面外に出たら、殺す
52
-
53
- if (true) {
54
-
55
- isAlive = false;
56
-
57
- }
58
-
59
- }
60
-
61
- ```