1 #include "Controller.h"
8 Controller::Controller(Game
*game
)
13 _is_empty
[i
][j
] = true;
14 _is_highlighted
[i
][j
] = false;
15 _highlight
[i
][j
] = false;
18 _has_highlight
= false;
21 _game
->fill_pieces(&**_is_empty
, &**_piece
);
24 Controller::~Controller()
28 void Controller::click(int x
, int y
)
30 printf("Click: (%i, %i)\n", x
, y
);
32 if(!_is_playing
) return;
35 if(_is_highlighted
[x
][y
]) {
36 if(x
== _last_click_x
&& y
== _last_click_y
) {
41 // realiza movimento de (_last_click_x, _last_click_y) para (x, y)
42 _game
->move(_last_click_x
, _last_click_y
, x
, y
);
50 if(can_highlight(x
, y
)) {
51 _has_highlight
= true;
52 _is_highlighted
[x
][y
] = true;
55 // possibilidades de movimento
56 _game
->fill_moves(x
, y
, &**_is_highlighted
);
64 void Controller::set_minimax_depth(int minimaxDepth
)
67 printf("minimaxDepth: %i\n", minimaxDepth
);
68 _game
->set_minimax_depth(minimaxDepth
);
71 void Controller::set_first_move(int firstMove
)
73 printf("firstMove: %i\n", firstMove
);
74 _game
->set_player(firstMove
);
77 void Controller::set_computer_color(int computerColor
)
79 printf("computerColor: %i\n", computerColor
);
80 _game
->set_computer_color(computerColor
);
83 void Controller::set_window(Window
*window
)
88 void Controller::play()
93 _window
->disable_all();
94 _window
->enable("stop");
98 void Controller::stop()
103 _window
->enable_all();
104 _window
->disable("stop");
108 void Controller::undo()
114 void Controller::redo()
120 void Controller::load(FILE *in
)
126 void Controller::after_display()
128 if(_is_playing
&& _game
->think()) {
133 bool Controller::is_empty(int x
, int y
)
135 return _is_empty
[x
][y
];
138 int Controller::piece(int x
, int y
)
143 bool Controller::is_highlighted(int x
, int y
)
145 return _is_highlighted
[x
][y
];
148 int Controller::highlight(int x
, int y
)
150 return _highlight
[x
][y
];
153 void Controller::clear_highlight()
157 _is_highlighted
[i
][j
] = false;
158 _highlight
[i
][j
] = false;
160 _has_highlight
= false;
161 _last_click_x
= _last_click_y
= -1;
164 bool Controller::can_highlight(int x
, int y
)
166 return _game
->can_move(x
, y
);
169 void Controller::update_all()
171 int fromX
, fromY
, toX
, toY
;
172 _game
->fill_pieces(&**_is_empty
, &**_piece
);
174 _game
->get_last_move(fromX
, fromY
, toX
, toY
);
176 _is_highlighted
[fromX
][fromY
] = _is_highlighted
[toX
][toY
] = true;
177 _highlight
[fromX
][fromY
] = _highlight
[toX
][toY
] = 1;
179 if(_game
->can_undo()) _window
->enable("undo");
180 else _window
->disable("undo");
181 if(_game
->can_redo()) _window
->enable("redo");
182 else _window
->disable("redo");
183 if(_game
->is_end() && _is_playing
) {
188 //printf("digite\n");