当前位置:网站首页>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
边栏推荐
- APP接入Kakaotalk三方登录
- PLATO上线LAAS协议Elephant Swap,用户可借此获得溢价收益
- Thread lock and its ascending and descending levels
- 什么是原码、反码和补码
- Digital twin rail transit: "intelligent" monitoring to clear the pain points of urban operation
- ACM SIGIR 2022 | interpretation of selected papers of meituan technical team
- Synchronized keyword details
- Naver 三方登录
- Dart array, map, type judgment, conditional judgment operator, type conversion
- Flink Postgres CDC
猜你喜欢

How to deal with the time, scope and cost constraints in the project?

Flink Postgres CDC

Intel introduces you to visual recognition -- openvino

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

Flink SQL Hudi 实战

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

了解各种路径

18 diagrams, intuitive understanding of neural networks, manifolds and topologies

Solid smart contract tutorial (5) -nft auction contract

Spark 3.0 中七个必须知道的 SQL 性能优化
随机推荐
Day2: 130 questions in three languages
Bracket matching test
log4j动态加载配置文件
图扑软件亮相 2022 福州数博会,携手共创数字新时代
Google play APK uploads other international app stores
[Jenkins' notes] introduction, free space; Continuous integration of enterprise wechat; Allure reports, continuous integration of email notifications; Build scheduled tasks
Instruction rearrangement, happens before, as if serial
PLATO上线LAAS协议Elephant Swap,用户可借此获得溢价收益
正则校验与时间格式化
Docker-compose安装mysql
面试官:程序员,请你告诉我是谁把公司面试题泄露给你的?
Linux redis source code installation
Introduction to FLV documents
【ManageEngine】局域网监控软件是什么,有什么作用
js判断 数组/对象数组 1 是否包含数组/对象数组 2
DVWA之SQL注入
量化交易之数字货币篇 - 生成foot print因子数据
一文读懂Okaleido Tiger近期动态,挖掘背后价值与潜力
Error installing mysqlclient module on MAC system
mysql 创建索引的三种方式