⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gsnakehlp.cpp

📁 一个自己编写的贪食蛇游戏.
💻 CPP
字号:
#include "stdafx.h"

#include "GSnakeID.h"

bool PixelsToPos(int &x, int &y)
{
	int xx = x, yy = y;


	if( PixelinPos(xx, QI_KUAN) && PixelinPos(yy, QI_GAO))
	{
		x = xx;
		y = yy;
		return true;
	}

	return false;

}

bool PosToPixels(int &px, int &py)
{
	if( (px >= 1 && px<= QI_KUAN) && (py >= 1 && py <= QI_GAO))
	{
		px = INITPOS_X + (px-1)*INTERVAL;
		py = INITPOS_Y + (py-1)*INTERVAL;
		return true;
	}
	return false;
}

bool PixelinPos(int &x, int w)
{
	int px, xx = x;

	for(int i = 0; i<= w; i++)
	{
		px =i*INTERVAL+INITPOS_X;
		if( px-SNK_KUAN < x && px+SNK_KUAN > x )
		{
			x = i;
			return true;
		} 
	}
	return false;

}
void ClearBlock(HDC hdc, int x, int y)
{
	HPEN	hPen,	oldhPen;
	HBRUSH	hBrush, oldhBrush;
	
	hPen	= CreatePen(PS_INSIDEFRAME,1,BK_COLOR);
	oldhPen = (HPEN)SelectObject(hdc,(HPEN)hPen);
	hBrush	= (HBRUSH)CreateSolidBrush(BK_COLOR);

	oldhBrush = (HBRUSH)SelectObject(hdc,(HBRUSH)hBrush);

	if(PosToPixels(x, y))
	{
		Rectangle(hdc, x, y, x+SNK_KUAN, y+SNK_KUAN);
	}

	
	SelectObject(hdc, oldhPen);
	SelectObject(hdc, oldhBrush);
	DeleteObject(hPen);
	DeleteObject(hBrush);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -