From c5e5d9d6bbd7d7d2a6c6463505e7b7031e846ebf Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Tue, 24 Oct 2017 01:23:00 +0100 Subject: Draft of OO game logic --- src/main/game_state.cpp | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/main/game_state.cpp (limited to 'src/main/game_state.cpp') diff --git a/src/main/game_state.cpp b/src/main/game_state.cpp new file mode 100644 index 0000000..c6278e2 --- /dev/null +++ b/src/main/game_state.cpp @@ -0,0 +1,51 @@ +// +// Created by thecharlesblake on 10/23/17. +// + +#include +#include + +#include + +#include "game_state.h" + +using namespace std; +using namespace rapidjson; + +game_state::game_state(const Document& doc) { + const Value& json_tab_piles = doc["tableau piles"]; + assert(json_tab_piles.IsArray()); + + for (auto& json_tab : json_tab_piles.GetArray()) { + vector tableau_pile; + + for (auto& json_card : json_tab.GetArray()) { + tableau_pile.push_back(card(json_card.GetString())); + } + + tableau_piles.push_back(tableau_pile); + } +} + +ostream& game_state::print(ostream& stream) const { + bool empty_row = false; + int row_idx = 0; + + while (!empty_row) { + empty_row = true; + for (auto tableau_pile : tableau_piles) { + if (tableau_pile.size() > row_idx) { + empty_row = false; + stream << tableau_pile[row_idx]; + } + stream << "\t"; + } + stream << "\n"; + row_idx++; + } + return stream; +} + +ostream& operator <<(ostream& stream, const game_state& gs) { + return gs.print(stream); +} \ No newline at end of file -- cgit v1.2.1