当前位置:网站首页>els 到底停止
els 到底停止
2022-07-29 00:30:00 【joker_0030】
1、函数实现(els.c)
#include"els_h.h"
//背景数组
char g_arrBackGroud[20][10] = {0};
char g_arrSqare[2][4] = {0};
void OnPaint(HDC hDc)
{
//创建兼容性DC。
HDC hMemDC = CreateCompatibleDC(hDc);//内存id为:HMemDc,窗口id hDc。
//创建兼容性位图。
HBITMAP hBitmapBack= CreateCompatibleBitmap(hDc, 500, 600);
//关联起来。
SelectObject(hMemDC, hBitmapBack);
PaintSqare(hMemDC);
//传递:
//返回值:失败返回0,成功返回非零。
//参数1:目标DC,窗口DC
//参数2,3:目标的起始位置,注意是基于我们的窗口。
//参数4,5:区域的大小。
//参数6:源DC,也就是我们的内存DC。
//参数7,8:内存图片的起始位置。
//参数9:传递方式。
//
BitBlt(hDc, 0, 0, 300, 600, hMemDC, 0, 0, SRCCOPY);
//释放DC
DeleteObject(hBitmapBack);
DeleteDC(hMemDC);
}
void Oncreate()
{
srand((unsigned int)time(NULL));//只执行一次。
CreateRandomSqare();
CopySqareToBack();
}
void PaintSqare(HDC hMemDC)
{
int i = 0,
j = 0;
//画大方块。
Rectangle(hMemDC, 0, 0, 300, 600);//矩形框距离运行窗口的开始位置坐标和截至位置坐标。
//指定一个方块。
/*g_arrBackGroud[2][4] = 1;
g_arrBackGroud[3][3] = 1;
g_arrBackGroud[3][4] = 1;
g_arrBackGroud[3][5] = 1;*/
//遍历
for (i=0 ; i < 20; i++)//2、?
{
for (j=0 ; j < 10; j++)
{
if (1 == g_arrBackGroud[i][j])
{
//画方块。
Rectangle(hMemDC, j*30, i*30, j*30 + 30, i*30 + 30);//矩形框距离运行窗口的开始位置坐标和截至位置坐标。
}
}
}
}
//创建随机块。
int CreateRandomSqare()
{
int nIndex=rand()%7;
switch (nIndex)
{
case 0:
g_arrBackGroud[0][0] = 1, g_arrBackGroud[0][1] = 1, g_arrBackGroud[0][2] = 0, g_arrBackGroud[0][3] = 0;
g_arrBackGroud[1][0] = 0, g_arrBackGroud[1][1] = 1, g_arrBackGroud[1][2] = 1, g_arrBackGroud[1][3] = 0;
break;
case 1:
g_arrBackGroud[0][0] = 0, g_arrBackGroud[0][1] = 1, g_arrBackGroud[0][2] = 1, g_arrBackGroud[0][3] = 0;
g_arrBackGroud[1][0] = 1, g_arrBackGroud[1][1] = 1, g_arrBackGroud[1][2] = 0, g_arrBackGroud[1][3] = 0;
break;
case 2:
g_arrBackGroud[0][0] = 1, g_arrBackGroud[0][1] = 0, g_arrBackGroud[0][2] = 0, g_arrBackGroud[0][3] = 0;
g_arrBackGroud[1][0] = 1, g_arrBackGroud[1][1] = 1, g_arrBackGroud[1][2] = 1, g_arrBackGroud[1][3] = 0;
break;
case 3:
g_arrBackGroud[0][0] = 0, g_arrBackGroud[0][1] =0 , g_arrBackGroud[0][2] = 1, g_arrBackGroud[0][3] = 0;
g_arrBackGroud[1][0] = 1, g_arrBackGroud[1][1] = 1, g_arrBackGroud[1][2] = 1, g_arrBackGroud[1][3] = 0;
break;
case 4:
g_arrBackGroud[0][0] = 0, g_arrBackGroud[0][1] = 1, g_arrBackGroud[0][2] = 0, g_arrBackGroud[0][3] = 0;
g_arrBackGroud[1][0] = 1, g_arrBackGroud[1][1] = 1, g_arrBackGroud[1][2] = 1, g_arrBackGroud[1][3] = 0;
break;
case 5:
g_arrBackGroud[0][0] = 0, g_arrBackGroud[0][1] = 1, g_arrBackGroud[0][2] = 1, g_arrBackGroud[0][3] = 0;
g_arrBackGroud[1][0] = 0, g_arrBackGroud[1][1] = 1, g_arrBackGroud[1][2] = 1, g_arrBackGroud[1][3] = 0;
break;
case 6:
g_arrBackGroud[0][0] = 1, g_arrBackGroud[0][1] = 1, g_arrBackGroud[0][2] = 1, g_arrBackGroud[0][3] = 1;
g_arrBackGroud[1][0] = 0, g_arrBackGroud[1][1] = 0, g_arrBackGroud[1][2] = 0, g_arrBackGroud[1][3] = 0;
break;
}
return nIndex;
}
void CopySqareToBack()
{
int i = 0,
j = 0;
for ( i = 0; i <2 ; i++)
{
for ( j = 0; j < 4; j++)
{
g_arrBackGroud[i][j + 3] = g_arrSqare[i][j];
}
}
}
void OnReturn(HWND hWnd)
{
//启动定时器
//返回值:成功返回非零。
//参数1:窗口句柄hWnd,NUL
//参数2:定时器ID 不理会
//参数3:间隔时间,毫秒 1000ms=1s。
//参数4:设置为NULL 处理函数的地址。
SetTimer(hWnd, DEF_TIMER1, 500, NULL);
}
void SqareDwon()
{
int i = 0,
j = 0;
for (i = 19; i >=0; i--)
{
for (j = 0; j < 10; j++)
{
if (1==g_arrBackGroud[i][j])
{
g_arrBackGroud[i + 1][j] = g_arrBackGroud[i][j];
g_arrBackGroud[i][j]=0;
}
}
}
}
void OnTimer(HWND hWnd)
{
HDC hDc=GetDC(hWnd);//内核对象。
if (1 == CanSqareDown())
{
SqareDwon();//停止下落。
}
else
{
//产生随机块。
CreateRandomSqare();
//复制到背景上。
CopySqareToBack();
}
//SqareDwon();
//显示方块:
//PaintSqare(hDc);
OnPaint(hDc);
ReleaseDC(hWnd, hDc);
}
int CanSqareDown()
{
int i = 0;
for ( i = 0; i < 10; i++)
{
if (1 == g_arrBackGroud[19][i])
{
return 0;
}
}
return 1;
}
2、头函数(els.h)
#ifndef N_d
#define N_d
#include<Windows.h>
#include<time.h>
#define DEF_TIMER1 1234
void OnPaint(HDC hDc);
//显示方块。
void PaintSqare(HDC hMemDC);
//产生随机块。
int CreateRandomSqare();
//随机块贴近背景。
void CopySqareToBack();
void Oncreate();
//回车键。
void OnReturn(HWND hWnd);
//方块下落。
void SqareDwon();
//定时器响应的函数。
void OnTimer(HWND hWnd);
//方块停在最底层
int CanSqareDown();
#endif
边栏推荐
猜你喜欢

