非经典消方块

#include <iostream>
#include <Windows.h>
#include <conio.h>

using namespace std;

void cursor_move(int x, int y);
void frame();
void produce_diamonds(int x);
void body();
void move();
void line_delete();

bool b[15][10] = { };
bool judge[15] = { };
char cleck = 0;
int point = 8;
int line = 3;
int timer = 0;
int score = 0;
char a;

int main()
{
    srand(time(0));
    for (int i = 0; i <= 9; i++)
    {
        b[0][i] = 1;
    }
    frame();
    cursor_move(30, 7);
    cout << "得分:";
    cursor_move(8, 14);
    cout << "■";
    produce_diamonds(1);
    produce_diamonds(2);
    produce_diamonds(3);
    body();
}

void cursor_move(int x, int y)
{
    COORD pos;
    pos.X = x;
    pos.Y = y;
    SetConsoleCursorPosition(HANDLE(GetStdHandle(STD_OUTPUT_HANDLE)), pos);
    CONSOLE_CURSOR_INFO cursor_info = { 1,0 };
    SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
}

void frame()
{
    SetConsoleTextAttribute(HANDLE(GetStdHandle(STD_OUTPUT_HANDLE)), 11);
    for (int i = 0; i <= 15; i++)
    {
        for (int j = 0; j <= 20; j += 2)
        {
            if (i == 0 || i == 15 || j == 0 || j == 20)
            {
                cursor_move(j, i);
                cout << "■";
            }
        }
    }
}

void produce_diamonds(int x)
{
    for (int i = 2; i <= 18; i += 2)
    {
        if (rand() % 3 < 2)
        {
            cursor_move(i, x);
            b[x][i/2] = 1;
            cout << "■";
        }
    }
}

void body()
{
    while (1)
    {
        if (_kbhit())
        {
            cleck = _getch();
            move();
        }
        cursor_move(36, 7);
        cout << score;
        timer++;
        if (timer == 10)
        {
            line++;
            produce_diamonds(line);
            timer = 0;
        }
        line_delete();
        if (line == 14)
        {
            cursor_move(40, 7);
            cout << "菜的抠脚";
            a = _getch();
            cursor_move(0, 17);
            break;
        }
        Sleep(20);
    }
}

void move()
{
    switch ((int)cleck)
    {
    case 77:
        point += 2;
        if (point == 20)
        {
            point = 18;
            break;
        }
        cursor_move(point - 2, 14);
        cout << "  ";
        cursor_move(point, 14);
        cout << "■";
        break;
    case 75:
        point -= 2;
        if (point == 0)
        {
            point = 2;
            break;
        }
        cursor_move(point + 2, 14);
        cout << "  ";
        cursor_move(point, 14);
        cout << "■";
        break;
    case 32:
        for (int i = line; i >= 0; i--)
        {
            if (b[i][point/2])
            {
                cursor_move(point, i + 1);
                cout << "■";
                b[i + 1][point/2] = 1;
                if (i == line)
                {
                    line++;
                }
                break;
            }
        }
        break;
    }
}

void line_delete()
{
    int sum = 0;
    for (int i = 1; i <= line; i++)
    {
        for (int j = 1; j <= 9; j ++)
        {
            if (b[i][j])
            {
                sum++;
            }
        }
        if (sum == 9)
        {
            judge[i] = true;
        }
        sum = 0;
    }
    for (int i = 1; i <= line; i++)
    {
        if (judge[i])
        {
            judge[i] = false;
            for (int j = i; j <= line; j++)
            {
                for (int k = 2; k <= 18; k += 2)
                {
                    cursor_move(k, j);
                    cout << "  ";
                    b[j][k/2] = 0;
                    if (b[j + 1][k/2])
                    {
                        cursor_move(k, j);
                        cout << "■";
                        b[j][k/2] = 1;
                    }
                }
            }
            line--;
            score++;
            break;
        }
    }
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

空白12138

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值