#include "pch.h" #include "Puzzle.h" Cell Puzzle::GetCell(int x, int y) const { x = Mod(x); if (!SafeCell(x, y)) return Cell::Undefined(); return grid[x][y]; } Cell::Color Puzzle::GetLine(int x, int y) const { return grid[x][y].color; } void Puzzle::NewGrid(int newWidth, int newHeight) { if (newWidth == 0) { assert(false); newWidth = width; newHeight = height; } else { // @Cleanup! This should be in the ctor... width = 2*newWidth + 1; height = 2*newHeight + 1; } grid.clear(); grid.resize(width); for (int x=0; xcolor == Color::Black) j["color"] = "black"; else if (cell.decoration->color == Color::Blue) j["color"] = "blue"; else if (cell.decoration->color == Color::Cyan) j["color"] = "cyan"; else if (cell.decoration->color == Color::Gray) j["color"] = "gray"; else if (cell.decoration->color == Color::Green) j["color"] = "green"; else if (cell.decoration->color == Color::Orange) j["color"] = "orange"; else if (cell.decoration->color == Color::Pink) j["color"] = "pink"; else if (cell.decoration->color == Color::Purple) j["color"] = "purple"; else if (cell.decoration->color == Color::White) j["color"] = "white"; else if (cell.decoration->color == Color::Yellow) j["color"] = "yellow"; if (cell.decoration->type == Type::Stone) { j["type"] = "square"; } else if (cell.decoration->type == Type::Star) { j["type"] = "star"; } else if (cell.decoration->type == Type::Poly) { j["type"] = "poly"; j["polyshape"] = cell.decoration->polyshape; } else if (cell.decoration->type == Type::Ylop) { j["type"] = "ylop"; j["polyshape"] = cell.decoration->polyshape; } else if (cell.decoration->type == Type::Nega) { j["type"] = "nega"; } else if (cell.decoration->type == Type::Triangle) { j["type"] = "triangle"; j["count"] = cell.decoration->count; } } if (cell.start) j["start"] = true; if (cell.end != Cell::Dir::NONE) { if (cell.end == Cell::Dir::LEFT) j["end"] = "left"; else if (cell.end == Cell::Dir::RIGHT) j["end"] = "right"; else if (cell.end == Cell::Dir::UP) j["end"] = "top"; else if (cell.end == Cell::Dir::DOWN) j["end"] = "bottom"; } puzzle["grid"][x][y] = j; } } return puzzle.dump(); } int Puzzle::Mod(int x) const { if (!pillar) return x; return (x + width * height * 2) % width; } bool Puzzle::SafeCell(int x, int y) const { if (x < 0 || x >= width) return false; if (y < 0 || y >= height) return false; return true; }