Skip to content

Instantly share code, notes, and snippets.

@YASAI03
Created January 24, 2020 13:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YASAI03/aeb289229d1d8fbe1fc29f90814d7b4e to your computer and use it in GitHub Desktop.
Save YASAI03/aeb289229d1d8fbe1fc29f90814d7b4e to your computer and use it in GitHub Desktop.
# include <Siv3D.hpp> // OpenSiv3D v0.4.0
void Main()
{
Scene::Resize(640, 320);
Window::SetStyle(WindowStyle::Sizable);
Scene::SetBackground(ColorF(0.8, 0.9, 1.0));
const FilePath root = U"signboard_t1/";
constexpr Size cellSize{ 32,32 };
const Texture ans(root + U"design.png");
Array<Texture> pieces(65);
const String spl = U" ";
Array<int> suma(64);
{
TextReader tex(U"ans.txt");
if (!tex) {
iota(suma.begin(), suma.end(), 1);
}
else {
for (int y = 0; y < 8; y++) {
String s;
tex.readLine(s);
auto str = s.split(spl[0]);
for (int x = 0; x < 8; x++) {
suma[y * 8 + x] = Parse<int>(str[x]);
}
}
}
}
for (int i = 1; i <= 64; i++) {
pieces[i] = Texture(Format(root, U"pieces/p_", i, U".png"));
}
int s = -1;
while (System::Update())
{
if (KeyEnter.down()) {
TextWriter tex(U"ans.txt");
for (int y = 0; y < 8; y++) {
for (int x = 0; x < 8; x++) {
tex.write(suma[y * 8 + x], U" ");
}
tex.write(U"\n");
}
}
for (int y = 0; y < 8; y++) {
for (int x = 0; x < 8; x++) {
if (y * 8 + x == s) {
pieces[suma[y * 8 + x]].draw(cellSize * Point(x, y)).drawFrame(1.0, Palette::Yellow);
}
else {
pieces[suma[y * 8 + x]].draw(cellSize * Point(x, y)).drawFrame(1.0, Palette::Black);
}
if (Rect(cellSize * Point(x, y), cellSize).leftClicked()) {
if (s == -1) {
s = y * 8 + x;
}
else {
std::swap(suma[y * 8 + x], suma[s]);
s = -1;
}
}
ans(cellSize * Point(x, y), cellSize).draw(cellSize * Point(x + 9, y)).drawFrame(1.0, Palette::Black);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment