-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
executable file
·115 lines (111 loc) · 2.58 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
//
// main.cpp
// TTTGame
//
// Created by åæˆ ä¸?on 16/9/9.
// Copyright © 2016�Zicheng Wan. All rights reserved.
//
#include <iostream>
#include <string>
#include <sstream>
#include "controller/TTTController.h"
#include "rapidjson/document.h"
#include "rapidjson/writer.h"
#include "rapidjson/stringbuffer.h"
using namespace std;
int main(){
cout<<"Content-Type:text/html\n\n";
stringstream post;
post<<cin.rdbuf();
string command = post.str();
string method = "";
string input = "";
const char* j = command.c_str();
rapidjson::Document document;
if(document.Parse(j).HasParseError()){
cout << "Failed to load JSON object" << endl;
}
rapidjson::Value& methodj = document["controllerMethod"];
method = methodj.GetString();
rapidjson::Value& inputj = document["input"];
rapidjson::StringBuffer buffer;
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
inputj.Accept(writer);
input = buffer.GetString();
/*
while(1){
if(*j == ':'){
j++;
while(*j != ','){
stringstream stream;
stream << *j++;
method.append(stream.str());
}
break;
}
j++;
}
while(1){
if(*j == ':'){
j++;
while(*j != '}'){
stringstream stream;
stream << *j++;
input.append(stream.str());
}
break;
}
j++;
}
*/
TTTController controller;
if(method == "getAllSavedPlayers"){
cout << controller.getAllSavedPlayers();
}
if(method == "createPlayer"){
controller.createPlayer(input);
}
if(method == "setSelection1"){
controller.setSelection1(input);
}
if(method == "setSelection"){
controller.setSelection(input);
}
if(method == "restart"){
ofstream Ofile("./grid.txt", ios::out);
Ofile << "";
Ofile.close();
Ofile.open("./grid0.txt", ios::out);
Ofile << "";
Ofile.close();
Ofile.open("./grid1.txt", ios::out);
Ofile << "";
Ofile.close();
Ofile.open("./grid2.txt", ios::out);
Ofile << "";
Ofile.close();
Ofile.open("./grid3.txt", ios::out);
Ofile << "";
Ofile.close();
Ofile.open("./grid4.txt", ios::out);
Ofile << "";
Ofile.close();
Ofile.open("./grid5.txt", ios::out);
Ofile << "";
Ofile.close();
Ofile.open("./grid6.txt", ios::out);
Ofile << "";
Ofile.close();
Ofile.open("./grid7.txt", ios::out);
Ofile << "";
Ofile.close();
Ofile.open("./grid8.txt", ios::out);
Ofile << "";
Ofile.close();
Ofile.open("./grid9.txt", ios::out);
Ofile << "";
Ofile.close();
}
//cout << controller.getGameDisplay() << endl;
return 0;
}