aboutsummaryrefslogtreecommitdiff
path: root/src/main/game_state.cpp
diff options
context:
space:
mode:
authorthecharlesblake2017-10-24 01:23:00 +0100
committerthecharlesblake2017-10-26 14:51:33 +0100
commitc5e5d9d6bbd7d7d2a6c6463505e7b7031e846ebf (patch)
tree09bfac6f5499620317602cd8e8ab3c2933677a50 /src/main/game_state.cpp
parentAdd deal file parsing and verifying (diff)
downloadmetasol-c5e5d9d6bbd7d7d2a6c6463505e7b7031e846ebf.tar.gz
metasol-c5e5d9d6bbd7d7d2a6c6463505e7b7031e846ebf.zip

Draft of OO game logic

Diffstat (limited to 'src/main/game_state.cpp')
-rw-r--r--src/main/game_state.cpp51
1 files changed, 51 insertions, 0 deletions
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 <vector>
+#include <ostream>
+
+#include <rapidjson/document.h>
+
+#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<card> 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