weiwancheng

· · 个人记录


#include<bits/stdc++.h>
#include<windows.h>
#include<stdio.h>
#include<conio.h>
#include<time.h>
#define int long long
#define KD(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0) 
using namespace std;
inline int read(){
    int x=0,f=1;char c=getchar();
    while(c>'9'||c<'0'){if(c=='-')f=-f;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*f;
}
POINT pos;
double pi;
void setpose(int x,int y){
    COORD pos;pos.X=x,pos.Y=y;
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);
}
void SS(int ForgC, int BackC) {
    WORD wColor = ((BackC & 0x0F) << 4) + (ForgC & 0x0F);
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), wColor);
}
int mp[20][20]={
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,
    0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,
    0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,
    0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,
    0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,
    0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,
    0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,
    0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,
    0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,
    0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
};
int show[22][22];
int col[101][2]={
    0,7,
    1,1,
    2,2,
    4,4,
    6,6,
    7,7,
};
void upt(int x,int y){
    setpose(x*2+1,y+1);
    if(mp[x][y])SS(col[show[x][y]][0],col[show[x][y]][1]);
    else SS(0,0);
    printf("▇");
}
void drop(){
    for(int p=1;p<=20;p++){
        for(int i=0;i<20;i++){
            for(int j=0;j<20;j++){
                if(show[i][j+1]==0&&mp[i][j+1]){
                    swap(show[i][j],show[i][j+1]);
                    upt(i,j);upt(i,j+1);
                }
            }
        }
    }
    for(int i=19;i>0;i--){
        for(int j=0;j<20;j++){
            if(show[i][j]==0&&mp[i][j]){
                show[i][j]=rand()%5+1;
                upt(i,j);
            }
        }
    }
}
main(){
    srand(time(0));
    system("mode con cols=100 lines=50");
    HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE);
    DWORD mode;GetConsoleMode(hStdin,&mode);
    mode&=~ENABLE_QUICK_EDIT_MODE;SetConsoleMode(hStdin,mode);
    CONSOLE_CURSOR_INFO cursor_info = {1, 0}; 
    SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
//  MoveWindow(hwnd,rect.left,rect.top,rect.right-rect.left,rect.bottom-rect.top,TRUE);
    for(int i=0;i<20;i++){
        for(int j=0;j<20;j++){
            upt(i,j);
        }
    }drop();
    while(1){
        RECT rect; HWND hwnd=GetForegroundWindow();GetWindowRect(hwnd,&rect); 
        GetCursorPos(&pos);
        int Y=pos.x-rect.left,X=pos.y-rect.top;

    }

}