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

📄 els.cpp

📁 一个用vc编写的俄罗斯方块和贪吃蛇游戏的源代码
💻 CPP
字号:
// Els.cpp: implementation of the CEls class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "games.h"
#include "Els.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CEls::CEls()
{
	m_Hotp = (-1, -1);
	m_nType = -1;
	m_nMoveType = -1;
	m_nOldType = -1;
}

CEls::CEls(UINT nType, int x, int y)
{
	m_Hotp = m_Oldp = CPoint(x, y);
	m_nType  = nType;
	m_nMoveType = m_nOldType = 1;
}

CEls::~CEls()
{

}

void CEls::SetMoveType(int off)
{
	m_nOldType = m_nMoveType;

	m_nMoveType += off;
	if(m_nMoveType == 5)
		m_nMoveType = 1;
	else if(m_nMoveType == 0)
		m_nMoveType = 4;

}

void CEls::SetMoveType()
{
	m_nOldType = m_nMoveType;
// 	m_Oldp = m_Hotp;
}

void CEls::SetHotPoint(int xOff, int yOff)
{
//	m_Oldp = m_Hotp;
	m_Hotp.x += xOff;
	m_Hotp.y += yOff;
}

int CEls::GetPointNum()
{
	int re;
	switch(m_nType)
	{
	case 0:          // *****
		re = 5;
		break;
	case 1:
	case 2:
	case 3:
	case 4:
		re = 4;
		break;
	case 5:
	case 6:
	case 7:
		re = 6;
		break;
	case -1:         //NULL
		re  =0;
		break;
	}
	
	return re;
}

