-
Notifications
You must be signed in to change notification settings - Fork 0
/
Chess v.02.cpp
114 lines (92 loc) · 2.4 KB
/
Chess v.02.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
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <conio.h>
#define ROWS 8
#define COLS 8
void DrawBoard (char ChessBoard[ROWS][COLS][2])
{
HANDLE hConsole;
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
bool White = true;
system("cls");
for(int i=0;i<ROWS;i++)
{
for(int j=0;j<COLS;j++)
{
switch(White)
{
case true:
switch(ChessBoard[j][i][1])
{
case 'b':
SetConsoleTextAttribute(hConsole, 112);
printf("%c",(i*10)+j,ChessBoard[j][i][0]);
break;
case 'r':
SetConsoleTextAttribute(hConsole, 124);
printf("%c",(i*10)+j,ChessBoard[j][i][0]);
break;
default:
SetConsoleTextAttribute(hConsole, 127);
printf("%c",(i*10)+j,ChessBoard[j][i][0]);
break;
}
break;
case false:
{
case 'b':
SetConsoleTextAttribute(hConsole, 128);
printf("%c",(i*10)+j,ChessBoard[j][i][0]);
break;
case 'r':
SetConsoleTextAttribute(hConsole, 140);
printf("%c",(i*10)+j,ChessBoard[j][i][0]);
break;
default:
SetConsoleTextAttribute(hConsole, 128);
printf("%c",(i*10)+j,ChessBoard[j][i][0]);
break;
}
break;
}
White = !White;
}
printf("\n");
White = !White;
}
}
int main ()
{
int ii,jj;
char ChessBoard [ROWS][COLS][2];
HANDLE hConsole;
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
for(int i=0;i<ROWS;i++){
for(int j=0;j<COLS;j++){
if ((i*10+j)>= 28 and (i*10+j) <= 46)
{
ChessBoard[i][j][0]=' ';
ChessBoard[i][j][1]=' ';
} else if ((i*10+j)>=28 and (i*10+j)%2==1) {
ChessBoard[i][j][0]='o';
ChessBoard[i][j][1]='b';
} else if ((i*10+j)<=48 and (i*10+j)%2==1){
ChessBoard[i][j][0]='o';
ChessBoard[i][j][1]='r';
}
}
}
DrawBoard(ChessBoard);
getch();
ChessBoard[6][2][1]='b';
ChessBoard[6][2][0]='o';
DrawBoard(ChessBoard);
getch();
ChessBoard[4][4][1]='r';
ChessBoard[4][4][0]='o';
DrawBoard(ChessBoard);
getch();
getchar(); // wait
return 0;
}