当前位置:网站首页>els 显示一个随机方块
els 显示一个随机方块
2022-07-28 02:06: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++)
{
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];
}
}
}
2、头函数(els.h)
#ifndef N_d
#define N_d
#include<Windows.h>
#include<time.h>
void OnPaint(HDC hDc);
//显示方块。
void PaintSqare(HDC hMemDC);
//产生随机块。
int CreateRandomSqare();
//随机块贴近背景。
void CopySqareToBack();
void Oncreate();
#endif
边栏推荐
- Docker高级篇-Docker容器内Redis集群配置
- [QNX Hypervisor 2.2用户手册]9.10 pass
- Introduction to the reduce() function in JS
- [TA frost wolf \u may - hundred people plan] Figure 3.7 TP (d) r architecture of mobile terminal
- Opengauss Developer Day 2022 sincerely invites you to visit the "database kernel SQL Engine sub forum" of Yunhe enmo
- Welcome to CSDN markdown editor Assad
- Center Based 3D object detection and tracking (centerpoint) paper notes
- Gbase8s how to delete data in a table with a foreign key relationship
- First knowledge of C language -- structure, branch and loop statements
- Pycharm 快速给整页全部相同名称修改的快捷键
猜你喜欢

Representation of children and brothers of trees

Superparameter adjustment and experiment - training depth neural network | pytorch series (26)
![[software testing] - unittest framework for automated testing](/img/7a/29b222cb0b6a5953b98f8d797cd106.png)
[software testing] - unittest framework for automated testing

JS event object offsetx/y clientx y pagex y

Day 19 of leetcode

tfx airflow 使用体验

Retainface use error: modulenotfounderror: no module named'rcnn.cyton.bbox'

JS 事件对象2 e.charcode字符码 e.keyCode键码 盒子上下左右移动

Redis AOF log persistence

意外收获史诗级分布式资源,从基础到进阶都干货满满,大佬就是强!
随机推荐
Oracle basicfile lob field space recycling shrink space doubts
Development and design logic of rtsp/onvif protocol easynvr video platform one click upgrade scheme
[ACNOI2022]总差一步
Skills in writing English IEEE papers
【红队】ATT&CK - 文件隐藏
Is it safe to buy funds on Alipay? I want to make a fixed investment in the fund
How do you use the jar package sent by others (how to use the jar package sent by others)
How do gateways and chirpstacks in lorawan communicate? UDP? GRPC? MQTT?
Pytorch 相关-梯度回传
[signal denoising] signal denoising based on Kalman filter with matlab code
[elm classification] classification of UCI data sets based on nuclear limit learning machine and limit learning machine, with matlab code
First knowledge of C language -- structure, branch and loop statements
Four methods of modifying MySQL password (suitable for beginners)
Eigenvalues and eigenvectors
意外收获史诗级分布式资源,从基础到进阶都干货满满,大佬就是强!
[image defogging] image defogging based on dark channel and non-mean filtering with matlab code
[brother hero's July training] day 27: picture
[QNX Hypervisor 2.2用户手册]9.10 pass
First knowledge of C language -- operators and keywords, define, pointer
Docker高级篇-Docker容器内Redis集群配置