質問編集履歴

5

コードのデバッグを掲載

2020/07/25 02:24

投稿

ryamamot0
ryamamot0

スコア3

test CHANGED
File without changes
test CHANGED
@@ -327,3 +327,7 @@
327
327
 
328
328
 
329
329
  ```
330
+
331
+
332
+
333
+ ![コードのデバック](7323db551ce84119ce26ad82aee47859.png)

4

コードの修正

2020/07/25 02:24

投稿

ryamamot0
ryamamot0

スコア3

test CHANGED
File without changes
test CHANGED
@@ -58,14 +58,24 @@
58
58
 
59
59
  //MemoryMatchGame.h
60
60
 
61
+
62
+
61
63
  #include <iostream>
62
64
 
63
65
  #include <vector>
64
66
 
65
67
  #include <string>
66
68
 
69
+ #include <random>
70
+
71
+ #include <numeric>
72
+
73
+ #include <cassert>
74
+
67
75
  #include <time.h>
68
76
 
77
+ #include <iomanip>
78
+
69
79
  using namespace std;
70
80
 
71
81
 
@@ -168,6 +178,8 @@
168
178
 
169
179
  //ここでshuffleArrの中身はシャッフルされる
170
180
 
181
+ /*
182
+
171
183
  for (int i = 50; i > 1; --i)
172
184
 
173
185
  {
@@ -186,6 +198,8 @@
186
198
 
187
199
  }
188
200
 
201
+ */
202
+
189
203
  //tmpArrで1次元配列を作成する
190
204
 
191
205
  int tmpArr[randomNum];
@@ -202,6 +216,64 @@
202
216
 
203
217
  //cout << element[tmpArr[i]]でstring elementを呼び出す(後で書く)
204
218
 
219
+
220
+
221
+
222
+
223
+ assert( gridSize*gridSize % 2 == 0 );
224
+
225
+ int num = gridSize * gridSize / 2;
226
+
227
+ int* data = new int[num*2];
228
+
229
+ // 「0~num-1 で埋める」を二回やって
230
+
231
+ iota(data, data+num, 0);
232
+
233
+ iota(data+num, data+num*2, 0);
234
+
235
+ // かきまぜる
236
+
237
+ for (int i = 50; i > 1; --i)
238
+
239
+ {
240
+
241
+ int a = i-1;
242
+
243
+ int b = rand()%i;
244
+
245
+ //change shuffleArr[a] and ShuffleArr[b]
246
+
247
+ int tmp = shuffleArr[a];
248
+
249
+ shuffleArr[a] = shuffleArr[b];
250
+
251
+ shuffleArr[b] = tmp;
252
+
253
+ }
254
+
255
+
256
+
257
+
258
+
259
+ for (int r = 0; r < gridSize; ++r)
260
+
261
+ {
262
+
263
+ for (int c = 0; c < gridSize; ++c)
264
+
265
+ {
266
+
267
+ cout << gridArr[r][c] << ' ';
268
+
269
+ }
270
+
271
+ cout << endl;
272
+
273
+ }
274
+
275
+
276
+
205
277
 
206
278
 
207
279
  //gridを作成している
@@ -252,4 +324,6 @@
252
324
 
253
325
  };
254
326
 
327
+
328
+
255
329
  ```

3

コードを変更

2020/07/25 02:22

投稿

ryamamot0
ryamamot0

スコア3

test CHANGED
File without changes
test CHANGED
@@ -56,6 +56,8 @@
56
56
 