CPoint CEls::GetPoint(int num, BOOL b)
{
	CPoint reP(0,0);
	int xOff = 0;
	int yOff = 0;

	UINT nType;
	if(b) 
		nType = m_nMoveType;
	else
		nType = m_nOldType;

	switch(m_nType)
	{
	case 0:          
		if(nType == 1 || nType == 3) // *****
			xOff = 24 * (num - 2);
		else
			yOff = 24 * (num - 2);
		break;

	case 1:
		if(nType == 1)
						// *
						// * *
						// *
		{
			if(num < 3)
				yOff = 24 * (num - 1);
			else
				xOff = 24;

		}
		else if(nType == 2)
					    //   *
						// * * *
		{
			if(num < 3)
				xOff = 24 * (num - 1);
			else
				yOff = -24;
		}
		else if(nType == 3)
						//   *
						// * *
						//   *
		{
			if(num < 3)
				yOff = 24 * (num - 1);
			else
				xOff = -24;
		}
		else if(nType == 4)
						// * * *
						//   *
		{
			if(num < 3)
				xOff = 24 * (num - 1);
			else
				yOff= 24;
		}
		break;
	
	case 2:
		if(nType == 1 || nType == 3)
						// * *
						//   * *
		{
			if(num < 2)
				xOff = 24 * (num - 1);
			else
			{	
				xOff = 24 * (num - 2);
				yOff = 24;
			}
		}
		else if(nType == 2 || nType == 4)
					    //   *
						// * *
						// * 
		{
			if(num < 2)
				yOff = 24 * (1 - num);
			else
			{
				xOff = 24;
				yOff = 24 * (2 - num);
			}
		}
		break;
	
	case 3:
		if(nType == 1 || nType == 3)
						//    * *
						//  * *
		{
			if(num < 2)
				xOff = 24 * (1 - num);
			else
			{	
				xOff = 24 * (2 - num);
				yOff = 24;
			}
		}
		else if(nType == 2 || nType == 4)
					    // *
						// * *
						//   * 
		{
			if(num < 2)
				yOff = 24 * (num - 1);
			else
			{
				xOff = 24;
				yOff = 24 * (num - 2);
			}
		}
		break;

	case 4:          // **
					 // ** 
		if(num <= 1)
			xOff = 24 * num;
		else
		{
			xOff = 24 * (num - 2);
			yOff = 24;
		}
		break;
	
	case 5:          //***
					 //  ***
		if(nType == 1 || nType == 3)
		{
			if(num <= 2)
				xOff = 24 * (num - 2);
			else
			{	
				xOff = 24 * (num - 3);
				yOff = 24;
			}
		}
		else if(nType == 2 || nType == 4)
						//   *
						//   *
						// * *
						// *
						// *
		{
			if(num <= 2)
				yOff = 24 * (2 - num);
			else
			{	
				yOff = 24 * (3 - num);
				xOff = 24;
			}
		}
		break;

	case 6:          //    ***
					 //  ***
		if(nType == 1 || nType == 3)
		{
			if(num <= 2)
				xOff = 24 * (num - 2);
			else
			{	
				xOff = 24 * (num - 3);
				yOff = -24;
			}
		}
		else if(nType == 2 || nType == 4)
						//   *
						//   *
						//   * *
						//     *
						//     *
		{
			if(num <= 2)
				yOff = 24 * (num - 2);
			else
			{	
				yOff = 24 * (num - 3);
				xOff = 24;
			}
		}
		break;

	case 7:								// ***
										//   *
										//	 *
		if(nType == 1)			      //	 *
		{
			if(num <= 2)
			xOff = 24 * (num - 2);
			else
			{	
				yOff = 24 * (num - 2);
			}
		}
		
		else if(nType == 2)      // ****
			                     // *
							     // *
		{
			 if(num <= 3)
				 xOff = 24 * num;
			 else
				 yOff = 24 * (num - 3);
		}
		else if(nType == 3)            // *
			                           // *
									   // *
									   // ***
		{
			 if(num <= 3)
				 yOff = 24 * -num;
			 else
				 xOff = 24 * (num - 3);
		}
		else if(nType == 4)       
			                           //    *
									   //    *
									   // ****
		{
			 if(num <= 3)
				 xOff = 24 * -num;
			 else
				 yOff = 24 * -(num - 3);
		}
		break;
	case 10:          // *****
		        		 // *   *
					 //	*   *
		if(nType == 1)
		{
			if(num <= 4)
				xOff = 24 * (num - 2);
			else if(num == 5 || num == 6)
			{
				xOff = 24 * 2;
				yOff = 24 * (num - 4);
			}
			else if(num == 7 || num == 8)
			{
				xOff = 24 * -2;
				yOff = 24 * (num - 6);
			}
		}
		else if(nType == 2)
							// * * *
							// *
							// *
							// *
							// * * *
		{
			if(num <= 4)
			{
				yOff = 24 * (num - 2);
			}
			else if(num == 5 || num == 6)
			{
				xOff = 24 * (num - 4);
				yOff = 24 * -2;
			}
			else if(num == 7 || num == 8)
			{
				xOff = 24 * (num - 6);
				yOff = 24 * 2;
			}
		}
		else if(nType == 3)
							// *       *
							// *       *
							// * * * * *
		{
			if(num <= 4)
			{
				xOff = 24 * (num - 2);
			}
			else if(num == 5 || num == 6)
			{
				yOff = 24 * (4 - num);
				xOff = 24 * -2;
			}
			else if(num == 7 || num == 8)
			{
				yOff = 24 * (6 - num);
				xOff = 24 * 2;
			}
		}
		else if(nType == 4)
						     // * * *
							 //     *
							 //     *
							 //     *
							 // * * *
		{
			if(num <= 4)
			{
				yOff = 24 * (num - 2);
			}
			else if(num == 5 || num == 6)
			{
				yOff = 24 * 2;
				xOff = 24 * (4 - num);
			}
			else if(num == 7 || num == 8)
			{
				xOff = 24 * (6 - num);
				yOff = 24 * -2;
			}
		}

		break;


	}
	reP = CPoint(m_Hotp.x + xOff, m_Hotp.y + yOff);
	return reP;
}

CEls CEls::operator=(const CEls &Es)
{
	m_nType = Es.m_nType;
	m_Hotp = Es.m_Hotp;
	m_nMoveType = Es.m_nMoveType;
	m_nOldType = Es.m_nOldType;

	return *this;
}

⌨️ 快捷键说明

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