fix: players now alternate after input
This commit is contained in:
+28
-8
@@ -8,30 +8,50 @@ void Input::get_input(bool &running, Player &one, Player &two, std::vector<Point
|
|||||||
cbreak();
|
cbreak();
|
||||||
noecho();
|
noecho();
|
||||||
|
|
||||||
|
|
||||||
_getch = getch();
|
_getch = getch();
|
||||||
endwin();
|
endwin();
|
||||||
|
Player *active = nullptr;
|
||||||
|
Player *inactive = nullptr;
|
||||||
|
if(one.m_turn) active = &one;
|
||||||
|
else if(two.m_turn) active = &two;
|
||||||
|
if(active == &one) inactive = &two;
|
||||||
|
else if(active == &two) inactive = &one;
|
||||||
|
|
||||||
switch (_getch) {
|
switch (_getch) {
|
||||||
case 49:
|
case 49:
|
||||||
one.input_tile(0, points);
|
active->input_tile(0, points);
|
||||||
|
active->m_turn = false;
|
||||||
|
inactive->m_turn = true;
|
||||||
break;
|
break;
|
||||||
case 50:
|
case 50:
|
||||||
one.input_tile(1, points);
|
active->input_tile(1, points);
|
||||||
|
active->m_turn = false;
|
||||||
|
inactive->m_turn = true;
|
||||||
break;
|
break;
|
||||||
case 51:
|
case 51:
|
||||||
one.input_tile(2, points);
|
active->input_tile(2, points);
|
||||||
|
active->m_turn = false;
|
||||||
|
inactive->m_turn = true;
|
||||||
break;
|
break;
|
||||||
case 52:
|
case 52:
|
||||||
one.input_tile(3, points);
|
active->input_tile(3, points);
|
||||||
|
active->m_turn = false;
|
||||||
|
inactive->m_turn = true;
|
||||||
break;
|
break;
|
||||||
case 53:
|
case 53:
|
||||||
one.input_tile(4, points);
|
active->input_tile(4, points);
|
||||||
|
active->m_turn = false;
|
||||||
|
inactive->m_turn = true;
|
||||||
break;
|
break;
|
||||||
case 54:
|
case 54:
|
||||||
one.input_tile(5, points);
|
active->input_tile(5, points);
|
||||||
|
active->m_turn = false;
|
||||||
|
inactive->m_turn = true;
|
||||||
break;
|
break;
|
||||||
case 55:
|
case 55:
|
||||||
one.input_tile(6, points);
|
active->input_tile(6, points);
|
||||||
|
active->m_turn = false;
|
||||||
|
inactive->m_turn = true;
|
||||||
break;
|
break;
|
||||||
case 113:
|
case 113:
|
||||||
running = false;
|
running = false;
|
||||||
|
|||||||
+1
-1
@@ -6,7 +6,7 @@
|
|||||||
void Window::update_display(std::vector<Point> &points_list) {
|
void Window::update_display(std::vector<Point> &points_list) {
|
||||||
for(std::array<char, COL> &row : m_board) { row.fill('.'); }
|
for(std::array<char, COL> &row : m_board) { row.fill('.'); }
|
||||||
for(int i = 0; i < points_list.size(); i++) {
|
for(int i = 0; i < points_list.size(); i++) {
|
||||||
m_board[points_list[i].m_row][points_list[i].m_col] = '*';
|
m_board[points_list[i].m_row][points_list[i].m_col] = points_list[i].m_symbol;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "\033[H" << std::flush;
|
std::cout << "\033[H" << std::flush;
|
||||||
|
|||||||
Reference in New Issue
Block a user