当前位置:网站首页>ELS new box falls
ELS new box falls
2022-07-29 01:40:00 【joker_ 0030】
1、 Function implementation (els.c)
#include"els_h.h"
// Background array
char g_arrBackGroud[20][10] = {0};
char g_arrSqare[2][4] = {0};
void OnPaint(HDC hDc)
{
// Create compatibility DC.
HDC hMemDC = CreateCompatibleDC(hDc);// Memory id by :HMemDc, window id hDc.
// Create compatibility bitmap .
HBITMAP hBitmapBack= CreateCompatibleBitmap(hDc, 500, 600);
// Connect .
SelectObject(hMemDC, hBitmapBack);
PaintSqare(hMemDC);
ShowSqare2(hMemDC);
// Pass on :
// Return value : Failure to return 0, Successfully returned non-zero .
// Parameters 1: The goal is DC, window DC
// Parameters 2,3: The starting position of the target , Attention is based on our window .
// Parameters 4,5: The size of the area .
// Parameters 6: Source DC, That is, our memory DC.
// Parameters 7,8: The starting position of the memory picture .
// Parameters 9: delivery .
//
BitBlt(hDc, 0, 0, 300, 600, hMemDC, 0, 0, SRCCOPY);
// Release DC
DeleteObject(hBitmapBack);
DeleteDC(hMemDC);
}
void Oncreate()
{
srand((unsigned int)time(NULL));// Only once .
CreateRandomSqare();
CopySqareToBack();
}
void PaintSqare(HDC hMemDC)
{
int i = 0,
j = 0;
// Draw a big square .
Rectangle(hMemDC, 0, 0, 300, 600);// The coordinates of the starting position and the ending position of the rectangular box from the running window .
// Specify a square .
/*g_arrBackGroud[2][4] = 1;
g_arrBackGroud[3][3] = 1;
g_arrBackGroud[3][4] = 1;
g_arrBackGroud[3][5] = 1;*/
// Traverse
for (i=0 ; i < 20; i++)//2、?
{
for (j=0 ; j < 10; j++)
{
if (1 == g_arrBackGroud[i][j])
{
// Draw squares .
Rectangle(hMemDC, j*30, i*30, j*30 + 30, i*30 + 30);// The coordinates of the starting position and the ending position of the rectangular box from the running window .
}
}
}
}
// Create random block .
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)
{
// Start timer
// Return value : Successfully returned non-zero .
// Parameters 1: Window handle hWnd,NUL
// Parameters 2: Timer ID Ignore
// Parameters 3: Time interval between , millisecond 1000ms=1s.
// Parameters 4: Set to NULL Address of processing function .
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);// Kernel object .
if (1 == CanSqareDown())
{
SqareDwon();// Stop falling .
}
else
{
//1 To 2
Change1To2();
// Generate random blocks .
CreateRandomSqare();
// Copy to background .
CopySqareToBack();
}
//SqareDwon();
// Display box :
//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;
}
void Change1To2()
{
int i = 0,
j = 0;
for ( i = 0; i < 20; i++)
{
for ( j = 0; j < 10; j++)
{
if (1==g_arrBackGroud[i][j])
{
g_arrBackGroud[i][j] = 2;
}
}
}
}
void ShowSqare2(HDC hMemDC)
{
int i = 0,
j = 0;
for ( i = 0; i < 20; i++)
{
for ( j = 0; j < 10; j++)
{
if (2 == g_arrBackGroud[i][j])
{
Rectangle(hMemDC, j * 30, i * 30, j * 30 + 30, i * 30 + 30);// The coordinates of the starting position and the ending position of the rectangular box from the running window .
}
}
}
}
2、 Head function (els.h)
#ifndef N_d
#define N_d
#include<Windows.h>
#include<time.h>
#define DEF_TIMER1 1234
void OnPaint(HDC hDc);
// Display box .
void PaintSqare(HDC hMemDC);
// Generate random blocks .
int CreateRandomSqare();
// Random blocks close to the background .
void CopySqareToBack();
void Oncreate();
// Enter key .
void OnReturn(HWND hWnd);
// The fall of the square .
void SqareDwon();
// Timer response function .
void OnTimer(HWND hWnd);
// The box stops at the bottom
int CanSqareDown();
// take 1 become 2.
void Change1To2();
// Show 2
void ShowSqare2(HDC hMemDC);
#endif
边栏推荐
- Self-attention neural architecture search for semantic image segmentation
- How to choose professional, safe and high-performance remote control software
- [search] - iteration deepening / bidirectional dfs/ida*
- Flink Postgres CDC
- New 1688 API access instructions
- API stability guarantee of Prometheus
- RHCE command practice (II)
- 了解各种路径
- 第二轮Okaleido Tiger热卖的背后,是背后生态机构战略支持
- 一文读懂Okaleido Tiger近期动态,挖掘背后价值与潜力
猜你喜欢

Basic label in body

T-sne降维

Embedded sharing collection 23

过去10年的10起重大网络安全事件
![A ten thousand word blog post takes you into the pit. Reptiles are a dead end [ten thousand word pictures]](/img/aa/a5e7b4516aa395f8d4d0e2eee7d3c7.png)
A ten thousand word blog post takes you into the pit. Reptiles are a dead end [ten thousand word pictures]

SQL question brushing: find the last of all employees who have been assigned departments_ Name and first_ Name and Dept_ no
![[hcip] MPLS Foundation](/img/91/a2aebf333fb3e3fedf0fc393e175a9.png)
[hcip] MPLS Foundation

PlatoFarm社区生态福音,用户可借助Elephant Swap获得溢价收益

SQL question brushing: find the employee number EMP with more than 15 salary records_ No and its corresponding recording times t

瑞吉外卖项目实战Day01
随机推荐
New upgrade: get Taobao product details "advanced version" API
Focus on differentiated product design, intelligent technology efficiency improvement and literacy education around new citizen Finance
Openpyxl cell center
vm options、program arguments、environment property
Flink SQL Hudi actual combat
Flash reports an error: type object 'news' has no attribute' query 'the view name is duplicate with the model name
Log4j dynamic loading configuration file
Nacos installation guide on win system
Read the recent trends of okaleido tiger and tap the value and potential behind it
TypeError: can only concatenate str (not “int“) to str
数据库的decimal类型的数据,发现可以通过resultSet.getDouble去拿到这个数据,但是通过getObject却拿不到这个属性。
els 方块移动
How to choose professional, safe and high-performance remote control software
Plato launched the LAAS protocol elephant swap, which allows users to earn premium income
Intel introduces you to visual recognition -- openvino
uniapp createSelectorQuery().select 获取返回null报错
【HCIP】两个MGRE网络通过OSPF实现互联(eNSP)
BOM系列之定时器
梅克尔工作室——HarmonyOS实现列表待办
代码生成器