質問するログイン新規登録

質問編集履歴

12

2019/11/21 05:29

投稿

R-ogiura
R-ogiura

スコア60

title CHANGED
File without changes
body CHANGED
@@ -305,4 +305,7 @@
305
305
 
306
306
  編集後の配列の解決したプログラム
307
307
  文字数制限があるのでこちらのサイトに書きました。
308
- [配列の解決したプログラム](https://pastebin.com/fgBeSWM5)
308
+ [配列の解決したプログラム](https://pastebin.com/fgBeSWM5)
309
+
310
+ 編集後の構造体の解決したプログラム
311
+ [構造体の解決したプログラム](https://pastebin.com/FQJSyKYh)

11

編集

2019/11/21 05:29

投稿

R-ogiura
R-ogiura

スコア60

title CHANGED
File without changes
body CHANGED
@@ -244,6 +244,7 @@
244
244
  ```
245
245
 
246
246
  編集後の解決したクラスのプログラム
247
+ ```ここに言語を入力
247
248
  #include <DxLib.h>
248
249
 
249
250
  class Str {
@@ -256,7 +257,6 @@
256
257
  void setMember(int iMember) { pos = iMember; }
257
258
  Str(const char* str, int frame)
258
259
  : str(str), frame(frame), pos(0), count(0) {}
259
- ```
260
260
 
261
261
  void drawString(int x, int y, int color) {
262
262
  if (count == 0 && str[pos]) pos += 1 + IsDBCSLeadByte(str[pos]);
@@ -302,6 +302,7 @@
302
302
  }
303
303
  ```
304
304
 
305
+
305
306
  編集後の配列の解決したプログラム
306
307
  文字数制限があるのでこちらのサイトに書きました。
307
308
  [配列の解決したプログラム](https://pastebin.com/fgBeSWM5)

10

んごいr

2019/11/21 05:12

投稿

R-ogiura
R-ogiura

スコア60

title CHANGED
File without changes
body CHANGED
@@ -244,7 +244,6 @@
244
244
  ```
245
245
 
246
246
  編集後の解決したクラスのプログラム
247
- ```
248
247
  #include <DxLib.h>
249
248
 
250
249
  class Str {
@@ -257,6 +256,7 @@
257
256
  void setMember(int iMember) { pos = iMember; }
258
257
  Str(const char* str, int frame)
259
258
  : str(str), frame(frame), pos(0), count(0) {}
259
+ ```
260
260
 
261
261
  void drawString(int x, int y, int color) {
262
262
  if (count == 0 && str[pos]) pos += 1 + IsDBCSLeadByte(str[pos]);
@@ -300,4 +300,8 @@
300
300
  DxLib_End(); // DXライブラリ終了処理
301
301
  return 0;
302
302
  }
303
- ```
303
+ ```
304
+
305
+ 編集後の配列の解決したプログラム
306
+ 文字数制限があるのでこちらのサイトに書きました。
307
+ [配列の解決したプログラム](https://pastebin.com/fgBeSWM5)

9

編集

2019/11/21 05:11

投稿

R-ogiura
R-ogiura

スコア60

title CHANGED
File without changes
body CHANGED
@@ -21,7 +21,7 @@
21
21
  int pos;
22
22
  int count;
23
23
  public:
24
- int position() const { return pos; } // コレ追加
24
+
25
25
  void setMember(int iMember) { pos = iMember; }
26
26
  Str(const char* str, int frame)
27
27
  : str(str), frame(frame), pos(0), count(0) {}
@@ -61,7 +61,7 @@
61
61
  str1.drawString(100, 500, Green);
62
62
 
63
63
 
64
- DrawFormatString(300, 100, Green, "%d", str1.position());//Str str1("あいうabc", 50);に関しての関数position()のposについて描画できた。
64
+
65
65
  if (++t == 60 * 6) { t = 0; str1.reset(); } // 6秒ごとにリセット
66
66
  }
67
67
 
@@ -241,4 +241,63 @@
241
241
  DxLib_End(); // DXライブラリ終了処理
242
242
  return 0;
243
243
  }
244
+ ```
245
+
246
+ 編集後の解決したクラスのプログラム
247
+ ```
248
+ #include <DxLib.h>
249
+
250
+ class Str {
251
+ const char* str;
252
+ int frame;
253
+ int pos;
254
+ int count;
255
+ public:
256
+ int position() const { return pos; } // コレ追加
257
+ void setMember(int iMember) { pos = iMember; }
258
+ Str(const char* str, int frame)
259
+ : str(str), frame(frame), pos(0), count(0) {}
260
+
261
+ void drawString(int x, int y, int color) {
262
+ if (count == 0 && str[pos]) pos += 1 + IsDBCSLeadByte(str[pos]);
263
+ if (++count == frame) count = 0;
264
+ DrawFormatString(x, y, color, "%.*s", pos, str);//ポインタの配列としてstrを*sとして、[]の中のposは%としたのだ。
265
+ }
266
+
267
+ void reset() { pos = count = 0; }
268
+ };
269
+
270
+ int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
271
+ {
272
+ SetFontSize(25); //サイズを64に変更 ???
273
+ SetFontThickness(10); //太さを8に変更 ???
274
+ ChangeFont("MS 明朝"); //種類をMS明朝に変更
275
+ ChangeFontType(DX_FONTTYPE_ANTIALIASING); //アンチエイリアスフォント
276
+
277
+ SetGraphMode(780, 680, 32); // ウィンドウの大きさを指定
278
+ ChangeWindowMode(TRUE); // 全画面ではなくウインドウを使用
279
+ if (DxLib_Init() == -1) return -1; // DXライブラリ初期化処理
280
+ SetDrawScreen(DX_SCREEN_BACK); // 裏画面を使用する設定
281
+
282
+ SetWindowSizeChangeEnableFlag(FALSE, FALSE);
283
+
284
+ SetGraphMode(780, 680, 32); // 画面サイズは最大の780*680にしておく
285
+ SetWindowSize(780, 680); // 最初は 640x480 にしておく ???
286
+
287
+ int Green = GetColor(0, 255, 0);
288
+
289
+ Str str1("あいうabc", 50); // 6文字を 50フレームごとに 1文字追加
290
+ // 全部で 300フレーム(5秒)
291
+ int t = 0;
292
+ while (!ScreenFlip() && !ProcessMessage() && !ClearDrawScreen()) {
293
+ str1.drawString(100, 500, Green);
294
+
295
+
296
+ DrawFormatString(300, 100, Green, "%d", str1.position());//Str str1("あいうabc", 50);に関しての関数position()のposについて描画できた。
297
+ if (++t == 60 * 6) { t = 0; str1.reset(); } // 6秒ごとにリセット
298
+ }
299
+
300
+ DxLib_End(); // DXライブラリ終了処理
301
+ return 0;
302
+ }
244
303
  ```

8

2019/11/20 23:10

投稿

R-ogiura
R-ogiura

スコア60

title CHANGED
File without changes
body CHANGED
@@ -16,52 +16,57 @@
16
16
  #include <DxLib.h>
17
17
 
18
18
  class Str {
19
- const char *str;
19
+ const char* str;
20
- int frame;
20
+ int frame;
21
- int pos;
21
+ int pos;
22
- int count;
22
+ int count;
23
23
  public:
24
+ int position() const { return pos; } // コレ追加
25
+ void setMember(int iMember) { pos = iMember; }
24
- Str(const char *str, int frame)
26
+ Str(const char* str, int frame)
25
- : str(str), frame(frame), pos(0), count(0) {}
27
+ : str(str), frame(frame), pos(0), count(0) {}
26
28
 
27
- void drawString(int x, int y, int color) {
29
+ void drawString(int x, int y, int color) {
28
- if (count == 0 && str[pos]) pos += 1 + IsDBCSLeadByte(str[pos]);
30
+ if (count == 0 && str[pos]) pos += 1 + IsDBCSLeadByte(str[pos]);
29
- if (++count == frame) count = 0;
31
+ if (++count == frame) count = 0;
30
- DrawFormatString(x, y, color, "%.*s", pos, str);
32
+ DrawFormatString(x, y, color, "%.*s", pos, str);//ポインタの配列としてstrを*sとして、[]の中のposは%としたのだ。
31
- }
33
+ }
32
34
 
33
- void reset() { pos = count = 0; }
35
+ void reset() { pos = count = 0; }
34
36
  };
35
37
 
36
38
  int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
37
39
  {
38
- SetFontSize(25); //サイズを64に変更 ???
40
+ SetFontSize(25); //サイズを64に変更 ???
39
- SetFontThickness(10); //太さを8に変更 ???
41
+ SetFontThickness(10); //太さを8に変更 ???
40
- ChangeFont("MS 明朝"); //種類をMS明朝に変更
42
+ ChangeFont("MS 明朝"); //種類をMS明朝に変更
41
- ChangeFontType(DX_FONTTYPE_ANTIALIASING); //アンチエイリアスフォント
43
+ ChangeFontType(DX_FONTTYPE_ANTIALIASING); //アンチエイリアスフォント
42
44
 
43
- SetGraphMode(780, 680, 32); // ウィンドウの大きさを指定
45
+ SetGraphMode(780, 680, 32); // ウィンドウの大きさを指定
44
- ChangeWindowMode(TRUE); // 全画面ではなくウインドウを使用
46
+ ChangeWindowMode(TRUE); // 全画面ではなくウインドウを使用
45
- if (DxLib_Init() == -1) return -1; // DXライブラリ初期化処理
47
+ if (DxLib_Init() == -1) return -1; // DXライブラリ初期化処理
46
- SetDrawScreen(DX_SCREEN_BACK); // 裏画面を使用する設定
48
+ SetDrawScreen(DX_SCREEN_BACK); // 裏画面を使用する設定
47
49
 
48
- SetWindowSizeChangeEnableFlag(FALSE, FALSE);
50
+ SetWindowSizeChangeEnableFlag(FALSE, FALSE);
49
51
 
50
- SetGraphMode(780, 680, 32); // 画面サイズは最大の780*680にしておく
52
+ SetGraphMode(780, 680, 32); // 画面サイズは最大の780*680にしておく
51
- SetWindowSize(780, 680); // 最初は 640x480 にしておく ???
53
+ SetWindowSize(780, 680); // 最初は 640x480 にしておく ???
52
54
 
53
- int Green = GetColor(0, 255, 0);
55
+ int Green = GetColor(0, 255, 0);
54
56
 
55
- Str str1("あいうabc", 50); // 6文字を 50フレームごとに 1文字追加
57
+ Str str1("あいうabc", 50); // 6文字を 50フレームごとに 1文字追加
56
- // 全部で 300フレーム(5秒)
58
+ // 全部で 300フレーム(5秒)
57
- int t = 0;
59
+ int t = 0;
58
- while (!ScreenFlip() && !ProcessMessage() && !ClearDrawScreen()) {
60
+ while (!ScreenFlip() && !ProcessMessage() && !ClearDrawScreen()) {
59
- str1.drawString(100, 500, Green);
61
+ str1.drawString(100, 500, Green);
62
+
63
+
64
+ DrawFormatString(300, 100, Green, "%d", str1.position());//Str str1("あいうabc", 50);に関しての関数position()のposについて描画できた。
60
- if (++t == 60 * 6) { t = 0; str1.reset(); } // 6秒ごとにリセット
65
+ if (++t == 60 * 6) { t = 0; str1.reset(); } // 6秒ごとにリセット
61
- }
66
+ }
62
67
 
63
- DxLib_End(); // DXライブラリ終了処理
68
+ DxLib_End(); // DXライブラリ終了処理
64
- return 0;
69
+ return 0;
65
70
  }
66
71
  ```
67
72
  こちらが構造体です。

7

ふぁ

2019/11/20 22:25

投稿

R-ogiura
R-ogiura

スコア60

title CHANGED
File without changes
body CHANGED
@@ -115,7 +115,54 @@
115
115
 
116
116
  こちらが配列のプログラムです。
117
117
  ```ここに言語を入力
118
+ #include <DxLib.h>
119
+
120
+ const char *str[3] = { "あいうabc", "0123456789", "ABCDEFG" };
121
+ int frame[3] = { 50, 30, 40 };
122
+ int pos[3];
123
+ int count[3];
124
+
125
+ void drawString(int i, int x, int y, int color)
126
+ {
127
+ char c = str[i][pos[i]];
128
+ if (count[i] == 0 && c != '\0')
129
+ pos[i] += IsDBCSLeadByte(c) ? 2 : 1;
130
+ if (++count[i] == frame[i]) count[i] = 0;
131
+ DrawFormatString(x, y, color, "%.*s", pos[i], str[i]);
132
+ }
133
+
134
+ int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
135
+ {
136
+ SetFontSize(25); //サイズを64に変更 ???
137
+ SetFontThickness(10); //太さを8に変更 ???
138
+ ChangeFont("MS 明朝"); //種類をMS明朝に変更
139
+ ChangeFontType(DX_FONTTYPE_ANTIALIASING); //アンチエイリアスフォント
140
+
141
+ SetGraphMode(780, 680, 32); // ウィンドウの大きさを指定
142
+ ChangeWindowMode(TRUE); // 全画面ではなくウインドウを使用
143
+ if (DxLib_Init() == -1) return -1; // DXライブラリ初期化処理
144
+ SetDrawScreen(DX_SCREEN_BACK); // 裏画面を使用する設定
145
+
146
+ SetWindowSizeChangeEnableFlag(FALSE, FALSE);
147
+
148
+ int Green = GetColor(0, 255, 0);
149
+ int Yellow = GetColor(255, 255, 0);
150
+ int White = GetColor(255, 255, 255);
151
+
118
- const char*
152
+ int t = 0;
153
+ while (!ScreenFlip() && !ProcessMessage() && !ClearDrawScreen()) {
154
+ drawString(0, 100, 500, Green);
155
+ drawString(1, 100, 530, Yellow);
156
+ drawString(2, 500, 530, White);
157
+ if (++t == 6*60) {
158
+ t = 0;
159
+ for (int i = 0; i < 3; i++) pos[i] = count[i] = 0;
160
+ }
161
+ }
162
+
163
+ DxLib_End(); // DXライブラリ終了処理
164
+ return 0;
165
+ }
119
166
  ```
120
167
 
121
168
  編集

6

編集後のクラスのプログラム

2019/11/19 23:41

投稿

R-ogiura
R-ogiura

スコア60

title CHANGED
File without changes
body CHANGED
@@ -134,7 +134,7 @@
134
134
  const char* str[3] = { "あいうabc", "0123456789", "ABCDEFG" };
135
135
  ポインタを使用して右の三つの文字列を配列に入れるまではわかるのですが、**なぜポインタを使用して、constを付けたのかわかりません。**どうか理由を教えてください。
136
136
 
137
- 編集 クラスのプログラム
137
+ 編集後のクラスのプログラム
138
138
  ```ここに言語を入力
139
139
  #include <DxLib.h>
140
140
 

5

2019/11/19 23:13

投稿

R-ogiura
R-ogiura

スコア60

title CHANGED
File without changes
body CHANGED
@@ -132,4 +132,61 @@
132
132
 
133
133
  もう一つ、配列のプログラムに関して
134
134
  const char* str[3] = { "あいうabc", "0123456789", "ABCDEFG" };
135
- ポインタを使用して右の三つの文字列を配列に入れるまではわかるのですが、**なぜポインタを使用して、constを付けたのかわかりません。**どうか理由を教えてください。
135
+ ポインタを使用して右の三つの文字列を配列に入れるまではわかるのですが、**なぜポインタを使用して、constを付けたのかわかりません。**どうか理由を教えてください。
136
+
137
+ 編集 クラスのプログラム
138
+ ```ここに言語を入力
139
+ #include <DxLib.h>
140
+
141
+ class Str {
142
+ const char* str;
143
+ int frame;
144
+ int pos;
145
+ int count;
146
+ public:
147
+ int position() const { return pos; } // コレ追加
148
+ Str(const char* str, int frame)
149
+ : str(str), frame(frame), pos(0), count(0) {}
150
+
151
+ void drawString(int x, int y, int color) {
152
+ if (count == 0 && str[pos]) pos += 1 + IsDBCSLeadByte(str[pos]);
153
+ if (++count == frame) count = 0;
154
+ DrawFormatString(x, y, color, "%.*s", pos, str);
155
+ }
156
+
157
+ void reset() { pos = count = 0; }
158
+ };
159
+
160
+ int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
161
+ {
162
+ SetFontSize(25); //サイズを64に変更 ???
163
+ SetFontThickness(10); //太さを8に変更 ???
164
+ ChangeFont("MS 明朝"); //種類をMS明朝に変更
165
+ ChangeFontType(DX_FONTTYPE_ANTIALIASING); //アンチエイリアスフォント
166
+
167
+ SetGraphMode(780, 680, 32); // ウィンドウの大きさを指定
168
+ ChangeWindowMode(TRUE); // 全画面ではなくウインドウを使用
169
+ if (DxLib_Init() == -1) return -1; // DXライブラリ初期化処理
170
+ SetDrawScreen(DX_SCREEN_BACK); // 裏画面を使用する設定
171
+
172
+ SetWindowSizeChangeEnableFlag(FALSE, FALSE);
173
+
174
+ SetGraphMode(780, 680, 32); // 画面サイズは最大の780*680にしておく
175
+ SetWindowSize(780, 680); // 最初は 640x480 にしておく ???
176
+
177
+ int Green = GetColor(0, 255, 0);
178
+
179
+ Str str1("あいうabc", 50); // 6文字を 50フレームごとに 1文字追加
180
+ // 全部で 300フレーム(5秒)
181
+ int t = 0;
182
+ while (!ScreenFlip() && !ProcessMessage() && !ClearDrawScreen()) {
183
+ str1.drawString(100, 500, Green);
184
+ if (++t == 60 * 6) { t = 0; str1.reset(); } // 6秒ごとにリセット
185
+
186
+ DrawFormatString(300, 300, Green, "%d",pos);//これを追加した
187
+ }
188
+
189
+ DxLib_End(); // DXライブラリ終了処理
190
+ return 0;
191
+ }
192
+ ```

4

へんsっゆ

2019/11/19 22:26

投稿

R-ogiura
R-ogiura

スコア60

title CHANGED
File without changes
body CHANGED
@@ -115,54 +115,7 @@
115
115
 
116
116
  こちらが配列のプログラムです。
117
117
  ```ここに言語を入力
118
- #include <DxLib.h>
119
-
120
- const char *str[3] = { "あいうabc", "0123456789", "ABCDEFG" };
121
- int frame[3] = { 50, 30, 40 };
122
- int pos[3];
123
- int count[3];
124
-
125
- void drawString(int i, int x, int y, int color)
126
- {
127
- char c = str[i][pos[i]];
128
- if (count[i] == 0 && c != '\0')
129
- pos[i] += IsDBCSLeadByte(c) ? 2 : 1;
130
- if (++count[i] == frame[i]) count[i] = 0;
131
- DrawFormatString(x, y, color, "%.*s", pos[i], str[i]);
132
- }
133
-
134
- int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
135
- {
136
- SetFontSize(25); //サイズを64に変更 ???
137
- SetFontThickness(10); //太さを8に変更 ???
138
- ChangeFont("MS 明朝"); //種類をMS明朝に変更
139
- ChangeFontType(DX_FONTTYPE_ANTIALIASING); //アンチエイリアスフォント
140
-
141
- SetGraphMode(780, 680, 32); // ウィンドウの大きさを指定
142
- ChangeWindowMode(TRUE); // 全画面ではなくウインドウを使用
143
- if (DxLib_Init() == -1) return -1; // DXライブラリ初期化処理
144
- SetDrawScreen(DX_SCREEN_BACK); // 裏画面を使用する設定
145
-
146
- SetWindowSizeChangeEnableFlag(FALSE, FALSE);
147
-
148
- int Green = GetColor(0, 255, 0);
149
- int Yellow = GetColor(255, 255, 0);
150
- int White = GetColor(255, 255, 255);
151
-
152
- int t = 0;
118
+ const char*
153
- while (!ScreenFlip() && !ProcessMessage() && !ClearDrawScreen()) {
154
- drawString(0, 100, 500, Green);
155
- drawString(1, 100, 530, Yellow);
156
- drawString(2, 500, 530, White);
157
- if (++t == 6*60) {
158
- t = 0;
159
- for (int i = 0; i < 3; i++) pos[i] = count[i] = 0;
160
- }
161
- }
162
-
163
- DxLib_End(); // DXライブラリ終了処理
164
- return 0;
165
- }
166
119
  ```
167
120
 
168
121
  編集

3

変数

2019/11/19 22:24

投稿

R-ogiura
R-ogiura

スコア60

title CHANGED
File without changes
body CHANGED
@@ -175,4 +175,8 @@
175
175
  DrawFormatString(x, y, color, "%.*s", s->pos, s->str);//関数drawStringの引数として関数DrawFormatStringの引数を利用する
176
176
  ```
177
177
  の部分に関してわからないことがあります。
178
- 最後の部分のs->pos, s->strの中身を表すために"%.*s"と書いていますが、なぜ"%.*s"のように書けるのでしょうか。
178
+ 最後の部分のs->pos, s->strの中身を表すために"%.*s"と書いていますが、なぜ"%.*s"のように書けるのでしょうか。
179
+
180
+ もう一つ、配列のプログラムに関して
181
+ const char* str[3] = { "あいうabc", "0123456789", "ABCDEFG" };
182
+ ポインタを使用して右の三つの文字列を配列に入れるまではわかるのですが、**なぜポインタを使用して、constを付けたのかわかりません。**どうか理由を教えてください。

2

へんしゅう

2019/11/19 04:50

投稿

R-ogiura
R-ogiura

スコア60

title CHANGED
File without changes
body CHANGED
@@ -163,4 +163,16 @@
163
163
  DxLib_End(); // DXライブラリ終了処理
164
164
  return 0;
165
165
  }
166
- ```
166
+ ```
167
+
168
+ 編集
169
+ 構造体のプログラムに関してなのですが
170
+ ```ここに言語を入力
171
+ char c = s->str[s->pos];//ポインタsに入っているstr[pos]の文字のデータが一文字ずつcに入る
172
+ if (s->count == 0 && c != '\0')//その時にcountが0でかつcに入る文字が¥0(文字列の最後の部分\0)でない、すなわち文字ならば日本語一文字は2バイトなので、
173
+   s->pos += IsDBCSLeadByte(c) ? 2 : 1;//posに2バイトを足す、違う場合は¥0(\0)なので1バイト加える。(¥0(\0)は1バイトなので。)
174
+ if (++s->count == s->frame) s->count = 0;//一文字ずつ出力する間隔を処理する変数countと間隔の最大値を表すframeが等しくなったら、countを0にする
175
+ DrawFormatString(x, y, color, "%.*s", s->pos, s->str);//関数drawStringの引数として関数DrawFormatStringの引数を利用する
176
+ ```
177
+ の部分に関してわからないことがあります。
178
+ 最後の部分のs->pos, s->strの中身を表すために"%.*s"と書いていますが、なぜ"%.*s"のように書けるのでしょうか。

1

hennsuu

2019/11/19 04:29

投稿

R-ogiura
R-ogiura

スコア60

title CHANGED
@@ -1,1 +1,1 @@
1
- クラス、構造体、配列で作った関数の外で同じ変数を扱う方法。
1
+ クラス、構造体、配列で作った関数の外(while (){}の{}の中)で同じ変数を扱う方法。
body CHANGED
@@ -11,6 +11,7 @@
11
11
 
12
12
  **最後の質問です。**配列で書かれたプログラムについてです。
13
13
  関数の中以外で(while (!ScreenFlip() && !ProcessMessage() && !ClearDrawScreen())の{}の中でpos[i]を使うにはどのように書けばいいでしょうか。他にも原因は同じですが、DrawFormatString(300, 300, Green, "%d", i);と書いてみたのですが、変数iが定義されていないとでてエラーになります。
14
+ こちらがクラスのプログラムです。
14
15
  ```
15
16
  #include <DxLib.h>
16
17