Google play APK uploads other international app stores

面试官:程序员,请你告诉我是谁把公司面试题泄露给你的?

Univariate function integration 1__ Indefinite integral

mysql分表之后怎么平滑上线?

SQL injection of DVWA

图扑软件亮相 2022 福州数博会,携手共创数字新时代

ACM SIGIR 2022 | interpretation of selected papers of meituan technical team

Flask reports an error: pymysq1.err OperationalError:(1054, “Unknown column ‘None‘ in ‘field list‘“)

This article enables you to understand the underlying principle of MySQL- Internal structure, index, lock, cluster

Redis installation, cluster deployment and common tuning
随机推荐
Intel带你初识视觉识别--OpenVINO
Django reports an error using pymsql module django.db.utils.operationalerror
【idea】查询字段使用位置
拼多多众多 API 接口皆可使用
一文搞懂ES6基本全部语法
一文让你搞懂MYSQL底层原理。-内部结构、索引、锁、集群
图扑软件亮相 2022 福州数博会,携手共创数字新时代
Self-attention neural architecture search for semantic image segmentation
Regular checksum time formatting
全面升级,你能想象的都在这————京东API接口
Closures and decorators
Letax record \documentclass{}, authoryear attribute is used
[Jenkins' notes] introduction, free space; Continuous integration of enterprise wechat; Allure reports, continuous integration of email notifications; Build scheduled tasks
Writing assignment 1
Log4j dynamic loading configuration file
日期转换 EEE MMM dd HH:mm:ss zzz yyyy
【ManageEngine】局域网监控软件是什么,有什么作用
【SQL之降龙十八掌】01——亢龙有悔:入门10题
regular expression
Flink SQL Hudi 实战