小游戏 · 3 蒟蒻的开灯游戏

· · 个人记录

#include<cmath>
#include<ctime>
#include<cstdio>
#include<string>
#include<cstdlib>
#include<iostream>
#include<windows.h>
#include<algorithm>
using namespace std;
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
string nicheng,ni;
int len;
struct Button{
    int x,y,color;
    const char *name;
    int len;
};
void hide(){
    CONSOLE_CURSOR_INFO cursor_info = {1, 0}; 
    SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
}
void GetPos(POINT &pt){
    HWND hwnd=GetForegroundWindow();
    GetCursorPos(&pt);
    ScreenToClient(hwnd,&pt);
    pt.y=pt.y/16,pt.x=pt.x/16;
}
void color(int a){
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),a);
}
void gto(int x,int y){
    COORD pos;pos.X=y*2;pos.Y=x;
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);
}
Button NewButton(int x,int y,int color,const char *name){
    Button t;
    t.x=x,t.y=y,t.name=name;
    t.color=color;
    t.len=strlen(name);
    return t;
}
bool Preserve(Button A){
    gto(A.x,A.y),color(A.color),printf("%s",A.name);
    POINT pt;
    GetPos(pt);
    if(pt.y==A.x&&(pt.x>=A.y&&pt.x<=A.y+A.len/2)){
        gto(A.x,A.y),printf("%s",A.name);
        if(KEY_DOWN(MOUSE_MOVED)) return 1;
    }
    return 0;
}
bool qq[7][7];
int n;
int dis[5][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}, {0, 0}};
Button z[7][7];

void output(){
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            if(qq[i][j] == false){
                //cout << "         ";
                z[i][j] = NewButton(i * 2 + 1, j * 2 + 1, 7, "○");
                //cout << " ";
            }else{
                //cout << "         ";
                z[i][j] = NewButton(i * 2 + 1, j * 2 + 1, 7, "●");
                //cout << " ";
            }
        }
        cout << endl; 
    }
}

bool in(int x, int y){
    return 0 <= x && x < n && 0 <= y && y < n;
}

bool ying(){
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            if(qq[i][j] == false){
                continue;
            }else{
                return false;
            }
        }
    }
    return true;
}

int main( ){
    cin >> n;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            srand(time(NULL));
            int c = (rand()%100000);
            Sleep(50);
            system("cls");
            cout << "生" << endl; 
            Sleep(50);
            system("cls");
            cout << "生成" << endl; 
            Sleep(50);
            system("cls");
            cout << "生成数" << endl; 
            Sleep(50);
            system("cls");
            cout << "生成数据" << endl; 
            Sleep(50);
            system("cls");
            cout << "生成数据中" << endl; 
            Sleep(100);
            system("cls");
            cout << "生成数据中▁" << endl;
            Sleep(100) ;
            system("cls");
            cout << "生成数据中▁▂" << endl;
            Sleep(100);
            system("cls");
            cout << "生成数据中▁▂▃" << endl;
            Sleep(100);
            system("cls");
            cout << "生成数据中▁▂▃▅" << endl;
            Sleep(100);
            system("cls");
            cout << "生成数据中▁▂▃▅▆" << endl;
            Sleep(100);
            system("cls");
            cout << "生成数据中▁▂▃▅▆▇" << endl;
            Sleep(100);
            system("cls");
            cout << "生成数据中▁▂▃▅▆▇▉" << endl;
            Sleep(100);
            system("cls");
            if(c % 2 == 1){
                qq[i][j] = true;
                //cout << "         ";
                z[i][j] = NewButton(i * 2 + 1, j * 2 + 1, 7, "●");
                //cout << " ";
            }else{
                qq[i][j] = false;
                //cout << "         ";
                z[i][j] = NewButton(i * 2 + 1, j * 2 + 1, 7, "○");
                //cout << " ";
            }
        }
        cout << endl;
    }
    while(true){
        bool h1 = false;
        int a, b;
        Sleep(100);
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                if(Preserve(z[i][j])){
                    a = i;
                    b = j;
                    h1 = true;
                    Sleep(100);
                    break;
                }
            }
            if(h1){
                break;
            }
        }
        if(h1){
            if(in(a, b)){
                for(int i = 0; i < 5; i++){
                    int ta = a + dis[i][0];
                    int tb = b + dis[i][1];
                    if(in(ta, tb)){
                        qq[ta][tb] = !qq[ta][tb];
                    }
                }
            }else{
                cout << "您的输入无效" << endl;
                Sleep(500);
                system("cls");
                continue;
            }
            system("cls");
            output();
            if(ying()){
                cout << "恭喜您获胜了" << endl;
                Sleep(10000);
                return 0;
            }else{
                continue;
            }
        }
    }
    return 0;
}