-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
78 lines (70 loc) · 1.43 KB
/
main.cpp
File metadata and controls
78 lines (70 loc) · 1.43 KB
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
//
// main.cpp
// Chess
//
// Created by Yuval Atir
//
//int main(int argc, char* const argv[]) {
#include "./board/chessboard.hpp"
void console_clear_screen() {
#ifdef WINDOWS
#ifndef ECLIPSE
system("cls");
#endif
#endif
#ifdef LINUX
system("clear");
#endif
}
int console_input_eclipse_win() {
int in;
#ifdef ECLIPSE
in = getchar()-48;
#endif
#ifdef WIN
cin >> in ;
#endif
return in;
}
int main()
{
Chessboard boardgame;
int from_row, from_col, to_row, to_col;
int turn=1; // 1 = WHITE
int location[4];
bool ok;
color bw_str;
while (1) {
console_clear_screen();
boardgame.print_board();
cout << "to exit type q" << endl;
ok = boardgame.promt_user(turn, location);
if (ok == false) {
exit(0);
}
from_row = location[0];
from_col = location[1];
to_row = location[2];
to_col = location[3];
bw_str = (turn == 1 ? white : black );
if (boardgame.get_piece(from_row,from_col)->get_color() != bw_str) {
cout << "pick a " << bw_str <<" piece, hit any key\n" << endl;
cin.ignore();
continue;
}
if ( boardgame.get_piece(from_row,from_col)->get_type() == nada ) {
cout << "pick a piece, hit any key\n" << endl;
cin.ignore();
continue;
}
if ( boardgame.move_piece(from_row, from_col, to_row, to_col) ) {
turn=(turn==1 ? 0 : 1 ); // change turn
continue;
}
else {
cout << "pick another piece, hit any key\n" << endl;
cin.ignore();
continue;
}
} // while
} // main