当前位置:网站首页>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
边栏推荐
- Arm32进行远程调试
- Pytorch 相关-梯度回传
- P6118 [joi 2019 final] solution to the problem of Zhenzhou City
- @Valid的作用(级联校验)以及常用约束注解的解释说明
- els 键盘信息
- 蓝桥杯原题
- Using pytorch's tensorboard visual deep learning indicators | pytorch series (25)
- Niuke-top101-bm340
- 注意,这些地区不能参加7月NPDP考试
- Collision and rebound of objects in unity (learning)
猜你喜欢

Games101 review: ray tracing

数据中台建设(三):数据中台架构介绍

Which of the four solutions of distributed session do you think is the best?

Redis AOF log persistence

Day 19 of leetcode

Intelligent industrial design software company Tianfu C round financing of hundreds of millions of yuan

Data Lake: flume, a massive log collection engine

Flutter God operation learning (full level introduction)

数据湖:海量日志采集引擎Flume

JVM memory layout detailed, illustrated, well written!
随机推荐
阿憨的故事
JS 事件对象 offsetX/Y clientX Y PageX Y
Yiwen teaches you to distinguish between continuous integration, continuous delivery and continuous deployment
JS event object 2 e.charcode character code e.keycode key code box moves up, down, left and right
Constant power wireless charging based on stm32
What "posture" does JD cloud have to promote industrial digitalization to climb to a "new level"?
JS event object offsetx/y clientx y pagex y
蓝桥杯原题
Is it you who are not suitable for learning programming?
优炫数据库客户端如何认证
stm32F407-------DSP学习
Where do I go to open an account for stock speculation? Is it safe to open an account on my mobile phone
Pytest the best testing framework
CNN中的混淆矩阵 | PyTorch系列(二十三)
Confusion matrix in CNN | pytorch series (XXIII)
Pychart shortcut key for quickly modifying all the same names on the whole page
R 笔记 MICE
数据中台建设(三):数据中台架构介绍
How to authenticate Youxuan database client
【微信小程序开发(六)】绘制音乐播放器环形进度条