-
Notifications
You must be signed in to change notification settings - Fork 1
/
Matching.cpp
218 lines (187 loc) · 5.21 KB
/
Matching.cpp
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#include "Matching.hpp"
#include "Maze.hpp"
Matching::Matching(const InitData& init)
: IScene(init)
{
// INIファイル
// 全てのセクションを列挙
for (const auto& section : Matching_ini.sections())
{
if (section.section == U"Audio") // Audioセクション
{
// セクション内のすべてのキーを列挙
for (const auto& key : section.keys)
{
if (key.name == U"Matching_BGM") // Matchingキー
{
Matching_Audio_BGM_num = Parse<uint8>(key.value);
}
}
}
}
net->ResetData();
Print << U"迷路作成中";
//if (getData().maze.isEmpty())
{
Maze maze(MazeSize);
getData().maze = maze.coordinate;
}
ClearPrint();
IsMatching = false;
// GUI
// マッチング文字
Match_MatchNow = String{ U"マッチング中・・・" };
}
void Matching::update()
{
// 音楽
// 曲が流れてるか判定
if (AudioAsset(U"Matching_BGM" + Format(Matching_Audio_BGM_num)).isPlaying() == false)
{
AudioAsset(U"Matching_BGM" + Format(Matching_Audio_BGM_num)).play(MixBus0);
}
if (net != nullptr)
{
//ClearPrint();
if (!IsMatching)
{
if (Match_Button.leftClicked() && !net->IsPressed)
{
net->joinwithSize();
net->IsPressed = true;
}
//オプションシーンへ戻る
if (SimpleGUI::Button(U"←", Vec2(30, 30), unspecified, !net->IsPressed))
{
changeScene(State::Option);
}
}
if (net->isInRoom())
{
if (Match_Button.leftClicked()&& net->getPlayerCountInCurrentRoom()==1)
{
net->opLeaveRoom();
net->IsPressed = false;
}
}
if (net->errorconnect && Match_Button.leftClicked())
{
net->connect();
}
//部屋の参加人数が二人ならシーン遷移
if (net->getPlayerCountInCurrentRoom() == 2&&IsOnce)
{
AudioAsset(U"Matching_BGM" + Format(Matching_Audio_BGM_num)).stop();
if (net->isMasterClient())
{
net->opRaiseEvent(1, rle.make(getData().maze,getData().maze.size().x, getData().maze.size().y));
if (isNGword(getData().UserName))
{
getData().UserName = U"NG";
}
net->opRaiseEvent(2, getData().UserName);
net->map.gridinport(getData().maze);
IsOnce = false;
changeScene(State::Game);
}else if (net->maze&&net->EnemyPlayerName)
{
getData().maze = net->maze.value();
if (isNGword(getData().UserName))
{
getData().UserName = U"NG";
}
net->opRaiseEvent(2, getData().UserName);
net->map.gridinport(getData().maze);
IsOnce = false;
changeScene(State::Game);
}
IsMatching = true;
}
if (KeyEnter.pressed())
{
Print_NetworkData();
}
if (Match_Button.mouseOver())
{
if (net->getPlayerCountInCurrentRoom() != 2)
Cursor::RequestStyle(CursorStyle::Hand);
}
if (Match_Button.mouseOver())
{
if (net->getPlayerCountInCurrentRoom() != 2)
Cursor::RequestStyle(CursorStyle::Hand);
}
net->update();
}
// k
text_time += Scene::DeltaTime();
if (static_cast<size_t>(text_time / 0.2) >= Match_MatchNow.size())
{
text_time = 0;
}
// k
}
void Matching::draw() const
{
// 背景設定
// 背景色設定
Scene::SetBackground(ColorF(0.3, 0.4, 0.5));
if (net != nullptr)
{
if (net->isInRoom())
{
if (net->getPlayerCountInCurrentRoom() == 1)
{
// メインメッセージ
Match_MatchNow_font(Match_MatchNow.substr(0, static_cast<size_t>(text_time / 0.2))).draw(175, 100);
// ぐるぐる
Circle(center, 30).drawArc(Scene::Time() * 140_deg, 240_deg, 0, 20, ColorF(0.4));
// Cancelボタン
Match_Button.draw(ColorF{ 1.0, 1.0, 1.0, 1.0 });
FontAsset(U"Medium_15")(U"キャンセル").drawAt(Match_Button.center(), ColorF{ 0, 0, 0, 1.0 });
}
else if (net->getPlayerCountInCurrentRoom() == 2)
{
font(U"対戦相手が見つかりました").drawAt(center);
}
}
else
{
if (net->errorconnect)
{
// メインメッセージ
font(U"サーバーへの接続に失敗しました").drawAt(400, 135);
// Reconnectボタン
Match_Button.draw(ColorF{ 1.0, 1.0, 1.0, 1.0 });
FontAsset(U"Medium_15")(U"再接続").drawAt(Match_Button.center(), ColorF{ 0, 0, 0, 1.0 });
}
else if (!net->isconnect)
{
// メインメッセージ
font(U"サーバーに接続中です").drawAt(400, 135);
}
else if (net->isconnect)
{
// メインメッセージ
//font(U"サーバーに接続完了しました").drawAt(400, 135);
// MatchStartボタン
Match_Button.draw(ColorF{ 1.0, 1.0, 1.0, 1.0 });
FontAsset(U"Medium_15")(U"マッチング開始").drawAt(Match_Button.center(), ColorF{ 0, 0, 0, 1.0 });
}
}
}
}
void Matching::Print_NetworkData()
{
Console.writeln();
Console << U"getRoomNameList: {}"_fmt(net->getRoomNameList());
Console << U"getName: {}"_fmt(net->getName());
Console << U"isInRoom: {}"_fmt(net->isInRoom());
Console << U"getCurrentRoomName: {}"_fmt(net->getCurrentRoomName());
Console << U"getPlayerCountInCurrentRoom: {}"_fmt(net->getPlayerCountInCurrentRoom());
Console << U"getMaxPlayersInCurrentRoom: {}"_fmt(net->getMaxPlayersInCurrentRoom());
Console << U"getIsOpenInCurrentRoom: {}"_fmt(net->getIsOpenInCurrentRoom());
Console << U"localPlayerID: {}"_fmt(net->localPlayerID());
Console << U"isMasterClient: {}"_fmt(net->isMasterClient());
Console << U"getNumber: {}"_fmt(net->getNumber());
}