#include <bits/stdc++.h>
#include <windows.h>
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
#define int long long
#define endl '\n'
using namespace std;
int testNo = 0;
// variables & definitions
void init() {
;
}
void press(int x,int y) {
;
}
void draw() {
;
}
void doTestcase() {
init();
HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE);
DWORD mode;
GetConsoleMode(hStdin,&mode);
mode &= ~ENABLE_QUICK_EDIT_MODE;
SetConsoleMode(hStdin,mode);
POINT p;
HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE);
HWND h = GetForegroundWindow();
CONSOLE_FONT_INFO consoleCurrentFont;
system("cls");
draw();
for (;;) {
if (KEY_DOWN(VK_LBUTTON)) {
GetCursorPos(&p);
ScreenToClient(h,&p);
GetCurrentConsoleFont(hOutput,FALSE,&consoleCurrentFont);
int x = p.x /= consoleCurrentFont.dwFontSize.X;
int y = p.y /= consoleCurrentFont.dwFontSize.Y;
press(x,y);
while (KEY_DOWN(VK_LBUTTON));
system("cls");
draw();
}
}
}
signed main() {
int t;
// cin >> t;
t = 1;
while (t--) ++testNo,doTestcase();
return 0;
}作品: 熄灯游戏
#include <bits/stdc++.h>
#include <windows.h>
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
#define int long long
#define endl '\n'
using namespace std;
int testNo = 0;
// variables & definitions
int a,b;
bool light[25][25];
void init() {
cout << "输入长和宽:\n";
cin >> a >> b;
while (1 > a || a > 20 || 1 > b || b > 20) cout << "长或宽 大于 20 或 小于 1,重新输入:",cin >> a >> b;
cout << a << " " << b << endl;
}
void press(int x,int y) {
swap(x,y);
++x,++y;
if (0 <= x && x <= a && 0 <= y && y <= b) {
light[x][y] = !light[x][y];
if (x != 0) light[x - 1][y] = !light[x - 1][y];
if (x != a) light[x + 1][y] = !light[x + 1][y];
if (y != 0) light[x][y - 1] = !light[x][y - 1];
if (y != b) light[x][y + 1] = !light[x][y + 1];
}
}
void draw() {
for (int i = 1; i <= a; ++i) {
for (int j = 1; j <= b; ++j) cout << (light[i][j]?'O':'.');
cout << endl;
}
}
void doTestcase() {
init();
HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE);
DWORD mode;
GetConsoleMode(hStdin,&mode);
mode &= ~ENABLE_QUICK_EDIT_MODE;
SetConsoleMode(hStdin,mode);
POINT p;
HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE);
HWND h = GetForegroundWindow();
CONSOLE_FONT_INFO consoleCurrentFont;
system("cls");
draw();
for (;;) {
if (KEY_DOWN(VK_LBUTTON)) {
GetCursorPos(&p);
ScreenToClient(h,&p);
GetCurrentConsoleFont(hOutput,FALSE,&consoleCurrentFont);
int x = p.x /= consoleCurrentFont.dwFontSize.X;
int y = p.y /= consoleCurrentFont.dwFontSize.Y;
press(x,y);
while (KEY_DOWN(VK_LBUTTON));
system("cls");
draw();
}
}
}
signed main() {
int t;
// cin >> t;
t = 1;
while (t--) ++testNo,doTestcase();
return 0;
}