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 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
void gotoxy(int x, int y){
HANDLE hConsole;
COORD cursorLoc;
std::cout.flush();
cursorLoc.X = x;
cursorLoc.Y = y;
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hConsole, cursorLoc);
}
void cursor(int x, int y){ //this moves the cursor up down left and right on the whole grid
while (true){
while (true){
gotoxy(x, y);
if (GetAsyncKeyState(VK_UP) != 0)
{
y -= 2;
Sleep(200);
gotoxy(x, y);
if (y < 1)
{
y = 17;
Sleep(200);
gotoxy(x, y);
}
break;
}
else if (GetAsyncKeyState(VK_DOWN) != 0)
{
y += 2;
Sleep(200);
gotoxy(x, y);
if (y > 17)
{
y = 1;
Sleep(200);
gotoxy(x, y);
}
break;
}
else if (GetAsyncKeyState(VK_RIGHT) != 0){
x += 4;
Sleep(200);
gotoxy(x, y);
if (x > 34)
{
x = 2;
Sleep(200);
gotoxy(x, y);
}
break;
}
else if (GetAsyncKeyState(VK_LEFT) != 0){
x -= 4;
Sleep(200);
gotoxy(x, y);
if (x < 2)
{
x = 34;
Sleep(200);
gotoxy(x, y);
}
break;
}
}
}
}
void pops0(int x, int y, int s0[3][3][3]){ //populates the cells with the given numbers
gotoxy(x, y);
for (int i = 0; i < 3; i++){
for (int j = 0; j < 3; j++){
for (int k = 0; k < 3; k++){
if (s0[i][j][k] != 0){
cout << s0[i][j][k];
gotoxy(x += 4, y);
}
else{
gotoxy(x += 4, y);
}
}
x = 2;
gotoxy(x, y += 2);
}
}
}
void pops1(int x, int y, int s1[3][3][3]){ //populates the cells with the given numbers
x = 14;
y = 1;
gotoxy(x, y);
for (int i = 0; i < 3; i++){
for (int j = 0; j < 3; j++){
for (int k = 0; k < 3; k++){
if (s1[i][j][k] != 0){
cout << s1[i][j][k];
gotoxy(x += 4, y);
}
else{
gotoxy(x += 4, y);
}
}
x = 14;
gotoxy(x, y += 2);
}
}
}
void pops2(int x, int y, int s0[3][3][3]){ //populates the cells with the given numbers
x = 26;
y = 1;
gotoxy(x, y);
for (int i = 0; i < 3; i++){
for (int j = 0; j < 3; j++){
for (int k = 0; k < 3; k++){
if (s0[i][j][k] != 0){
cout << s0[i][j][k];
gotoxy(x += 4, y);
}
else{
gotoxy(x += 4, y);
}
}
x = 26;
gotoxy(x, y += 2);
}
}
}
int main(){
int s0[3][3][3] = { { { {5}, {3}, {} }, { {6}, {}, {} }, { {}, {9}, {8} } }, { { {8}, {}, {} }, { {4}, {}, {} }, { {7}, {}, {} } }, { { {}, {6}, {} }, { {}, {}, {} }, { {}, {}, {} } } }; //array for 3, 3 by 3 boxes from left to right containing the values
int s1[3][3][3] = { { { {}, {7}, {} }, { {1}, {9}, {5} }, { {}, {}, {} } }, { { {}, {6}, {} }, { {8}, {}, {3} }, { {}, {2}, {} } }, { { {}, {}, {} }, { {4}, {1}, {9} }, { {}, {8}, {} } } }; //array for 3, 3 by 3 boxes from left to right containing the values
int s2[3][3][3] = { { { {}, {}, {} }, { {}, {}, {} }, { {}, {6}, {} } }, { { {}, {}, {3} }, { {}, {}, {1} }, { {}, {}, {6} } }, { { {}, {}, {} }, { {}, {}, { 5 } }, { {}, { 7 }, { 9 } } } }; //array for 3, 3 by 3 boxes from left to right containing the values
int x = 2, y = 1;
for (int i = 0; i < 9; i++){ //prints the whole sudoku box
if ((i % 3) == 0){
cout << "+---+---+---+---+---+---+---+---+---+\n";
}
else{
cout << "+-----------+-----------+-----------+\n";
}
for (int j = 0; j < 1; j++){
cout << "+ | | + | | + | | +\n";
}
}
cout << "+---+---+---+---+---+---+---+---+---+\n";
pops0(x, y, s0);
pops1(x, y, s1);
pops2(x, y, s2);
cursor(x, y);
system("pause");
|