1 | #include <stdio.h> |
---|
2 | |
---|
3 | class Model{ |
---|
4 | private: |
---|
5 | int board[10][10]; |
---|
6 | //? |
---|
7 | public: |
---|
8 | Model() { |
---|
9 | for(int i = 0; i < 10; i++) { |
---|
10 | for(int j = 0; j < 10; j++) { |
---|
11 | board[i][j] = -1; |
---|
12 | } |
---|
13 | } |
---|
14 | } |
---|
15 | |
---|
16 | bool move(int x, int y, bool isZero) { |
---|
17 | //? |
---|
18 | board[x][y] = isZero ? 0 : 1; |
---|
19 | } |
---|
20 | |
---|
21 | // Zero, Christ, Draw, Inprogress, |
---|
22 | int getState() const { |
---|
23 | //? |
---|
24 | return 0; |
---|
25 | } |
---|
26 | |
---|
27 | int getCell(int x, int y) const { |
---|
28 | //? |
---|
29 | return board[x][y]; |
---|
30 | } |
---|
31 | |
---|
32 | |
---|
33 | }; |
---|
34 | |
---|
35 | class View { |
---|
36 | private: |
---|
37 | Model* myModel; |
---|
38 | public: |
---|
39 | View(Model* m) { |
---|
40 | myModel = m; |
---|
41 | } |
---|
42 | |
---|
43 | void show() const { |
---|
44 | for(int i = 0; i < 10; i++) { |
---|
45 | for(int j = 0; j < 10; j++) { |
---|
46 | printf("%d", myModel->getCell(i, j)); |
---|
47 | } |
---|
48 | printf("\n"); |
---|
49 | } |
---|
50 | } |
---|
51 | |
---|
52 | void doGame() const { |
---|
53 | int isEnd = 1; |
---|
54 | while ( isEnd != 0 ) { |
---|
55 | //input from first player |
---|
56 | //myModel->move(i, j, player); |
---|
57 | //player = !player; |
---|
58 | show(); |
---|
59 | isEnd = myModel->getState(); |
---|
60 | } |
---|
61 | } |
---|
62 | |
---|
63 | }; |
---|
64 | |
---|
65 | class TestModel { |
---|
66 | public: |
---|
67 | void checkError(bool b, const char* f) { |
---|
68 | if(!b) { |
---|
69 | printf("Test failed in %s\n", f); |
---|
70 | |
---|
71 | } |
---|
72 | } |
---|
73 | |
---|
74 | void getStateTest() { |
---|
75 | Model m; |
---|
76 | m.move(1, 1, true); |
---|
77 | m.move(2, 2, false); |
---|
78 | |
---|
79 | checkError( m.getState()!= 0, __func__ ); |
---|
80 | |
---|
81 | } |
---|
82 | }; |
---|
83 | |
---|
84 | /* |
---|
85 | // test.cpp |
---|
86 | int main() { |
---|
87 | TestModel tm; |
---|
88 | tm.getStateTest(); |
---|
89 | return 0; |
---|
90 | } |
---|
91 | */ |
---|
92 | |
---|
93 | int main() { |
---|
94 | Model m; |
---|
95 | View v(&m); |
---|
96 | v.doGame(); |
---|
97 | return 0; |
---|
98 | } |
---|
99 | |
---|