小游戏 · 15 蒟蒻的dancing line

· · 个人记录

附加:游戏前请手动调整字体大小与窗口大小。

#include<cmath>
#include<ctime>
#include<cstdio>
#include<string>
#include<cstdlib>
#include<iostream>
#include<windows.h>
#include <conio.h>
#include<algorithm>
#include<bitset>
using namespace std;
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
const int dx = 50;
string nicheng,ni;
int len;
void block(int x,int y){
    HANDLE   hCon;
    hCon = GetStdHandle(STD_OUTPUT_HANDLE);  
    COORD   setps;
    setps.X = x;
    setps.Y = y;
    SetConsoleCursorPosition(hCon,setps);  
}
void SetPos(COORD a){
    HANDLE out=GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleCursorPosition(out, a);
}

void SetPos(int i, int j){
    COORD pos={i, j};
    SetPos(pos);
}

void HideCursor(){
    CONSOLE_CURSOR_INFO cursor_info = {1, 0}; 
    SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
}
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;
}

bitset<10>pre;
bitset<10>down;

void check(char c){//检测某个按键是否按下,按下就改变一下变量
    if(!KEY_DOWN(c))down[c-'A']=0;
    else down[c-'A']=1;
}

string zuantu[6] = {
"......",
"......",
"..yvz.",
"..z.y.",
"...V..",
"......"
};

int zuanco[6][6] = {
{0},
{0,7,7,7,7,7},
{0,7,13,13,13,7},
{0,7,13,7,13,7},
{0,7,7,13,7,7},
{0,7,7,7,7,7}
};

string guantu[6] = {
"......",
"......",
"..ooo.",
"..sss.",
"..zxy.",
"......"
};

int guanco[6][6] = {
{0},
{0,7,7,7,7,7},
{0,7,14,14,14,7},
{0,7,14,14,14,7},
{0,7,14,14,14,7},
{0,7,7,7,7,7}
};

int n, m, x1, x2, da1 = 1, da2 = 1, f = 1, zuan = 0, guan = 0;
string a[510];
char maze[5010][5010];
int mc[5010][5010];
char mq[dx + 10][dx + 10];

