c/c++ Vc++6.0俄罗斯方块

本文介绍了使用C/C++在Vc++6.0环境下实现俄罗斯方块游戏的方法。游戏设计中,背景图设置为黑色,通过与运算处理各形状。每个俄罗斯方块用4*4数组表示,并且在移动过程中实时监听键盘事件,可能采用多线程技术。游戏界面使用了EasyX第三方库,便于快速搭建和实现。
摘要由CSDN通过智能技术生成

游戏截图 游戏背景图

在这里插入图片描述

在这里插入图片描述背景图为黑色 每一块与img与运算 得到的就是背景图
每一种的俄罗斯块可以用 4*4数组表示
移动的同时 需要随时获取键盘事件 可以多线程
效果显示 如:正方形 使用了easyx第三方库 可直接百度 很好搭建
代码

#include <graphics.h>
#include <iostream>
#include <conio.h>
#include <Windows.h>
#include <stdlib.h>
#define BG_WIDTH 10
#define BG_HEIGHT 20
void Put_image(int Map[10][20]);
using namespace std;
class Game_1
{
   
public:
	Game_1();
	int curBlockIndex ;                   //方块类型
	int BlockIndex;                       //方向类型

	int poX;                              //方块所在位置
	int poY;

struct MatriData                          //4X4数组表示一个方向上的所有数据
{
   
	int data[4][4];
};
struct Block
{
   
	int dirctionCount;                    //方向数量
	
	MatriData matriData[4];               //最多四个方向上的数据
};
	Block arrBlock[7];                    //俄罗斯方块的七种形状
	void CreateNewBlock();
	void DrawBlock(Block &block,int posX,int poY); //动态
	void I_getch(void);                   //键盘检测 
	void changeBackGround(void);          //页面添加新的方块
	bool Check();						  //检测方块到达底部
};
int backGround[BG_WIDTH][BG_HEIGHT]={
   0};  //地图
DWORD WINAPI Game_getch(LPVOID lpParamter);
char CH;
int flag_1=0; //关于清除图片的标志位
int Ran[25]={
    1,1,1,0,2,3,2,5,0,2,1,0,1,2,2,4,4,4,4,4,3 };
int Ran_1=0;
void main()
{
   	
	
	HANDLE hThread = CreateThread(NULL, 0, Game_getch, NULL, 0, NULL);
    CloseHandle(hThread);  //多线程 


	initgraph(420, 840);   // 创建绘图窗口,大小为 420X840 像素
	
	Game_1 game_1;
	int i,j;
	for(i=0;i<4;i++)
	{
   
		for(j=0;j<4;j++)
				cout<<game_1.arrBlock[0].matriData[1].data[i][j];
		cout <<endl;
	}
	game_1.CreateNewBlock();  //初始化 随机建立新的方块
	while(1)
	{
   
		game_1.I_getch();
		game_1.DrawBlock(game_1.arrBlock[game_1.BlockIndex],game_1.poX,game_1.poY); 
		if(game_1.Check())
		{
   
			flag_1=1;
			game_1.changeBackGround();
			game_1.CreateNewBlock();
		}
		//方块移动
		Sleep(0.2*1000);
		game_1.poY++;
	}
	getch();
}
void Game_1::changeBackGround()
{
   
	int i=0,j=0;
	for(i=0;i<4;i++)   
		{
   
		for(j=0;j<4;j++)
		{
   
			if(this->arrBlock[this->curBlockIndex].matriData[BlockIndex].data[i][j]==1)
			{
   
				backGround[this->poX+i][this->poY+j]=1;
			}
					
		}
	}
	Put_image(backGround);
}
bool Game_1::Check()
{
   
	int tmpY =this->poY +1;  //假设可以到下一行的Y
	bool isNewTurn =false;
	int i=0,j=0;
	     //触底
	if( poY == 16 )
	{
   	
	for(i=0;i<4;i++)   
		{
   
		for(j=0;j<4;j++)
		{
   
			if(this->arrBlock[this->curBlockIndex].matriData[BlockIndex].data[i][3]==1)
				return true;	
		}
	}
	}
	if( poY == 17 )
	{
   	
	for(i=0;i<4;i++)   
		{
   
		for(j=0;j<4;j++)
		{
   
			if(this->arrBlock[this->curBlockIndex].matriData[BlockIndex].data[i][2]==1)
				return true;	
		}
	}
	
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值