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

📄 game.cpp

📁 黑白道游戏源码,VC环境编写
💻 CPP
字号:
//		Game.cpp: implementation of the CGame class.
//		write by: fatehost
//			date: 2004-1-16
//	 description: 这是一个黑白道游戏
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "hebai.h"
#include "Game.h"

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

#define CHECK_EXP  x > XSIZE || x<0 || y>YSIZE || y<0
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CGame::CGame()
{
	InitGameAry();
}

CGame::~CGame()
{

}

	/************************************************
	*
	*初始化数组
	*
	*************************************************/
void CGame::InitGameAry()
{
	srand((unsigned)time(NULL));

	for( int i=0; i<XSIZE; i++)
	{
		for( int j=0; j<YSIZE; j++)
		{
			m_uGameAry[i][j]=rand()%2;
			m_uTempAry[i][j]=m_uGameAry[i][j];
		}
	}
}
	
	/************************************************
	*
	*玩家点击x,y处。根据黑白道游戏规则改变数组
	*ary[x][y]=nValue
	*************************************************/
bool CGame::SetTempGameAry(int x,int y,int nValue)
{
	//if ( x > XSIZE || x<0 || y>YSIZE || y<0)
	if ( CHECK_EXP )
	{
		return false;
	}
	
	//改变x,y位置的值
	m_uTempAry[x][y]= m_uTempAry[x][y]?0:1;

	//改变左边的值
	if( y-1 >= 0)
	{
		m_uTempAry[x][y-1]= m_uTempAry[x][y-1]?0:1;
	}

	//改变上方的值
	if( x-1 >= 0)
	{
		m_uTempAry[x-1][y]= m_uTempAry[x-1][y]?0:1;
	}

	//改变右方的值
	if( y+1 <YSIZE)
	{
		m_uTempAry[x][y+1]= m_uTempAry[x][y+1]?0:1;
	}

	//改变下方的值
	if( x+1 < XSIZE)
	{
		m_uTempAry[x+1][y]= m_uTempAry[x+1][y]?0:1;
	}
	return true;
}

	/************************************************
	*
	*获取数组值,错误返回-1
	*
	*************************************************/
int CGame::GetTempGameAry(int x,int y)
{
	if( CHECK_EXP )
	{
		return -1 ;
	}
	return m_uTempAry[x][y];
}

	/************************************************
	*
	*获取最初数组值,错误返回-1
	*
	*************************************************/
int CGame::GetOrgAry(int x , int y)
{
	if( CHECK_EXP )
	{
		return -1;
	}
	return m_uGameAry[x][y];
}
	/************************************************
	*
	*重来
	*
	*************************************************/
void CGame::RePlay()
{

}

⌨️ 快捷键说明

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