diff --git a/Controller.cpp b/Controller.cpp index 2d80858..dd98d36 100644 --- a/Controller.cpp +++ b/Controller.cpp @@ -1,52 +1,30 @@ #include "Controller.h" -#include "utils.h" -#include Controller::Controller(Drawer& drawer): drawer(drawer) {}; void Controller::resize(const wxSize& tableSize) { wxSize& resolution = drawer.resolution; - wxSize& gridSize = drawer.gridSize; + Dimensions& gridSize = drawer.gridSize; wxRect& tablePixelRect = drawer.tablePixelRect; resolution = tableSize; - int gridPoint = min(resolution.x / (gridSize.x * TILE_WIDTH), - resolution.y / (gridSize.y * TILE_HEIGHT)); - - if (gridPoint > 2) { - tablePixelRect.SetSize({gridPoint * TILE_WIDTH * gridSize.x, gridPoint * TILE_HEIGHT * gridSize.y}); + if (stopwatch >= 0) { + int gridPoint = min(resolution.x / (gridSize.x * TILE_WIDTH), + resolution.y / (gridSize.y * TILE_HEIGHT)); + + if (gridPoint > 2) { + tablePixelRect.SetSize({gridPoint * TILE_WIDTH * gridSize.x, gridPoint * TILE_HEIGHT * gridSize.y}); - drawer.tilePixelSize.Set(gridPoint * TILE_WIDTH, gridPoint * TILE_HEIGHT); + drawer.tilePixelSize.Set(gridPoint * TILE_WIDTH, gridPoint * TILE_HEIGHT); + } + + tablePixelRect.SetPosition({(resolution.x - tablePixelRect.width) / 2, + (resolution.y - tablePixelRect.height) / 2}); } - tablePixelRect.SetPosition({(resolution.x - tablePixelRect.width) / 2, - (resolution.y - tablePixelRect.height) / 2}); - drawer.setBG(tableSize); - drawer.initScreen(tableSize, table); -} - -wxPoint Controller::toGrid(const wxPoint& point) { - wxPoint out(-1, -1); - - wxRect& tablePixelRect = drawer.tablePixelRect; - - if (point.x >= tablePixelRect.x && - point.x <= tablePixelRect.x + tablePixelRect.width && - point.y >= tablePixelRect.y && - point.y <= tablePixelRect.y + tablePixelRect.height) - { - out.x = (point.x - tablePixelRect.x) / drawer.tilePixelSize.x; - out.y = (point.y - tablePixelRect.y) / drawer.tilePixelSize.y; - } - - return out; -} - -wxPoint Controller::fromGrid(const wxPoint& point) { - return { drawer.tablePixelRect.x + point.x * drawer.tilePixelSize.x, - drawer.tablePixelRect.y + point.y * drawer.tilePixelSize.y }; + drawer.initScreen(table); } void Controller::loadLayout(const wxString& path) { @@ -54,72 +32,241 @@ void Controller::loadLayout(const wxString& path) { drawer.gridSize = layout.getDimensions(); - table = TLVec(drawer.gridSize.x, wxVector>(drawer.gridSize.y, wxVector())); + table = TLVec(drawer.gridSize.z, vector>(drawer.gridSize.x, vector(drawer.gridSize.y, -2))); layout.readLayout(table); + + remaining = layout.getTilesNumber(); + + if (remaining == 144) { + for (int i = 0; i < 34; i++) + cardsCounter[i] = 4; + for (int i = 34; i < TILE_IMAGES_N; i++) + cardsCounter[i] = 1; + } } -TLVec* Controller::getTable() { - return &table; +TLVec& Controller::getTable() { + return table; } -TLSquare* Controller::getCardByPosition(const wxPoint& point) { +void Controller::fillSolveableTable() { + time_t start_time = time(NULL); + + auto& gridSize = drawer.gridSize; + + std::list positions; + + int overall = gridSize.z * gridSize.x * gridSize.y; + int pos = rand() % overall; + int z, x, y; + + do { + z = pos / (gridSize.x * gridSize.y); + x = (pos / gridSize.y) % gridSize.x; + y = pos % gridSize.y; + } while (table[z][x][y] != -1); + + positions.push_back({z, x, y}); + + int past_pos = 0; + auto past_ptr = positions.begin(); + + while (!positions.empty()) { + int id = genRandId(); + + if (id < 34) { + past_pos = emplace_rand(id, positions, past_pos, past_ptr); + past_pos = emplace_rand(id, positions, past_pos, past_ptr); + + cardsCounter[id]--; + } else + emplace_rand(id, positions, past_pos, past_ptr); + } + + wxLogInfo(wxString::Format("Filling took %i seconds", start_time - time(NULL))); +} + +int Controller::emplace_rand(int id, std::list positions, int past_pos, std::list::iterator past_ptr) { + int d = rand() % positions.size() - past_pos; + + if (d > 0) + for (int i = 0; i < d; i++) + past_ptr++; + else + for (int i = 0; i > d; i--) + past_ptr--; + + past_pos += d; + + table[past_ptr->z][past_ptr->x][past_ptr->y] = id; + + // if () + // positions.push_back({}) + + /** + * TODO: random move and positions adding + */ + + return 0; +} + +void Controller::fillRandom() { + srand(time(NULL)); + int not_end = remaining; + + for (int z = 0; z < drawer.gridSize.z && not_end; z++) + for (int x = 0; x < drawer.gridSize.x && not_end; x++) + for (int y = 0; y < drawer.gridSize.y && not_end; y++) + if (table[z][x][y] == -1) { + table[z][x][y] = genRandId(); + not_end--; + } +} + +int Controller::genRandId() { + int id; + + int w = 0; + + do { + id = rand() % TILE_IMAGES_N; + w++; + } while (cardsCounter[id] == 0); + + cardsCounter[id]--; + + return id; +} + +/** + * It also changes point to top right coordinate of card +*/ +CardT* Controller::getCardByPosition(ThreePoint& point) { int8_t topIndex = -1; - auto res = table[0][0].rend(); + CardT* res = nullptr; - for (auto el = table[point.x][point.y].rbegin(); el != table[point.x][point.y].rend(); ++el) - if (el->second != (uint8_t)-1) { - auto d = el->first; - if (d > topIndex) { - topIndex = d; - res = el; + ThreePoint realPos = point; + + for (int z = table.size() - 1; z >= 0; z--) + if (table[z][point.x][point.y] >= 0) { + if (z > topIndex) { + topIndex = z; + res = &table[z][point.x][point.y]; } break; } if (point.x > 0) - for (auto el = table[point.x-1][point.y].rbegin(); el != table[point.x-1][point.y].rend(); ++el) - if (el->second != (uint8_t)-1) { - auto d = el->first; - if (d > topIndex) { - topIndex = d; - res = el; + for (int z = table.size() - 1; z >= 0; z--) + if (table[z][point.x-1][point.y] >= 0) { + if (z > topIndex) { + topIndex = z; + res = &table[z][point.x-1][point.y]; + + realPos.x = point.x - 1; + realPos.y = point.y; } break; } if (point.y > 0) - for (auto el = table[point.x][point.y-1].rbegin(); el != table[point.x][point.y-1].rend(); ++el) - if (el->second != (uint8_t)-1) { - auto d = el->first; - if (d > topIndex) { - topIndex = d; - res = el; + for (int z = table.size() - 1; z >= 0; z--) + if (table[z][point.x][point.y-1] >= 0) { + if (z > topIndex) { + topIndex = z; + res = &table[z][point.x][point.y-1]; + + realPos.x = point.x; + realPos.y = point.y - 1; } break; } if (point.x > 0 && point.y > 0) - for (auto el = table[point.x-1][point.y-1].rbegin(); el != table[point.x-1][point.y-1].rend(); ++el) - if (el->second != (uint8_t)-1) { - auto d = el->first; - if (d > topIndex) { - topIndex = d; - res = el; + for (int z = table.size() - 1; z >= 0; z--) + if (table[z][point.x-1][point.y-1] >= 0) { + if (z > topIndex) { + topIndex = z; + res = &table[z][point.x-1][point.y-1]; + + realPos.x = point.x - 1; + realPos.y = point.y - 1; } break; } - return &(*res); + point.x = realPos.x; + point.y = realPos.y; + point.z = topIndex; + + return res; } -void Controller::select(TLSquare* card) { - if (selected != nullptr && selected->second == card->second && selected != card) { - selected->second = -1; - card->second = -1; - selected = nullptr; - - drawer.initScreen(drawer.tableSize, table); - } else - selected = card; +bool Controller::available(const ThreePoint& point) { + return upFree(point) && sideFree(point); +} + +bool Controller::upFree(const ThreePoint& point) { + + if (point.z == table.size() - 1) + return true; + + return !( + (table[point.z + 1][point.x][point.y] >= 0) || + (point.x > 0 && table[point.z + 1][point.x - 1][point.y] >= 0) || + (point.y > 0 && table[point.z + 1][point.x][point.y - 1] >= 0) || + (point.x > 0 && point.y > 0 && table[point.z + 1][point.x - 1][point.y - 1] >= 0) || + (point.x < table[point.z].size() - 1 && table[point.z + 1][point.x + 1][point.y] >= 0) || + (point.y < table[point.z][point.x].size() - 1 && table[point.z + 1][point.x][point.y + 1] >= 0) || + (point.x < table[point.z].size() - 1 && point.y < table[point.z][point.x].size() - 1 && table[point.z + 1][point.x + 1][point.y + 1] >= 0) || + (point.x > 0 && point.y < table[point.z][point.x].size() - 1 && table[point.z + 1][point.x - 1][point.y + 1] >= 0) || + (point.x < table[point.z].size() - 1 && point.y > 0 && table[point.z + 1][point.x + 1][point.y - 1] >= 0) + ); +} + +bool Controller::sideFree(const ThreePoint& point) { + bool lfree = true; + bool rfree = true; + + if (point.x > 1) + lfree = !( + (point.y > 0 && table[point.z][point.x-2][point.y-1] >= 0) || + (table[point.z][point.x-2][point.y] >= 0) || + (point.y < table[point.z][point.x].size() - 1 && table[point.z][point.x-2][point.y+1] >= 0) + ); + + if (point.x < table[point.z].size() - 2) + rfree = !( + (point.y > 0 && table[point.z][point.x+2][point.y-1] >= 0) || + (table[point.z][point.x+2][point.y] >= 0) || + (point.y < table[point.z][point.x].size() - 1 && table[point.z][point.x+2][point.y+1] >= 0) + ); + + return lfree || rfree; +} + +void Controller::select(CardT* card) { + wxLogDebug(wxString::Format("%i %p", *card, card)); + + if (selected != nullptr && sameValues(*card, *selected) && selected != card) { + *selected = -3; + *card = -3; + selected = nullptr; + + drawer.marked = {-1, -1, -1}; + } else + selected = card; + + drawer.initScreen(table); +} + +bool Controller::sameValues(CardT a, CardT b) { + if (a == b) return true; + else if (a >= 38 && b >= 38) + return true; + else if (a >= 34 && a <= 37 && b >= 34 && b <= 37) + return true; + + return false; } diff --git a/Controller.h b/Controller.h index 58a994a..5049391 100644 --- a/Controller.h +++ b/Controller.h @@ -1,6 +1,9 @@ #ifndef CONTROLLER_H #define CONTROLLER_H +#include +#include + #include "wxw.h" #include "Drawer.h" @@ -10,27 +13,41 @@ class Controller { public: Controller(Drawer& drawer); - int stopwatch = 0; + int stopwatch = -1; void resize(const wxSize& tableSize); void loadLayout(const wxString& path); - wxPoint toGrid(const wxPoint& point); - wxPoint fromGrid(const wxPoint& point); + bool available(const ThreePoint& point); + bool upFree(const ThreePoint& point); + bool sideFree(const ThreePoint& point); - void select(TLSquare* card); + void select(CardT* card); - TLVec* getTable(); + TLVec& getTable(); - TLSquare* getCardByPosition(const wxPoint& point); + void fillSolveableTable(); + void fillRandom(); + + CardT* getCardByPosition(ThreePoint& point); + + std::arraycardsCounter; + + uint8_t remaining; private: Drawer& drawer; XmlLayout layout; TLVec table; - TLSquare* selected = nullptr; + CardT* selected = nullptr; + + int emplace_rand(int id, std::list positions, int past_pos, std::list::iterator past_ptr); + + int genRandId(); + + bool sameValues(CardT a, CardT b); }; #endif diff --git a/Drawer.cpp b/Drawer.cpp index 94eb5b6..4f5d7d8 100644 --- a/Drawer.cpp +++ b/Drawer.cpp @@ -1,11 +1,16 @@ #include "Drawer.h" -#define TILE_IMAGES_N 37 -static const char* tileImageNames[] = { "Back", "Blank", "Chun", "Front", "Haku", "Hatsu", "Man1", "Man2", "Man3", "Man4", "Man5", "Man6", "Man7", "Man8", "Man9", "Nan", "Pei", "Pin1", "Pin2", "Pin3", "Pin4", "Pin5", "Pin6", "Pin7", "Pin8", "Pin9", "Shaa", "Sou1", "Sou2", "Sou3", "Sou4", "Sou5", "Sou6", "Sou7", "Sou8", "Sou9", "Ton" }; +static const char* tileImageNames[] = { "Pin1", "Pin2", "Pin3", "Pin4", "Pin5", "Pin6", "Pin7", "Pin8", "Pin9", "Sou1", "Sou2", "Sou3", "Sou4", "Sou5", "Sou6", "Sou7", "Sou8", "Sou9", "Man1", "Man2", "Man3", "Man4", "Man5", "Man6", "Man7", "Man8", "Man9", "Chun", "Haku", "Hatsu", "Nan", "Pei", "Shaa", "Ton", "Flower1", "Flower2", "Flower3", "Flower4", "Season1", "Season2", "Season3", "Season4" }; -Drawer::Drawer() { - for (int i = 0; i < 37; i++) - tileImages[i].LoadFile(_("./resources/tiles/") + _(tileImageNames[i]) + _(".png"), wxBITMAP_TYPE_PNG); +/** + * TODO: fix not loading last two tiles icons + */ + +Drawer::Drawer(): marked{-1, -1, -1} { + for (int i = 0; i < TILE_IMAGES_N; i++) { + if (!tileImages[i].LoadFile(_("./resources/tiles/") + _(tileImageNames[i]) + _(".png"), wxBITMAP_TYPE_PNG)) + wxLogDebug(_("./resources/tiles/") + _(tileImageNames[i]) + _(".png ") + wxString::Format(wxT("%i"), i)); + } } void Drawer::drawTable(wxDC& dc) { @@ -28,33 +33,46 @@ void Drawer::setBG(const wxSize& tableSize) { isBgReady = true; } -void Drawer::initScreen(const wxSize& tableSize, const TLVec& layout) { +wxPoint Drawer::toGrid(const wxPoint& point) { + wxPoint out(-1, -1); + + if (point.x >= tablePixelRect.x && + point.x <= tablePixelRect.x + tablePixelRect.width && + point.y >= tablePixelRect.y && + point.y <= tablePixelRect.y + tablePixelRect.height) + { + out.x = (point.x - tablePixelRect.x) / tilePixelSize.x; + out.y = (point.y - tablePixelRect.y) / tilePixelSize.y; + } + + return out; +} + +wxPoint Drawer::fromGrid(int x, int y) { + return { tablePixelRect.x + x * tilePixelSize.x, + tablePixelRect.y + y * tilePixelSize.y }; +} + +wxPoint Drawer::fromGrid(const wxPoint& point) { + return fromGrid(point.x, point.y); +} + +void Drawer::initScreen(const TLVec& layout) { if (isBgReady) { screenBitmap = copyBitmap(bgBitmap); + wxLogDebug(_("Reinit")); + wxMemoryDC dc; dc.SelectObject(screenBitmap); - int cards_set = -1; - uint8_t layer = -1; - - while (cards_set) { - layer++; - cards_set = 0; - - for (int i = 0; i < layout.size(); i++) - for (int j = 0; j < layout[i].size(); j++) { - int k = layout[i][j].size() - 1; - while (k > -1 && layout[i][j][k].second == (uint8_t)-1) - k--; - - if (k > -1) - if (layout[i][j][k].first == layer || layer == 0) { - drawTile(dc, layout[i][j][k].second, {tablePixelRect.x + tilePixelSize.x*i, tablePixelRect.y + tilePixelSize.y*j}, layer); - cards_set++; - } - } - } + for (int z = 0; z < gridSize.z; z++) + for (int x = 0; x < gridSize.x; x++) + for (int y = 0; y < gridSize.y; y++) { + CardT c = layout[z][x][y]; + if (c >= 0) + drawTile(dc, c, fromGrid(x, y), z); + } isScreenReady = true; } @@ -62,16 +80,29 @@ void Drawer::initScreen(const wxSize& tableSize, const TLVec& layout) { void Drawer::drawTile(wxDC& dc, int8_t index, const wxPoint& position, uint8_t zIndex) { wxBrush _bgColor = dc.GetBrush(); - dc.SetBrush(wxColor(200, 200, 200)); + + wxBrush front = wxColor(255, 255, 255); + wxBrush back = wxColor(200, 200, 200); + + if (position == fromGrid({marked.x, marked.y}) && marked.z == zIndex) { + front = wxColor(200, 255, 200); + back = wxColor(190, 220, 190); + } + + dc.SetBrush(back); dc.DrawRoundedRectangle(position.x + (tilePixelSize.GetWidth()/10 + 3) - (tilePixelSize.GetWidth()/10 + 3)*zIndex, position.y + (tilePixelSize.GetHeight()/10 + 3) - (tilePixelSize.GetHeight()/10 + 3)*zIndex, tilePixelSize.GetWidth() * 2, tilePixelSize.GetHeight() * 2, 10); - dc.SetBrush(_bgColor); + dc.SetBrush(front); dc.DrawRoundedRectangle(position.x - (tilePixelSize.GetWidth()/10 + 3)*zIndex, position.y - (tilePixelSize.GetHeight()/10 + 3)*zIndex, tilePixelSize.GetWidth() * 2, tilePixelSize.GetHeight() * 2, 10); - if (tileImages[index].GetWidth() != tilePixelSize.x * 2) - dc.DrawBitmap(tileImages[index].Scale(tilePixelSize.x * 2 - 20, tilePixelSize.y * 2 - 20), {position.x + 10 - (tilePixelSize.GetWidth()/10 + 3)*zIndex, position.y + 10 - (tilePixelSize.GetHeight()/10 + 3)*zIndex}); - else - dc.DrawBitmap(tileImages[index], {position.x + 10 - (tilePixelSize.GetWidth()/10 + 3)*zIndex, position.y + 10 - (tilePixelSize.GetHeight()/10 + 3)*zIndex}); + dc.SetBrush(_bgColor); + + if (tileImages[index].IsOk()) { + if (tileImages[index].GetWidth() != tilePixelSize.x * 2) + dc.DrawBitmap(tileImages[index].Scale(tilePixelSize.x * 2 - 20, tilePixelSize.y * 2 - 20), {position.x + 10 - (tilePixelSize.GetWidth()/10 + 3)*zIndex, position.y + 10 - (tilePixelSize.GetHeight()/10 + 3)*zIndex}); + else + dc.DrawBitmap(tileImages[index], {position.x + 10 - (tilePixelSize.GetWidth()/10 + 3)*zIndex, position.y + 10 - (tilePixelSize.GetHeight()/10 + 3)*zIndex}); + } } diff --git a/Drawer.h b/Drawer.h index e63684b..aaa1cfe 100644 --- a/Drawer.h +++ b/Drawer.h @@ -8,6 +8,8 @@ #define TILE_HEIGHT 8 #define TILE_WIDTH 6 +#define TILE_IMAGES_N 42 + class Drawer { public: Drawer(); @@ -18,11 +20,17 @@ public: wxSize tilePixelSize; // 600x800 wxSize resolution; - wxSize gridSize; + Dimensions gridSize; wxRect tablePixelRect; void setBG(const wxSize& tableSize); - void initScreen(const wxSize& tableSize, const TLVec& layout); + void initScreen(const TLVec& layout); + + wxPoint toGrid(const wxPoint& point); + wxPoint fromGrid(int x, int y); + wxPoint fromGrid(const wxPoint& point); + + ThreePoint marked; private: void drawScreen(wxDC& dc); diff --git a/GamePanel.cpp b/GamePanel.cpp index 8ee30d7..7015b16 100644 --- a/GamePanel.cpp +++ b/GamePanel.cpp @@ -4,7 +4,7 @@ #include "utils.h" -GamePanel::GamePanel(wxFrame* parent) : wxPanel(parent), controller(drawer), sb(parent->GetStatusBar()) { +GamePanel::GamePanel(wxFrame* parent) : wxPanel(parent), controller(drawer) { SetBackgroundStyle(wxBG_STYLE_PAINT); Bind(wxEVT_PAINT, &GamePanel::OnPaint, this); @@ -12,21 +12,25 @@ GamePanel::GamePanel(wxFrame* parent) : wxPanel(parent), controller(drawer), sb( this->controller.resize(evt.GetSize()); }); - timer = new wxTimer(this); + timer = new wxTimer(this, 1); Bind(wxEVT_TIMER, &GamePanel::OnTimer, this, timer->GetId()); Bind(wxEVT_LEFT_DOWN, &GamePanel::OnClick, this); } -void GamePanel::Start(const wxString& path) { +void GamePanel::Start(const wxString& path, bool solveable) { controller.stopwatch = 0; controller.loadLayout(path); + if (solveable) + controller.fillSolveableTable(); + else + controller.fillRandom(); timer->Start(1000, wxTIMER_CONTINUOUS); + + if (sb == nullptr) + sb = ((wxFrame*)this->GetParent())->GetStatusBar(); sb->SetStatusText(LTimeToStr(controller.stopwatch)); - - - drawer.initScreen(drawer.tableSize, *controller.getTable()); } void GamePanel::OnPaint(wxPaintEvent& _) { @@ -41,13 +45,17 @@ void GamePanel::OnTimer(wxTimerEvent& _) { } void GamePanel::OnClick(wxMouseEvent& _) { - wxPoint res = controller.toGrid(ScreenToClient(wxGetMousePosition())); + wxPoint posPlain = drawer.toGrid(ScreenToClient(wxGetMousePosition())); - if (res.x > -1) { - auto card = controller.getCardByPosition(res); - if (card != nullptr) { + ThreePoint pos = {-1, posPlain.x, posPlain.y}; + + if (pos.x > -1) { + auto card = controller.getCardByPosition(pos); + + drawer.marked = pos; + + if (pos.z >= 0 && controller.available(pos)) controller.select(card); - } } Refresh(); diff --git a/GamePanel.h b/GamePanel.h index af2f63c..9056a45 100644 --- a/GamePanel.h +++ b/GamePanel.h @@ -12,7 +12,7 @@ class GamePanel : public wxPanel { public: GamePanel(wxFrame* parent); - void Start(const wxString& path); + void Start(const wxString& path, bool solveable); private: Drawer drawer; diff --git a/MainFrame.cpp b/MainFrame.cpp index dc8964c..a727450 100644 --- a/MainFrame.cpp +++ b/MainFrame.cpp @@ -23,6 +23,7 @@ void MainFrame::initMenu() { wxMenu *menuGame = new wxMenu; menuGame->Append(IDM_New_Game, _("Начать сначала")); menuGame->Append(IDM_Open, _("Открыть карту")); + menuGame->AppendCheckItem(IDM_Solveable, _("Генерировать решаемую карту")); menuGame->AppendSeparator(); menuGame->Append(IDM_Exit, _("Выход")); @@ -63,10 +64,14 @@ void MainFrame::bindMenu() { if (layoutPath.IsEmpty()) openLayout(); else - panel->Start(layoutPath); + panel->Start(layoutPath, solveable); Refresh(); }, IDM_New_Game); + + Bind(wxEVT_MENU, [this](wxCommandEvent& _) -> void { + solveable = _.IsChecked(); + }, IDM_Solveable); } void MainFrame::openLayout() { @@ -77,5 +82,5 @@ void MainFrame::openLayout() { layoutPath = openFileDlg.GetPath(); - panel->Start(layoutPath); + panel->Start(layoutPath, solveable); } diff --git a/MainFrame.h b/MainFrame.h index e8dc20b..226ae91 100644 --- a/MainFrame.h +++ b/MainFrame.h @@ -24,6 +24,8 @@ private: const wxString dataDirPath; wxString layoutPath; + + bool solveable = false; }; enum @@ -33,7 +35,8 @@ enum IDM_Help = wxID_HELP, IDM_About = wxID_ABOUT, IDM_Rules = wxID_HIGHEST + 1, - IDM_New_Game + IDM_New_Game, + IDM_Solveable }; #endif diff --git a/XmlLayout.cpp b/XmlLayout.cpp index 6a44dcc..c959f20 100644 --- a/XmlLayout.cpp +++ b/XmlLayout.cpp @@ -15,8 +15,9 @@ bool XmlLayout::openFile(const wxString& openPath) { return true; } -wxSize XmlLayout::getDimensions() { - return { wxAtoi(layoutDoc.GetRoot()->GetAttribute("ux")) + 2, +Dimensions XmlLayout::getDimensions() { + return { wxAtoi(layoutDoc.GetRoot()->GetAttribute("layers")), + wxAtoi(layoutDoc.GetRoot()->GetAttribute("ux")) + 2, wxAtoi(layoutDoc.GetRoot()->GetAttribute("uy")) + 2 }; } @@ -29,13 +30,15 @@ void XmlLayout::readLayout(TLVec& table) { if (tilePtr->GetName().IsSameAs("tile")) { x = wxAtoi(tilePtr->GetAttribute("x")); y = wxAtoi(tilePtr->GetAttribute("y")); - l = wxAtoi(tilePtr->GetAttribute("layer")); + l = wxAtoi(tilePtr->GetAttribute("layer")) - 1; - table[x][y].push_back(std::make_pair(l - 1, (uint8_t)-1)); - - table[x][y].at(table[x][y].size() -1).second = (random()) % 37; + table[l][x][y] = -1; } tilePtr = tilePtr->GetNext(); } } + +uint8_t XmlLayout::getTilesNumber() { + return wxAtoi(layoutDoc.GetRoot()->GetAttribute("tiles")); +} \ No newline at end of file diff --git a/XmlLayout.h b/XmlLayout.h index c5d98c8..1d2e7f4 100644 --- a/XmlLayout.h +++ b/XmlLayout.h @@ -12,8 +12,9 @@ public: XmlLayout(); bool openFile(const wxString& path); - wxSize getDimensions(); + Dimensions getDimensions(); void readLayout(TLVec& table); + uint8_t getTilesNumber(); private: wxString path; diff --git a/resources/tiles/Back.png b/resources/tiles/Back.png deleted file mode 100644 index b7a1e2e..0000000 Binary files a/resources/tiles/Back.png and /dev/null differ diff --git a/resources/tiles/Blank.png b/resources/tiles/Blank.png deleted file mode 100644 index 1f9160f..0000000 Binary files a/resources/tiles/Blank.png and /dev/null differ diff --git a/resources/tiles/Chun.png b/resources/tiles/Chun.png index b79b4c3..111e957 100644 Binary files a/resources/tiles/Chun.png and b/resources/tiles/Chun.png differ diff --git a/resources/tiles/Flower1.png b/resources/tiles/Flower1.png new file mode 100644 index 0000000..2f8f3b1 Binary files /dev/null and b/resources/tiles/Flower1.png differ diff --git a/resources/tiles/Flower2.png b/resources/tiles/Flower2.png new file mode 100644 index 0000000..5da8e32 Binary files /dev/null and b/resources/tiles/Flower2.png differ diff --git a/resources/tiles/Flower3.png b/resources/tiles/Flower3.png new file mode 100644 index 0000000..5c3921d Binary files /dev/null and b/resources/tiles/Flower3.png differ diff --git a/resources/tiles/Flower4.png b/resources/tiles/Flower4.png new file mode 100644 index 0000000..9d882e7 Binary files /dev/null and b/resources/tiles/Flower4.png differ diff --git a/resources/tiles/Front.png b/resources/tiles/Front.png deleted file mode 100644 index 1734865..0000000 Binary files a/resources/tiles/Front.png and /dev/null differ diff --git a/resources/tiles/Haku.png b/resources/tiles/Haku.png index 14fc45b..cff9c0c 100644 Binary files a/resources/tiles/Haku.png and b/resources/tiles/Haku.png differ diff --git a/resources/tiles/Hatsu.png b/resources/tiles/Hatsu.png index e9e2032..61c73b1 100644 Binary files a/resources/tiles/Hatsu.png and b/resources/tiles/Hatsu.png differ diff --git a/resources/tiles/Man1.png b/resources/tiles/Man1.png index 3b4c323..a0a9e6c 100644 Binary files a/resources/tiles/Man1.png and b/resources/tiles/Man1.png differ diff --git a/resources/tiles/Man2.png b/resources/tiles/Man2.png index b589670..e55a816 100644 Binary files a/resources/tiles/Man2.png and b/resources/tiles/Man2.png differ diff --git a/resources/tiles/Man3.png b/resources/tiles/Man3.png index 777d4bf..c927186 100644 Binary files a/resources/tiles/Man3.png and b/resources/tiles/Man3.png differ diff --git a/resources/tiles/Man4.png b/resources/tiles/Man4.png index ba194d7..0e69ec2 100644 Binary files a/resources/tiles/Man4.png and b/resources/tiles/Man4.png differ diff --git a/resources/tiles/Man5-Dora.png b/resources/tiles/Man5-Dora.png deleted file mode 100644 index ae1f296..0000000 Binary files a/resources/tiles/Man5-Dora.png and /dev/null differ diff --git a/resources/tiles/Man5.png b/resources/tiles/Man5.png index db0e1e8..cd635fd 100644 Binary files a/resources/tiles/Man5.png and b/resources/tiles/Man5.png differ diff --git a/resources/tiles/Man6.png b/resources/tiles/Man6.png index 8209f7d..e408711 100644 Binary files a/resources/tiles/Man6.png and b/resources/tiles/Man6.png differ diff --git a/resources/tiles/Man7.png b/resources/tiles/Man7.png index 740b352..8828920 100644 Binary files a/resources/tiles/Man7.png and b/resources/tiles/Man7.png differ diff --git a/resources/tiles/Man8.png b/resources/tiles/Man8.png index 52747e8..39e83a8 100644 Binary files a/resources/tiles/Man8.png and b/resources/tiles/Man8.png differ diff --git a/resources/tiles/Man9.png b/resources/tiles/Man9.png index 76f3260..9295d01 100644 Binary files a/resources/tiles/Man9.png and b/resources/tiles/Man9.png differ diff --git a/resources/tiles/Nan.png b/resources/tiles/Nan.png index c95a0a4..084b4a4 100644 Binary files a/resources/tiles/Nan.png and b/resources/tiles/Nan.png differ diff --git a/resources/tiles/Pei.png b/resources/tiles/Pei.png index 0423a1a..33d1af4 100644 Binary files a/resources/tiles/Pei.png and b/resources/tiles/Pei.png differ diff --git a/resources/tiles/Pin1.png b/resources/tiles/Pin1.png index 788b122..29e2dad 100644 Binary files a/resources/tiles/Pin1.png and b/resources/tiles/Pin1.png differ diff --git a/resources/tiles/Pin2.png b/resources/tiles/Pin2.png index 24db919..78b4c99 100644 Binary files a/resources/tiles/Pin2.png and b/resources/tiles/Pin2.png differ diff --git a/resources/tiles/Pin3.png b/resources/tiles/Pin3.png index c9cb1db..7a04f73 100644 Binary files a/resources/tiles/Pin3.png and b/resources/tiles/Pin3.png differ diff --git a/resources/tiles/Pin4.png b/resources/tiles/Pin4.png index 8a62119..9341406 100644 Binary files a/resources/tiles/Pin4.png and b/resources/tiles/Pin4.png differ diff --git a/resources/tiles/Pin5-Dora.png b/resources/tiles/Pin5-Dora.png deleted file mode 100644 index af8a48e..0000000 Binary files a/resources/tiles/Pin5-Dora.png and /dev/null differ diff --git a/resources/tiles/Pin5.png b/resources/tiles/Pin5.png index e1262f8..ddb3805 100644 Binary files a/resources/tiles/Pin5.png and b/resources/tiles/Pin5.png differ diff --git a/resources/tiles/Pin6.png b/resources/tiles/Pin6.png index 6bdd1a5..7ef8c4b 100644 Binary files a/resources/tiles/Pin6.png and b/resources/tiles/Pin6.png differ diff --git a/resources/tiles/Pin7.png b/resources/tiles/Pin7.png index 8d25212..52b1c40 100644 Binary files a/resources/tiles/Pin7.png and b/resources/tiles/Pin7.png differ diff --git a/resources/tiles/Pin8.png b/resources/tiles/Pin8.png index 2f7e912..7e43cd1 100644 Binary files a/resources/tiles/Pin8.png and b/resources/tiles/Pin8.png differ diff --git a/resources/tiles/Pin9.png b/resources/tiles/Pin9.png index c615133..fdb2367 100644 Binary files a/resources/tiles/Pin9.png and b/resources/tiles/Pin9.png differ diff --git a/resources/tiles/Season1.png b/resources/tiles/Season1.png new file mode 100644 index 0000000..445450c Binary files /dev/null and b/resources/tiles/Season1.png differ diff --git a/resources/tiles/Season2.png b/resources/tiles/Season2.png new file mode 100644 index 0000000..406ad94 Binary files /dev/null and b/resources/tiles/Season2.png differ diff --git a/resources/tiles/Season3.png b/resources/tiles/Season3.png new file mode 100644 index 0000000..fd771e8 Binary files /dev/null and b/resources/tiles/Season3.png differ diff --git a/resources/tiles/Season4.png b/resources/tiles/Season4.png new file mode 100644 index 0000000..aa7d1f6 Binary files /dev/null and b/resources/tiles/Season4.png differ diff --git a/resources/tiles/Shaa.png b/resources/tiles/Shaa.png index 424bac9..86d0273 100644 Binary files a/resources/tiles/Shaa.png and b/resources/tiles/Shaa.png differ diff --git a/resources/tiles/Sou1.png b/resources/tiles/Sou1.png index 76c0cfe..54d394a 100644 Binary files a/resources/tiles/Sou1.png and b/resources/tiles/Sou1.png differ diff --git a/resources/tiles/Sou2.png b/resources/tiles/Sou2.png index ecdf96d..2e5a35d 100644 Binary files a/resources/tiles/Sou2.png and b/resources/tiles/Sou2.png differ diff --git a/resources/tiles/Sou3.png b/resources/tiles/Sou3.png index b6ab4de..5a3d23f 100644 Binary files a/resources/tiles/Sou3.png and b/resources/tiles/Sou3.png differ diff --git a/resources/tiles/Sou4.png b/resources/tiles/Sou4.png index 0cb592e..d46f4d9 100644 Binary files a/resources/tiles/Sou4.png and b/resources/tiles/Sou4.png differ diff --git a/resources/tiles/Sou5-Dora.png b/resources/tiles/Sou5-Dora.png deleted file mode 100644 index 84951f4..0000000 Binary files a/resources/tiles/Sou5-Dora.png and /dev/null differ diff --git a/resources/tiles/Sou5.png b/resources/tiles/Sou5.png index e0f4c31..85ae738 100644 Binary files a/resources/tiles/Sou5.png and b/resources/tiles/Sou5.png differ diff --git a/resources/tiles/Sou6.png b/resources/tiles/Sou6.png index 7230b84..9fcc97b 100644 Binary files a/resources/tiles/Sou6.png and b/resources/tiles/Sou6.png differ diff --git a/resources/tiles/Sou7.png b/resources/tiles/Sou7.png index 529065f..d8c24cd 100644 Binary files a/resources/tiles/Sou7.png and b/resources/tiles/Sou7.png differ diff --git a/resources/tiles/Sou8.png b/resources/tiles/Sou8.png index b8f09eb..0f37e65 100644 Binary files a/resources/tiles/Sou8.png and b/resources/tiles/Sou8.png differ diff --git a/resources/tiles/Sou9.png b/resources/tiles/Sou9.png index 45a542d..cef52ad 100644 Binary files a/resources/tiles/Sou9.png and b/resources/tiles/Sou9.png differ diff --git a/resources/tiles/Ton.png b/resources/tiles/Ton.png index 1f8fc63..8a9ff51 100644 Binary files a/resources/tiles/Ton.png and b/resources/tiles/Ton.png differ diff --git a/utils.h b/utils.h index 9ba189d..38e7958 100644 --- a/utils.h +++ b/utils.h @@ -3,6 +3,10 @@ #include "wxw.h" +#include + +using std::vector; + wxString LTimeToStr(int time); int upDiv(int a, int b); wxString itowxS(int a); @@ -10,7 +14,24 @@ wxString itowxS(int a); #define min(a, b) (a + b - abs(a - b)) / 2 #define max(a, b) (a + b + abs(a - b)) / 2 -using TLSquare = std::pair; -using TLVec = wxVector>>; +using CardT = int16_t; + +class Dimensions : public wxSize { +public: + Dimensions(int _z, int _x, int _y): wxSize(_x, _y), z(_z) {}; + Dimensions(): wxSize(), z(0) {}; + int z; +}; + +class ThreePoint { +public: + ThreePoint(int _z, int _x, int _y): x(_x), y(_y), z(_z) {}; + ThreePoint(): x(0), y(0), z(0) {}; + int x; + int y; + int z; +}; + +using TLVec = vector>>; #endif