int main( ){
    freopen("dancline.txt", "r", stdin);
    HideCursor();
    cin >> n >> m >> x1 >> x2;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        for(int j = 1; j <= m; j++){
            if(a[i][j] == '#'){
                for(int i1 = 1; i1 <= 5; i1++){
                    for(int j1 = 1; j1 <= 5; j1++){
                        maze[i * 5 + i1][j * 5 + j1] = '#';
                        mc[i * 5 + i1][j * 5 + j1] = 15;
                    }
                }
            }else if(a[i][j] == '.'){
                for(int i1 = 1; i1 <= 5; i1++){
                    for(int j1 = 1; j1 <= 5; j1++){
                        maze[i * 5 + i1][j * 5 + j1] = '.';
                        mc[i * 5 + i1][j * 5 + j1] = 15;
                    }
                }
            }else if(a[i][j] == 'z'){
                for(int i1 = 1; i1 <= 5; i1++){
                    for(int j1 = 1; j1 <= 5; j1++){
                        maze[i * 5 + i1][j * 5 + j1] = zuantu[i1][j1];
                        mc[i * 5 + i1][j * 5 + j1] = zuanco[i1][j1];
                    }
                }
            }else if(a[i][j] == 'g'){
                for(int i1 = 1; i1 <= 5; i1++){
                    for(int j1 = 1; j1 <= 5; j1++){
                        maze[i * 5 + i1][j * 5 + j1] = guantu[i1][j1];
                        mc[i * 5 + i1][j * 5 + j1] = guanco[i1][j1];
                    }
                }
            }
        }
    }
    n *= 5;
    m *= 5;
    for(int i1 = da1; i1 <= da1 + dx; i1++){
        for(int j1 = da2; j1 <= da2 + dx; j1++){
            int i = i1 - da1 + 1;
            int j = j1 - da2 + 1; 
            if(i1 >= 30 + da1 && i1 <= 32 + da1 && j1 >= 27 + da2 && j1 <= 29 + da2){
                maze[i1][j1] = 'O';
                mc[i1][j1] = 12;
                if(maze[i1][j1] == 'A'){
                    zuan++;
                }else if(maze[i1][j1] == 'W'){
                    guan++;
                }
            }
            color(mc[i1][j1]);
            //block(j1 - da2 + 1, i1 - da1 + 1);
            SetPos(j1 - da2 + 1, i1 - da1 + 1);
            if(maze[i][j] == 'O'){
                cout << "@";
            }else if(maze[i1][j1] == 'z'){
                cout << "\\" ;
            }else if(maze[i1][j1] == 'y'){
                cout << "/";
            }else if(maze[i1][j1] == 's'){
                cout << "|";
            }else if(maze[i1][j1] == 'x'){
                cout << "_";
            }else if(maze[i1][j1] == 'v'){
                cout << "^";
            }else{
                cout << maze[i1][j1];
            }
            mq[i][j] = maze[i1][j1];
            //block(0, 0);
            SetPos(0, 0);
        }
    }
    da1 = 2;
    da2 = 1;
    char z = getch();
    while(true){
        bool h = true;
        bool h1 = false;
        for(int i1 = da1; i1 <= da1 + dx; i1++){
            for(int j1 = da2; j1 <= da2 + dx; j1++){
                int i = i1 - da1 + 1;
                int j = j1 - da2 + 1; 
                if(i1 >= 30 + da1 && i1 <= 32 + da1 && j1 >= 27 + da2 && j1 <= 29 + da2){
                    if(maze[i1][j1] == '#'){
                        h = false;
                    }else{
                        if(maze[i1][j1] == 'A'){
                            zuan++;
                        }else if(maze[i1][j1] == 'W'){
                            guan++;
                        }
                        maze[i1][j1] = 'O';
                        mc[i1][j1] = 12;
                    }
                }
                color(mc[i1][j1]);
                if(mq[i][j] != maze[i1][j1]){
                    //block(j, i);
                    SetPos(j, i);
                    if(maze[i1][j1] == 'O'){
                        cout << "@";
                    }else if(maze[i1][j1] == 'z'){
                        cout << "\\";
                    }else if(maze[i1][j1] == 'y'){
                        cout << "/";
                    }else if(maze[i1][j1] == 's'){
                        cout << "|";
                    }else if(maze[i1][j1] == 'x'){
                        cout << "_";
                    }else if(maze[i1][j1] == 'v'){
                        cout << "^";
                    }else{
                        cout << maze[i1][j1];
                    }
                    mq[i][j] = maze[i1][j1];
                    //block(0, 0);
                    SetPos(0, 0);
                }
                //cout << maze[i1][j1];
                check('A');
                if(down != pre){
                    pre = down;
                    if(down[0]){
                        h1 = true;
                    }
                }
            }
            //cout << endl;
        }
        check('A');
        if((down != pre && down[0] == 1) || h1){
            f = f % 2 + 1;
        }
        if(f == 1){
            da1++;
        }else{
            da2++;
        }
        if(!h){
            Sleep(3000);
            system("cls");
            color(15);
            cout << "皇冠:" << guan << "  钻石:" << zuan << endl;
            cout << "gameover" << endl;
            Sleep(3000);
            break;
        }
        Sleep(0);
        //system("cls");
    }
    system("pause");
    return 0;
}

关卡一:

30 30 1 1
#############################
#############################
#############################
#############################
#############################
#####..######################
#####..######################
#####.....###################
#####.....###################
########..###################
########..###################
########.....################
########.....################
###########..################
###########..################
###########.........#########
###########.........#########
############.#####..#########
############..####.........##
#############..###.........##
##############..#########..##
###############..########..##
################..#######..##
#################..........##
#########################..##