Created
January 24, 2020 13:32
-
-
Save YASAI03/4a9862a0fe730379a74717aca36870d3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# include <Siv3D.hpp> // OpenSiv3D v0.4.0 | |
# include <utility> | |
void Main() | |
{ | |
Window::Resize(1800, 1000); | |
Scene::Resize(1800, 1000); | |
Scene::SetBackground(ColorF(0.8, 0.9, 1.0)); | |
FilePath root = U"signboard_t1/"; | |
Texture ans(root + U"design.png"); | |
Array<Texture> pieces(65); | |
String spl = U" "; | |
Array<int> suma(64); | |
{ | |
TextReader tex(U"ans.txt"); | |
if (!tex) { | |
iota(suma.begin(), suma.end(), 1); | |
} | |
else { | |
for (int i = 0; i < 8; i++) { | |
String s; | |
tex.readLine(s); | |
auto str = s.split(spl[0]); | |
for (int j = 0; j < 8; j++) { | |
suma[i * 8 + j] = Parse<int>(str[j]); | |
} | |
} | |
} | |
} | |
for (int i = 1; i <= 64; i++) { | |
pieces[i] = Texture(Format(root, U"pieces/p_", i, U".png")); | |
} | |
Grid<Rect> rects(8, 8); | |
int s = -1; | |
while (System::Update()) | |
{ | |
if (KeyEnter.down()) { | |
TextWriter tex(U"ans.txt"); | |
for (int i = 0; i < 8; i++) { | |
for (int j = 0; j < 8; j++) { | |
tex.write(suma[i * 8 + j], U" "); | |
} | |
tex.write(U"\n"); | |
} | |
} | |
for (int i = 0; i < 8; i++) { | |
for (int j = 0; j < 8; j++) { | |
if (i * 8 + j == s) { | |
pieces[suma[i * 8 + j]].scaled(3.0).draw(j * 96, i * 96).drawFrame(1.0, Palette::Yellow); | |
} | |
else { | |
pieces[suma[i * 8 + j]].scaled(3.0).draw(j * 96, i * 96).drawFrame(1.0, Palette::Black); | |
} | |
if (Rect(j * 96, i * 96, 96, 96).leftClicked()) { | |
if (s == -1) { | |
s = i * 8 + j; | |
} | |
else { | |
std::swap(suma[i * 8 + j], suma[s]); | |
s = -1; | |
} | |
} | |
} | |
} | |
for (int i = 0; i < 8; i++) { | |
for (int j = 0; j < 8; j++) { | |
ans(j * 32, i * 32, 32, 32).scaled(3.0).draw(j * 96 + 864, i * 96).drawFrame(1.0, Palette::Black); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment