XP系统下用VC实现俄罗斯方块游戏

这篇博客介绍了如何在Windows XP系统下使用Visual C++(VC)开发一款俄罗斯方块游戏。源代码包括游戏窗口的设置、方块的绘制、旋转、碰撞检测等功能,并展示了游戏的运行效果。
摘要由CSDN通过智能技术生成


源文件名为t1.cpp

效果图如下所示


源代码如下:


#include <iostream>
#include<windows.h>
#include <vector>
#include <mmsystem.h>
#include<stdio.h>
using namespace std;


#define GameW 10
#define GameH 20
const int CtrlLeft = GameW*2+4 + 3;


struct Point {
    Point(){}
    Point(int x, int y) {_x = x, _y = y;}
    int _x, _y;
};


HANDLE g_hOutput = GetStdHandle(STD_OUTPUT_HANDLE);
HANDLE g_hInput  = GetStdHandle(STD_INPUT_HANDLE);


Point g_ptCursor(0,0);
BOOL isChecking = FALSE;
BOOL g_bGameOver = FALSE;
int g_nGameBack[GameH][GameW], Case;
int nowKeyInfo = -1;
int g_nDiff = 1;
int g_nLife = 2;
int g_nScore = 0;


void SetCursor(COORD cd) {
    SetConsoleCursorPosition(g_hOutput, cd);
}
void SetCursor(int x, int y){
    COORD cd = {x, y};
    SetCursor(cd);
}
void SetBlockCursor(int x, int y){
    COORD cd = {2*x + 2, y + 1};
    SetCursor(cd);
}


void SetBack(int x, int y, BOOL bk) {
    SetBlockCursor(x, y);
    if (bk)
        printf("%s", "■");
    else
        printf(" ");
}


bool Out(int x, int y) {
    return x < 0 || y < 0 || x >= GameW || y >= GameH;
}


struct xBlock {
public:
    int len;
    int nowRotateID;
    BOOL mask[4][4][4];
    static vector <xBlock> List;


    xBlock() { len = 0; }
    xBlock(int l, char *str) {
        int i, j, k;
        len = l;
        memset(mask, FALSE, sizeof(mask));
        for(i = 0; i < l; i++) {
            for(j = 0; j < l; j++) {
                mask[0][i][j] = str[i*l + j] - '0';
            }
        }
        for(k = 1; k < 4; k++) {
            for(i = 0; i < len; i++) {
                for(j = 0; j < len; j++) {
         

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值