質問編集履歴
5
質問用に編集したコード"fileinput.open("savefile.txt")"を元のコード"fileinput.open(filename);"に変更しました
title
CHANGED
File without changes
|
body
CHANGED
@@ -115,8 +115,8 @@
|
|
115
115
|
ifstream fileinput;
|
116
116
|
|
117
117
|
|
118
|
-
fileinput.open("savefile.txt");
|
118
|
+
//fileinput.open("savefile.txt");
|
119
|
-
|
119
|
+
fileinput.open(filename);
|
120
120
|
|
121
121
|
//ファイルに書き込みがあったらファイルの値を読み込む
|
122
122
|
|
4
コンストラクタの一部を追加しました
title
CHANGED
File without changes
|
body
CHANGED
@@ -100,6 +100,16 @@
|
|
100
100
|
```
|
101
101
|
|
102
102
|
```mainadmin.cpp
|
103
|
+
|
104
|
+
MainAdmin::MainAdmin():filename("savefile.txt"),quitApplication(false)
|
105
|
+
{
|
106
|
+
|
107
|
+
|
108
|
+
}
|
109
|
+
|
110
|
+
|
111
|
+
|
112
|
+
|
103
113
|
void MainAdmin::Init()
|
104
114
|
{
|
105
115
|
ifstream fileinput;
|
3
クラスヘッダファイルを一部抜粋ではなく、全体を追加しました
title
CHANGED
File without changes
|
body
CHANGED
@@ -12,6 +12,21 @@
|
|
12
12
|
|
13
13
|
> 現在のコードとテキストファイルの状態
|
14
14
|
```C++
|
15
|
+
#pragma once
|
16
|
+
#include <fstream>
|
17
|
+
using namespace std;
|
18
|
+
|
19
|
+
class SaveButton;
|
20
|
+
class GameObject;
|
21
|
+
class EnemyHP_AddButton;
|
22
|
+
class EnemyHP_SubButton;
|
23
|
+
class X_AddButton;
|
24
|
+
class X_SubButton;
|
25
|
+
class Y_AddButton;
|
26
|
+
class Y_SubButton;
|
27
|
+
class ClearScoreButton_Add;
|
28
|
+
class ClearScoreButton_Sub;
|
29
|
+
class Mouse;
|
15
30
|
class MainAdmin
|
16
31
|
{
|
17
32
|
protected:
|
@@ -19,7 +34,69 @@
|
|
19
34
|
int Player_initX;
|
20
35
|
int Player_initY;
|
21
36
|
|
37
|
+
int Player_initHP;
|
38
|
+
int Enemy_initHP;
|
39
|
+
|
40
|
+
int Clear_Score_init;
|
41
|
+
|
42
|
+
char key[256];
|
43
|
+
bool quitApplication;
|
44
|
+
|
45
|
+
int Player_GraphicHandle;
|
46
|
+
|
47
|
+
std::unique_ptr<GameObject>Player;
|
48
|
+
std::shared_ptr<Mouse>mouse;
|
49
|
+
|
50
|
+
std::unique_ptr<SaveButton>S_button;
|
51
|
+
|
52
|
+
std::unique_ptr<EnemyHP_AddButton>HPAdd;
|
53
|
+
std::unique_ptr<EnemyHP_SubButton>HPSub;
|
54
|
+
|
55
|
+
std::unique_ptr<X_AddButton>X_add;
|
56
|
+
std::unique_ptr<X_SubButton>X_Sub;
|
57
|
+
|
58
|
+
std::unique_ptr<Y_AddButton>Y_add;
|
59
|
+
std::unique_ptr<Y_SubButton>Y_Sub;
|
60
|
+
|
61
|
+
std::unique_ptr <ClearScoreButton_Add>Clear_Add;
|
62
|
+
std::unique_ptr<ClearScoreButton_Sub>Clear_Sub;
|
63
|
+
public:
|
64
|
+
|
65
|
+
const char* filename;
|
66
|
+
|
67
|
+
MainAdmin();
|
68
|
+
~MainAdmin();
|
69
|
+
int GetP_initX() { return Player_initX; }
|
70
|
+
int GetP_initY() {
|
71
|
+
return Player_initY;
|
22
|
-
}
|
72
|
+
}
|
73
|
+
int GetP_initHP() {
|
74
|
+
return Player_initHP;
|
75
|
+
}
|
76
|
+
int GetE_initHP() {
|
77
|
+
return Enemy_initHP;
|
78
|
+
}
|
79
|
+
int GetClear_Score_Init()
|
80
|
+
{
|
81
|
+
return Clear_Score_init;
|
82
|
+
}
|
83
|
+
std::shared_ptr<Mouse> GetMouse() { return mouse; }
|
84
|
+
void SetClear_Score_Init(int score) { Clear_Score_init = score; }
|
85
|
+
void SetEnemy_HP(int hp) { Enemy_initHP = hp; }
|
86
|
+
void SetinitX(int m_x) { Player_initX = m_x; }
|
87
|
+
void SetinitY(int m_y) { Player_initY = m_y; }
|
88
|
+
char* GetKey() { return key; }
|
89
|
+
void Init();
|
90
|
+
|
91
|
+
void Update();
|
92
|
+
|
93
|
+
void SaveFile();
|
94
|
+
|
95
|
+
void end();
|
96
|
+
|
97
|
+
};
|
98
|
+
|
99
|
+
|
23
100
|
```
|
24
101
|
|
25
102
|
```mainadmin.cpp
|
2
セーブ時のコード記述を追加しました
title
CHANGED
File without changes
|
body
CHANGED
@@ -43,6 +43,25 @@
|
|
43
43
|
fileinput.close();
|
44
44
|
|
45
45
|
}
|
46
|
+
|
47
|
+
|
48
|
+
void MainAdmin::SaveFile()
|
49
|
+
{
|
50
|
+
ofstream fileoutput;
|
51
|
+
if (!fileoutput.is_open()) {
|
52
|
+
fileoutput.open(filename);
|
53
|
+
}
|
54
|
+
//ファイルに出力する
|
55
|
+
fileoutput<< 200 << 200
|
56
|
+
<< 200 << 200
|
57
|
+
<< 200;
|
58
|
+
|
59
|
+
DrawString(320, 240, "セーブしました", GetColor(255, 255, 255));
|
60
|
+
fileoutput.close();
|
61
|
+
|
62
|
+
|
63
|
+
}
|
64
|
+
|
46
65
|
```
|
47
66
|
|
48
67
|
```
|
1
MainAdminクラスのヘッダファイルを追加しました
title
CHANGED
File without changes
|
body
CHANGED
@@ -12,6 +12,17 @@
|
|
12
12
|
|
13
13
|
> 現在のコードとテキストファイルの状態
|
14
14
|
```C++
|
15
|
+
class MainAdmin
|
16
|
+
{
|
17
|
+
protected:
|
18
|
+
//エディターを読み込んだ時の、自機の初期位置
|
19
|
+
int Player_initX;
|
20
|
+
int Player_initY;
|
21
|
+
|
22
|
+
}
|
23
|
+
```
|
24
|
+
|
25
|
+
```mainadmin.cpp
|
15
26
|
void MainAdmin::Init()
|
16
27
|
{
|
17
28
|
ifstream fileinput;
|