C++写俄罗斯方块

本文展示了如何使用C++编程实现俄罗斯方块游戏。通过键盘控制方块移动,包括上下左右,游戏设有暂停、重置和退出功能,同时具备计分系统和速度升级机制。代码中包含了游戏界面的绘制、方块生成、移动、消除行等功能。
摘要由CSDN通过智能技术生成

以下是C++写俄罗斯方块的具体代码(各位宝子们点个赞吧!谢谢!):

//上下左右键控制
#include<bits/stdc++.h>
#include<windows.h>
int a[24][17],i,j,tim=800,ti=800,shape=0,b,bn,ta[4][4],turn[4][4],nex[4][4],nextshape,add=0,score=0,speed=1,ok=1,mouse=0,best=0;
void Place(const int x, const int y)
{
COORD PlaceCursorHere;
PlaceCursorHere.X = y;
PlaceCursorHere.Y = x;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), PlaceCursorHere);
return;
}
void color(int x)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),x);
}
void appear()
{
for(i=3; i<=22; i++) for(j=1; j<=15; j++) if(a[i][j]!=0)
        {
            Place(i-2,2*j);
            printf("■");
        }
}
void disappear()
{
for(i=3; i<=22; i++) for(j=1; j<=15; j++) if(a[i][j]==2)
        {
            Place(i-2,2*j);
            printf(" ");
        }
}
int search(int x0,int y0,int x,int y)
{
POINT pt;
HWND h=GetForegroundWindow();
GetCursorPos(&pt);
ScreenToClient(h,&pt);
if(pt.x>=x0&&pt.y>=y0&&pt.x<=x&&pt.y<=y)
{
    if(mouse!=0)
    {
        Sleep(100);
        return 2;
    }
    else return 1;
}
else return 0;
}
void button(int x)
{
int m=x*10;
if(x<3)
{
    Place(22,m);
    printf("┌┄┄┄┐");
    Place(23,m);
    {
        if(x==0)
        {
            if(ok!=0) printf("┆开始 ┆");
            else printf("┆暂停 ┆");
        }
        if(x==1) printf("┆重置 ┆");
        if(x==2) printf("┆退出 ┆");
    }
    Place(24,m);
    printf("└┄┄┄┘");
}
else
{
    Place(9,m-33);
    printf("┌┄┄┐");
    Place(10,m-33);
    {
        if(x==4) printf("┆是┆");
        else printf("┆否┆");
    }
    Place(11,m-33);
    printf("└┄┄┘");
}
}
void menu(int x)
{
int k,l;
if(x==0)
{
    if(ok!=0)
    {
        ok=0;
        return;
    }
    else while(1)
        {
            mouse=GetAsyncKeyState(VK_LBUTTON);
            Place(9,13);
            printf("暂停");
            if(search(7,360,71,390)==2) break;
            Sleep(50);
        }
    Place(9,12);
    for(j=1; j<=6; j++) printf(" "); //appear();
}
else
{
    for(i=1; i<=20; i++) for(j=2; j<=30; j++)
        {
            Place(i,j);
            printf(" ");
        }
    Place(7,2);
    for(i=1; i<=15; i++) printf("┄");
    Place(12,2);
    for(i=1; i<=15; i++) printf("┄");
    Place(8,6);
   

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值