当前位置:网站首页>ELS displays a random square
ELS displays a random square
2022-07-28 03:09: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);
// 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++)
{
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];
}
}
}
2、 Head function (els.h)
#ifndef N_d
#define N_d
#include<Windows.h>
#include<time.h>
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();
#endif
边栏推荐
- JS 事件对象 offsetX/Y clientX Y PageX Y
- MySQL索引学习
- ORACLE BASICFILE LOB字段空间回收SHRINK SPACE的疑惑
- 分布式 session 的4个解决方案,你觉得哪个最好?
- Note that these regions cannot take the NPDP exam in July
- Confusion matrix in CNN | pytorch series (XXIII)
- Arm32 for remote debugging
- 数据中台夯实数据基础
- Development and design logic of rtsp/onvif protocol easynvr video platform one click upgrade scheme
- 小程序已获取数据库合集中的总记录、用户位置,怎么用Aggregate.geoNear将经纬度由近到远排列?
猜你喜欢

MySQL index learning
![[wechat applet development (VI)] draw the circular progress bar of the music player](/img/eb/9ce5d196970a6d6a887bf3e1d742ee.png)
[wechat applet development (VI)] draw the circular progress bar of the music player

MySQL索引学习

Record of a cross domain problem

每日刷题巩固知识
![[signal denoising] signal denoising based on Kalman filter with matlab code](/img/9e/9e569c83dc3106570cf7571056867f.png)
[signal denoising] signal denoising based on Kalman filter with matlab code

ROS的调试经验

Job 7.27 IO process

Pytest the best testing framework

@The function of valid (cascade verification) and the explanation of common constraint annotations
随机推荐
【stream】并行流与顺序流
Arm32进行远程调试
Why is it that when logging in, you clearly use the account information already in the database, but still display "user does not exist"?
Collision and rebound of objects in unity (learning)
Data center construction (III): introduction to data center architecture
Data Lake: flume, a massive log collection engine
Confusion matrix in CNN | pytorch series (XXIII)
Redis AOF log persistence
数据湖:海量日志采集引擎Flume
Unexpected harvest of epic distributed resources, from basic to advanced are full of dry goods, big guys are strong!
style=“width: ___“ VS width=“___“
Niuke-top101-bm340
【红队】ATT&CK - 文件隐藏
MySQL index learning
@Valid的作用(级联校验)以及常用约束注解的解释说明
“29岁,普通功能测试,我是如何在一周内拿到5份Offer的?”
蓝桥杯:第九届—“彩灯控制器”
CNN训练循环重构——超参数测试 | PyTorch系列(二十八)
Is the securities account given by qiniu safe? Can qiniu open an account and buy funds
NPDP candidates! The exam requirements for July 31 are here!