57
57
  ```C++
58
58
 
59
+ //MemoryMatchGame.h
60
+
59
61
  #include <iostream>
60
62
 
61
63
  #include <vector>
@@ -80,55 +82,71 @@
80
82
 
81
83
  int timer;
82
84
 
83
- string element[50] = {"H","He","Li","Be","B","C","N","O","F","Ne","Na","Mg","Al","Si","P","S","Cl","Ar","K","Ca","Sc","Ti","V","Cr","Mn","Fe","Co","Ni","Cu","Zn","Ga","Ge","As","Se","Br","Kr","Rb","Sr","Y","Zr","Nb","Mo","Tc","Ru","Rh","Pd","Ag","Cd","In","Sn"};
85
+ string element[50] = {"H","He","Li","Be","B","C","N","O","F","Ne","Na","Mg","Al","Si","P","S","Cl","Ar","K","Ca","Sc","Ti","V","Cr","Mn","Fe","Co","Ni","Cu","Zn","Ga","Ge","As","Se","Br","Kr","Rb","Sr","Y","Zr","Nb","Mo","Tc","Ru","Rh","Pd","Ag","Cd","In","Sn"};
84
86
 
85
87
  string fruits[50] = {"grape","apple","tangerine","satsuma","strawberry","pear","apricot","lime","orange","cantaloupe","jujube","papaya","fig","banana","honeydew","cherry","mango","kiwi","tomato","huckleberry","boysenberry","nectarine","grapefruit","pomegranate","passon_fruit","coconut","clementine","date","starfruit","peach","plum","blackberry","kumquat","guava","dragonfruit","raspberry","watermelon","pineapple","blueberry","avocado","lemon"};
86
88
 
87
- string candy[50] = {"Almond Joy","Cotton candy","Atomic Fireball","Twizzlers","Nik-L-Nips","Jawbreakers","Red Vines","Snickers","Junior Mints","Werther's Original","Smarties,Gummi Worms","Pixie Stix","Gummi Bears","Tootsie Rolls","Blow Pops","Peeps","Tootsie Roll Pops","Hershey Bar","Sour Patch Kids","Necco wafers","Three Musketeers","York Peppermint Patties","Candy corn","Butterfinger","Baby Ruth","Kit-Kat","Pocky","Jelly Belly","Jolly Ranchers","Mr. Goodbar","Nerds","Sugar Daddy","Swedish Fish","M&Ms","Toblerone","Circus peanuts","Skittles","Pop Rocks","Reese's pieces","Candy cigarettes","Twix","Milky Way","Milk Duds","Wax lips","Hershey's Kisses","Cadbury eggs","Starburst","Payday","Reese's Peanut Butter Cups"}; void start(){
88
-
89
- cout << "グリッドサイズを洗濯して下さい:" << endl;
90
-
91
- cout << "4*4をプレイしたい場合は4を入力して下さい" << endl;
92
-
93
- cout << "6*6をプレイしたい場合は6を入力して下さい" << endl;
94
-
95
- cout << "8*8をプレイしたい場合は8を入力して下さい" << endl;
96
-
97
- cout << "選んでください: ";
98
-
99
- cin >> gridsize;
89
+ string candy[50] = {"Almond Joy","Cotton candy","Atomic Fireball","Twizzlers","Nik-L-Nips","Jawbreakers","Red Vines","Snickers","Junior Mints","Werther's Original","Smarties,Gummi Worms","Pixie Stix","Gummi Bears","Tootsie Rolls","Blow Pops","Peeps","Tootsie Roll Pops","Hershey Bar","Sour Patch Kids","Necco wafers","Three Musketeers","York Peppermint Patties","Candy corn","Butterfinger","Baby Ruth","Kit-Kat","Pocky","Jelly Belly","Jolly Ranchers","Mr. Goodbar","Nerds","Sugar Daddy","Swedish Fish","M&Ms","Toblerone","Circus peanuts","Skittles","Pop Rocks","Reese's pieces","Candy cigarettes","Twix","Milky Way","Milk Duds","Wax lips","Hershey's Kisses","Cadbury eggs","Starburst","Payday","Reese's Peanut Butter Cups"};
90
+
91
+ public:
92
+
93
+ void start(){
94
+
95
+ cout << "Please choose grid size:" << endl;
96
+
97
+ cout << "If you want to play 4*4 grid size, press 4" << endl;
98
+
99
+ cout << "If you want to play 6*6 grid size, press 6" << endl;
100
+
101
+ cout << "If you want to play 8*8 grid size, press 8" << endl;
102
+
103
+ cout << "You choose: ";
104
+
105
+ cin >> gridSize;
100
106
 
101
107
  cout << "<---------------------->" << endl;
102
108
 
103
- cout << "テーマを選択して下さい:" << endl;
109
+ cout << "Please choose theme:" << endl;
110
+
104
-
111
+ cout << "If you want to play element, press 1" << endl;
112
+
105
- cout << "元素に関してプレイしたい場合,1を押してください" << endl;
113
+ cout << "If you want to play fruits, press 2" << endl;
106
-
107
- cout << "果物に関してプレイしたい場合,2を押してください" << endl;
114
+
108
-
109
- cout << "お菓子に関してプレイしたい場合,3を押してください" << endl;
115
+ cout << "If you want to play candy, press 3" << endl;
110
-
116
+
111
- cout << "選んでください: ";
117
+ cout << "You choose: ";
112
118
 
113
119
  cin >> theme;
114
120
 
115
-
121
+ cout << "<---------------------->" << endl;
122
+
116
-
123
+ cout << "Please choose play spped:" << endl;
124
+
117
-
125
+ cout << "If you want to play 2seconds(Difficult), press 2" << endl;
126
+
118
-
127
+ cout << "If you want to play 4seconds(normal), press 4" << endl;
128
+
129
+ cout << "If you want to play 6seconds(easy), press 6" << endl;
130
+
131
+ cout << "You choose: ";
132
+
133
+ cin >> timer;
134
+
135
+
136
+
119
- int **gridArr = new int*[gridsize];
137
+ int **gridArr = new int*[gridSize];
120
-
138
+
121
- for(int i = 0; i < gridsize; i++) {
139
+ for(int i = 0; i < gridSize; i++) {
122
-
140
+
123
- gridArr[i] = new int[gridsize];
141
+ gridArr[i] = new int[gridSize];
124
142
 
125
143
  }
126
144
 
127
145
  //いくつ必要なのかを計算する
128
146
 
129
- int randomNum = (gridsize*gridsize)/2;
147
+ int randomNum = (gridSize*gridSize)/2;
130
-
148
+
131
- int shuffleArr[50];
149
+ int shuffleArr[50];//ただの数字
132
150
 
133
151
  //shuffleArrの中に順に数字を入力する
134
152
 
@@ -140,6 +158,10 @@
140
158
 
141
159
  }
142
160
 
161
+ //時間を使用した乱数生成を行う
162
+
163
+ srand(time(NULL));
164
+
143
165
  //ここでランダムに数値を入れ替えていく
144
166
 
145
167
  //後ろから順番に順に交換する.
@@ -178,6 +200,50 @@
178
200
 
179
201
  };
180
202
 
203
+ //cout << element[tmpArr[i]]でstring elementを呼び出す(後で書く)
204
+
205
+
206
+
207
+ //gridを作成している
208
+
209
+ for(int iii = 0; iii<gridSize;iii++)
210
+
211
+ {
212
+
213
+ cout << " " << iii+1 << " ";
214
+
215
+ }
216
+
217
+ cout << endl;
218
+
219
+ for (int ii = 0; ii <= gridSize; ii++)
220
+
221
+ {
222
+
223
+ cout << " - ";
224
+
225
+ }
226
+
227
+ cout << endl;
228
+
229
+ for (int i = 0; i < gridSize; i++)
230
+
231
+ {
232
+
233
+ cout << i + 1 << " | ";
234
+
235
+ for (int j = 0; j < gridSize; j++)
236
+
237
+ {
238
+
239
+ cout << "* ";
240
+
241
+ }
242
+
243
+ cout << endl;
244
+
245
+ }
246
+
181
247
 
182
248
 
183
249
 

2

1つ目のわからないところを修正しました。

2020/07/25 02:10

投稿

ryamamot0
ryamamot0

スコア3

test CHANGED
File without changes
test CHANGED
@@ -80,13 +80,11 @@
80
80
 
81
81
  int timer;
82
82
 
83
- string element[50] = {H,He,Li,Be,B,C,N,O,F,Ne,Na,Mg,Al,Si,P,S,Cl,Ar,K,Ca,Sc,Ti,V,Cr,Mn,Fe,Co,Ni,Cu,Zn,Ga,Ge,As,Se,Br,Kr,Rb,Sr,Y,Zr,Nb,Mo,Tc,Ru,Rh,Pd,Ag,Cd,In,Sn}
83
+ string element[50] = {"H","He","Li","Be","B","C","N","O","F","Ne","Na","Mg","Al","Si","P","S","Cl","Ar","K","Ca","Sc","Ti","V","Cr","Mn","Fe","Co","Ni","Cu","Zn","Ga","Ge","As","Se","Br","Kr","Rb","Sr","Y","Zr","Nb","Mo","Tc","Ru","Rh","Pd","Ag","Cd","In","Sn"};
84
84
 
85
- string fruits[50] = {grape,apple,tangerine,satsuma,strawberry,pear,apricot,lime,orange,cantaloupe,jujube,papaya,fig,banana,honeydew,cherry,mango,kiwi,tomato,huckleberry,boysenberry,nectarine,grapefruit,pomegranate,passon_fruit,coconut,clementine,date,starfruit,peach,plum,blackberry,kumquat,guava,dragonfruit,raspberry,watermelon,pineapple,blueberry,avocado,lemon}
85
+ string fruits[50] = {"grape","apple","tangerine","satsuma","strawberry","pear","apricot","lime","orange","cantaloupe","jujube","papaya","fig","banana","honeydew","cherry","mango","kiwi","tomato","huckleberry","boysenberry","nectarine","grapefruit","pomegranate","passon_fruit","coconut","clementine","date","starfruit","peach","plum","blackberry","kumquat","guava","dragonfruit","raspberry","watermelon","pineapple","blueberry","avocado","lemon"};
86
86
 
87
- public:
88
-
89
- void start(){
87
+ string candy[50] = {"Almond Joy","Cotton candy","Atomic Fireball","Twizzlers","Nik-L-Nips","Jawbreakers","Red Vines","Snickers","Junior Mints","Werther's Original","Smarties,Gummi Worms","Pixie Stix","Gummi Bears","Tootsie Rolls","Blow Pops","Peeps","Tootsie Roll Pops","Hershey Bar","Sour Patch Kids","Necco wafers","Three Musketeers","York Peppermint Patties","Candy corn","Butterfinger","Baby Ruth","Kit-Kat","Pocky","Jelly Belly","Jolly Ranchers","Mr. Goodbar","Nerds","Sugar Daddy","Swedish Fish","M&Ms","Toblerone","Circus peanuts","Skittles","Pop Rocks","Reese's pieces","Candy cigarettes","Twix","Milky Way","Milk Duds","Wax lips","Hershey's Kisses","Cadbury eggs","Starburst","Payday","Reese's Peanut Butter Cups"}; void start(){
90
88
 
91
89
  cout << "グリッドサイズを洗濯して下さい:" << endl;
92
90
 
@@ -172,15 +170,13 @@
172
170
 
173
171
  //tmpArrの中にランダムに作成した数値を入れる.
174
172
 
175
- //tmpArr[i]
176
-
177
173
  for(int i =0; i <randomNum ; i++)
178
174
 
179
175
  {
180
176
 
181
- //ここになんて書けば良いかわからない
177
+ tmpArr[i] = shuffleArr[i];
182
178
 
183
- }
179
+ };
184
180
 
185
181
 
186
182
 

1

内容の追加

2020/07/25 00:52

投稿

ryamamot0
ryamamot0

スコア3

test CHANGED
File without changes
test CHANGED
@@ -79,6 +79,10 @@
79
79
  int theme;
80
80
 
81
81
  int timer;
82
+
83
+ string element[50] = {H,He,Li,Be,B,C,N,O,F,Ne,Na,Mg,Al,Si,P,S,Cl,Ar,K,Ca,Sc,Ti,V,Cr,Mn,Fe,Co,Ni,Cu,Zn,Ga,Ge,As,Se,Br,Kr,Rb,Sr,Y,Zr,Nb,Mo,Tc,Ru,Rh,Pd,Ag,Cd,In,Sn}
84
+
85
+ string fruits[50] = {grape,apple,tangerine,satsuma,strawberry,pear,apricot,lime,orange,cantaloupe,jujube,papaya,fig,banana,honeydew,cherry,mango,kiwi,tomato,huckleberry,boysenberry,nectarine,grapefruit,pomegranate,passon_fruit,coconut,clementine,date,starfruit,peach,plum,blackberry,kumquat,guava,dragonfruit,raspberry,watermelon,pineapple,blueberry,avocado,lemon}
82
86
 
83
87
  public:
84
88