gsnakehlp.cpp

来自「一个自己编写的贪食蛇游戏.」· C++ 代码 · 共 70 行

CPP
70
字号
#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 + =
减小字号Ctrl + -
显示快捷键?