14号,不该胡说,今天锅真坏了,研究下怎么用茶壶煮水饺.....

这是两种类型的扫雷游戏,说是3D版其实还是2D版贴在了桌面上而已。有部分提示功能,无联机功能。

第一种类型是经典玩法,每个格子中的数字代表周围九宫格中雷的数目。

ios swift简单扫雷游戏源码 android扫雷游戏源码_General

第二种扫雷游戏,在每一行的右边有一排数字代表该行中空格的布局,每一列下面也有一排数字代表该列中空格的布局。每点到一个雷会损失一条生命。 

ios swift简单扫雷游戏源码 android扫雷游戏源码_游戏_02

第一种源码:

#ifndef  __MiniGameMineClear__H__
#define  __MiniGameMineClear__H__

#include "Rpg/MiniGame.h"
#include "Render/Texture.h"
#define MaxCol 50
#define MaxRow 30
class MiniGameMineClear:public MiniGame
{
public:
	MiniGameMineClear();	
	virtual ~MiniGameMineClear();

public:
	enum BlockState
	{
		Intact         = 0, //初始未翻状态
		Flag_Mine      = 1, //右键标记为雷
		Flag_Question  = 2, //右键标记问号

		MineClick    = 3,
		MineCross    = 4,

		MineNormal = 5,
		//Question  = 6, 
		Num8 = 7,//15-8
		Num7,
		Num6,
		Num5,
		Num4,
		Num3,
		Num2,
		Num1,
		Num0 = 15,
	};
	class Block
	{
	public:
		vec2I grid;
		char  display;
		char  real;
	};

	void OnLose();
	void OnClear();

	virtual bool Start();
	virtual bool Stop();
	virtual bool Render();
	virtual void RenderUI();
	virtual bool Update();
	virtual bool Free();
	virtual bool KeepResource(bool once,int& circle,String& nextTip);

	//三种类型结构
	virtual MiniPlayer*  CreatePlayer();
	virtual MiniPlayer*  CreateRobot ();
	virtual MiniPlayer*  CreateRole  ();

	void LoadFromFile(const char* filename);
	void SaveToFile(const char* filename);

	void OnLButtonUp();
	void OnRButtonUp();
	void OnMouseMove();
	void OnMButtonDown();  
	void OnMButtonUp();  
	bool IsEnd();

private:
	Block* GetBlock(const vec2& screenPos);
	Block* GetNeiBlock(Block* block,int index);
	void FindOut(Block* block);

protected:
	int m_allMineClearNum;
	int m_leftMineClearNum;
	int m_Status;
	int m_Level;

	vec2 m_blockNum;
	vec2 m_blockSize;

	RectF m_gameRect;

	//列主序
	Block m_blocks[MaxCol][30];

	TexturePtr  m_texBlock;
	TexturePtr  m_texFace;
	TexturePtr  m_texBack;
	TexturePtr  m_texCloud;

	RectF       m_rectFace;
	RectF       m_rectLevel;
};

extern MiniGameMineClear* G_MineClearGame;

#endif 


#include "General/Pch.h"
#include "MineClear/MiniGameMineClear.h"
#include "Render/RendDriver.h"
#include <stdlib.h>
#include "General/Window.h"
#include "Input/InputMgr.h"
#include "General/Timer.h"
#include "Render/MC_MovieClip.h"
#include "Render/Camera.h"
#include "Render/Shader.h"
#include "Gui/GuiMgr.h"
#include "General/File.h"
#include "General/Pce.h"

enum {DOWN,WIN,LOSE,CRY,SMILE};
enum {ACTIVE,ISWIN,ISLOSE};

MiniGameMineClear* G_MineClearGame = NULL;

MiniGameMineClear::MiniGameMineClear()
{
	G_MineClearGame = this;
	m_blockSize=vec2(24,24);
	m_Level=2;
}
MiniGameMineClear::~MiniGameMineClear()
{
	G_MineClearGame = NULL;
}


bool MiniGameMineClear::Start()
{
	if(!MiniGame::Start())
		return false;

	G_TextureMgr->AddTexture(m_texFace, "data/minigame/mineclear/face.png");
	G_TextureMgr->AddTexture(m_texBlock,"data/minigame/mineclear/block.png");
	G_TextureMgr->AddTexture(m_texBack, "data/minigame/mineclear/back.png");
	G_TextureMgr->AddTexture(m_texCloud,"data/environment/clouds/cloud2.png");
	//
	if (m_movieScene == NULL)
	{
		LoadConfig loader(LoadConfig::GenDonotReShrinkBound, true, true);
		m_movieScene = new RendSys::MovieClip;
		m_movieScene->LoadFromFile("data/minigame/mineclear/board.movie", &loader);

		Frame frame;
		frame.SetPos(m_startPos);
		m_movieScene->SetProgramFrame(&frame);
		m_movieScene->Advance();
	}

	if (m_movieScene->IsLoadComplete() == false)
	{
		m_gameState = MS_End;
		return false;
	}
	//m_Level=2;
	if(m_Level==0)
	{
		m_blockNum.y=10;
		m_blockNum.x=10;
		m_allMineClearNum=10;
	}
	if(m_Level==1)
	{
		m_blockNum.y=15;
		m_blockNum.x=15;
		m_allMineClearNum=40;
	}
	if(m_Level==2)
	{
		m_blockNum.y=20;
		m_blockNum.x=20;
		m_allMineClearNum=90;
	}


	float width__  = m_texBack->GetWidth(); 
	float height_  = m_texBack->GetHeight(); 
	SetBoardRect(RectF((G_Window->m_iWidth-width__)/2,(G_Window->m_iHeight-height_)/2,width__,height_), 
		RectF(m_startPos.x-50,m_startPos.z-33,100,66),
		m_startPos.y+10.1f);

	m_gameRect.SetPos(BoardRect2D.GetPos() + vec2(26,23));
	m_gameRect.SetExtent(vec2(460,460));
	m_blockSize = m_gameRect.GetExtent()/m_blockNum;

	m_Status=ACTIVE;

	m_leftMineClearNum=m_allMineClearNum;
	int i,j;

	for(i=0; i<m_blockNum.x; i++)
	{
		for(j=0; j<m_blockNum.y; j++)
		{
			m_blocks[i][j].display=0;//current display
			m_blocks[i][j].real=0;   //m_mines table   实际的
			m_blocks[i][j].grid=vec2I(i,j);
		}
	}

	vec2I block;
	for(int i=0; i<m_allMineClearNum;)
	{
		block.x=Rand() % (int)m_blockNum.x ;
		block.y=Rand() % (int)m_blockNum.y;
		if(m_blocks[block.x][block.y].real==0)
		{
			m_blocks[block.x][block.y].real=MineNormal;
			i++;
		}
	}

	for(i=0; i<m_blockNum.x; i++)
	{
		for(j=0; j<m_blockNum.y; j++)
		{
			Block* block = &m_blocks[i][j];
			if(block->real!=MineNormal)
			{
				int mineNum=0;
				for(int k=0; k<8; k++)
				{
					Block* blockit = GetNeiBlock(block,k);
					if(blockit && blockit->real==MineNormal)
					{
						mineNum++;
					}
				};
				m_blocks[i][j].real=15-mineNum;
			}
		}
	}

	//进入miniplaygui,(选人、选关卡都已在房间里进行完毕)。
	if(GetStyle()) G_GuiMgr->PushGui(GetStyle()->playGUI.c_str(),GL_DIALOG);

	//PlaySoundEx(SOUND_BEGIN);

	//设置摄像机
	CameraCtrlerTarget* ctrler = new CameraCtrlerTarget;
	ctrler->SetDistToTar(60);
	ctrler->SetTarPos(m_startPos);
	G_Camera->PushCtrler(ctrler);	
	G_Camera->SetEuler(0, -60, 0);
	//片头摄像机
	PushIntroCamera();

	return true;
}

MiniPlayer* MiniGameMineClear::CreatePlayer()
{
	return NULL  ;
}

MiniPlayer* MiniGameMineClear::CreateRobot()
{
	return NULL  ;
}

MiniPlayer* MiniGameMineClear::CreateRole()
{
	return NULL;
}

bool MiniGameMineClear::Stop()
{
	MiniGame::Stop();
	return true;
}

bool MiniGameMineClear::Free()
{
	MiniGame::Free();
	return true;
}

bool MiniGameMineClear::KeepResource(bool once,int& circle,String& nextTip)
{
	return true;
}

bool MiniGameMineClear::Update()
{
	MiniGame::Update();
	{
		float width__  = m_texBack->GetWidth(); 
		float height_  = m_texBack->GetHeight(); 
		SetBoardRect(RectF((G_Window->m_iWidth-width__)/2,(G_Window->m_iHeight-height_)/2,width__,height_), 
			RectF(m_startPos.x-50,m_startPos.z-33,100,66),
			m_startPos.y+10.1f);

		m_gameRect.SetPos(BoardRect2D.GetPos() + vec2(26,23));
		m_gameRect.SetExtent(vec2(410,410));
	}
	
	if (G_Mouse->IsButtonUping(MOUSE_LEFT))
	{
		OnLButtonUp();
	}
	if (G_Mouse->IsButtonUping(MOUSE_RIGHT))
	{
		//OutputDebugStr("IsButtonUping\n");
		OnRButtonUp();
	}
	if (G_Mouse->IsButtonDowning(MOUSE_MIDDLE))
	{
		OnMButtonDown();
	}
	if (G_Mouse->IsButtonUping(MOUSE_MIDDLE))
	{
		OnMButtonUp();
	}
	if (m_3dMode)
	{
		m_movieScene->Advance();
	}
	IsEnd();
	return true;
}

bool MiniGameMineClear::Render()
{
	G_RendDriver->Color4f(1,1,1,1);
	if (m_3dMode)
	{
		G_RendDriver->EndUI();
		if(m_movieScene==NULL
			||m_movieScene->IsLoadComplete()==false)
			return false;
		m_movieScene->RendClip();

		G_RendDriver->PushMatrix();
		G_RendDriver->MultMatrix(mat2Dto3D);
	}
	else
	{
		G_RendDriver->BeginUI();
		//画背景
		m_texBack->Bind();
		G_RendDriver->DrawTextureRect(BoardRect2D);
	}

	if (G_ShaderMgr&& G_ShaderMgr->m_curEffect)
	{
		G_ShaderMgr->MapChangeParm();
	}

	//画时间和得分
	G_RendDriver->Color4f(1, 0, 0, 1);
	m_texLcdNumber->Bind();
	DrawLcd(3,m_gameTime,                           RectF(BoardRect2D.x+636, BoardRect2D.y+213, 39, 23));
	DrawLcd(3,1,                                    RectF(BoardRect2D.x+636, BoardRect2D.y+62, 39, 23));
	DrawLcd(3,m_allMineClearNum-m_leftMineClearNum, RectF(BoardRect2D.x+636, BoardRect2D.y+89, 39, 23));

	//画等级
	m_rectLevel = RectF(BoardRect2D.x+636, BoardRect2D.y+36, 39, 23);
	if(m_rectLevel.IsPointIn(this->GetMousePos()))
	{
		G_RendDriver->Color4f(1, 1, 0, 1);
	}
	else
	{
		G_RendDriver->Color4f(1, 0, 0, 1);
	}
	m_texLcdNumber->Bind();
	DrawLcd(3,m_Level, m_rectLevel);
	G_RendDriver->Color4f(1, 1, 1, 1);

	//画笑脸
	m_texFace->Bind();
	m_rectFace = RectF(BoardRect2D.x+609, BoardRect2D.y+347, 36, 36);
	if(m_rectFace.IsPointIn(this->GetMousePos()))
	{
		G_RendDriver->DrawTextureRect(m_rectFace, RectF(0, DOWN / 5.0f, 1, 1 / 5.0f));
	}
	else
	{
		if(m_Status==ACTIVE)
			G_RendDriver->DrawTextureRect(m_rectFace, RectF(0, SMILE / 5.0f, 1, 1 / 5.0f));
		else if(m_Status==LOSE)
			G_RendDriver->DrawTextureRect(m_rectFace, RectF(0, LOSE / 5.0f, 1, 1 / 5.0f));
		else if(m_Status==ISWIN)
			G_RendDriver->DrawTextureRect(m_rectFace, RectF(0, WIN / 5.0f, 1, 1 / 5.0f));
	}

	//画方块
	m_texBlock->Bind();
	for(int i=0; i<m_blockNum.x; i++)
	{
		for(int j=0; j<m_blockNum.y; j++)
		{
			int m=i*m_blockSize.x+m_gameRect.x;
			int n=j*m_blockSize.y+m_gameRect.y;
			G_RendDriver->DrawTextureRect(RectF(m,n,m_blockSize.x,m_blockSize.y),RectF(0,m_blocks[i][j].display/16.0f,1.0f,1.0f/16));
		}
	}

	//画选中
	Block* block = GetBlock(this->GetMousePos());
	if (block)
	{
		int m=block->grid.x*m_blockSize.x+m_gameRect.x;
		int n=block->grid.y*m_blockSize.y+m_gameRect.y;
		G_RendDriver->Color4f(0,0,1,0.3f);
		if (G_ShaderMgr&& G_ShaderMgr->m_curEffect)
		{
			G_ShaderMgr->MapChangeParm();
		}
		G_RendDriver->DrawRect(RectF(m,n,m_blockSize.x,m_blockSize.y));
	}

	//
	if (m_3dMode)
	{
		G_RendDriver->PopMatrix();
	}
	return true;
}

void MiniGameMineClear::RenderUI()
{

}

void MiniGameMineClear::OnLButtonUp()
{
	if(m_rectFace.IsPointIn(this->GetMousePos()))
	{
		//重新开始
		Start();
		return;
	}

	if(m_rectLevel.IsPointIn(this->GetMousePos()))
	{
		//重新开始
		m_Level++;
		m_Level%=3;
		//Start();
		return;
	}

	if(m_Status!=ACTIVE)
		return;

	vec2 point = this->GetMousePos();
	Block* block = GetBlock(point);
	if(block)
	{
		if(block->display!=Flag_Mine)
		{
			if( block->real==Num0)
			{
				FindOut(block);
			}
			else
			{
				block->display=block->real;
				OnClear();
			}
		};
		if(block->real==MineNormal)
		{
			block->display = MineClick;
			OnLose();
		};
	}
}

void MiniGameMineClear::OnRButtonUp()
{
	if(m_Status!=ACTIVE)
		return;

	vec2 point = this->GetMousePos();
	Block* block = GetBlock(point);
	if(block)
	{
		switch(block->display)
		{
		case Intact:
			block->display=Flag_Mine;
			m_leftMineClearNum--;
			break;
		case Flag_Mine:
			block->display=Flag_Question;
			m_leftMineClearNum++;
			break;
		case Flag_Question:
			block->display=Intact;
			break;
		}
	}
}

void MiniGameMineClear::OnMButtonDown()
{
	//if(m_Status!=ACTIVE && m_Status!=READY)return;
	//if(m_Status==READY)Start();

	//vec2 point = this->GetMousePos();
	//vec2I block = GetBlock(point);
	//if(block.x>=0)
	//{
	//	int tcol,tln,k;
	//	for(k=0; k<9; k++)
	//	{
	//		tcol=block.x+xmove[k];
	//		tln=block.y+ymove[k];
	//		if(InBound(tcol,tln))
	//		{
	//			//提示无法翻开的九宫格
	//			
	//		};
	//	}
	//}
	//OnWin();
};

void MiniGameMineClear::OnMButtonUp()
{
	if(m_Status!=ACTIVE)
		return;

	vec2 point = this->GetMousePos();
	Block* block = GetBlock(point);

	int num=0;
	for(int k=0; k<8; k++)
	{
		Block* blockit = GetNeiBlock(block,k);
		if(blockit && blockit->display==Flag_Mine)
			num++;
	}

	for(int k=0; k<9; k++)
	{
		Block* blockit = GetNeiBlock(block,k);
		if(blockit)
		{
			if(15-block->real==num             // 周边标记的雷数和实际雷数相同
				&& num!=0 
				&& blockit->display!=Flag_Mine // 自动翻开周边未标记雷的方块
				)
			{
				if(blockit->real==Num0)
				{
					FindOut(blockit);
				}
				else if(blockit->real==MineNormal)//翻错 失败
				{
					blockit->display = MineCross;
					OnLose();
				}
				else
				{
					blockit->display=blockit->real;
				}
			}
		}
	}
}

void MiniGameMineClear::OnMouseMove()
{
	vec2 point = this->GetMousePos();
}


void MiniGameMineClear::OnClear()
{
	PlaySound__("data/sound/ui_click.wav");
	IsEnd();
}
bool MiniGameMineClear::IsEnd()
{
	for(int i=0; i<m_blockNum.x; i++)
	{
		for(int j=0; j<m_blockNum.y; j++)
		{
			if( m_blocks[i][j].display!=Flag_Mine && m_blocks[i][j].real==MineNormal)
				return false;
		}
	}

	for(int i=0; i<m_blockNum.x; i++)
	{
		for(int j=0; j<m_blockNum.y; j++)
		{
			if( m_blocks[i][j].display<Num8 && m_blocks[i][j].real!=MineNormal)
				return false;
		}
	}

	m_Status=ISWIN;

	m_Level++;
	m_Level%=3;
	return true;
}
void MiniGameMineClear::OnLose()
{
	PlaySound__("data/sound/event_exploid02.wav");
	for(int i=0; i<m_blockNum.x; i++)
	{
		for(int j=0; j<m_blockNum.y; j++)
		{
			if(m_blocks[i][j].real==MineNormal)
			{
				//未翻开的翻开
				if(m_blocks[i][j].display==Intact)
					m_blocks[i][j].display = MineNormal;
				//已排除的
				else if(m_blocks[i][j].display==Flag_Mine)
					m_blocks[i][j].display = Flag_Mine;
				//当前翻错的
				else
					m_blocks[i][j].display = MineClick;

			}
			else
			{
				//标记错的打叉
				if(m_blocks[i][j].display==Flag_Mine)
					m_blocks[i][j].display=MineCross;
			}
		}
	}
	m_Status=ISLOSE;
}

void MiniGameMineClear::FindOut(Block* block)
{
	if (block && block->real==Num0)
	{
		block->display=Num0;
		for(int k=0; k<8; k++)
		{
			Block* blockit = GetNeiBlock(block,k);
			if(blockit)
			{
				if(blockit->display==Intact
					||blockit->display==Flag_Mine
					||blockit->display==Flag_Question
					)
				{
					PlaySound__("data/sound/event_equip.wav");
					blockit->display=blockit->real;
					if(blockit->real==Num0)
						FindOut(blockit);
				}
			}
		}
	}
}

MiniGameMineClear::Block*  MiniGameMineClear::GetBlock(const vec2& screenPos)
{
	int col=(screenPos.x-m_gameRect.x)/m_blockSize.x;
	int ln=(screenPos.y-m_gameRect.y)/m_blockSize.y;
	if (col<0||col>=m_blockNum.x
		||ln<0||ln>=m_blockNum.y)
	{
		return NULL;
	}
	return &m_blocks[col][ln];
}

MiniGameMineClear::Block* MiniGameMineClear::GetNeiBlock(Block* block,int index)
{
	int xmove[]= {-1,-1,0,1,-1,0,1,1,0};
	int ymove[]= {-1,0,-1,-1,1,1,0,1,0};
	int col=block->grid.x+xmove[index];
	int ln=block->grid.y+ymove[index];
	if (col<0||col>=m_blockNum.x
		||ln<0||ln>=m_blockNum.y)
	{
		return NULL;
	}
	return &m_blocks[col][ln];
}

void MiniGameMineClear::LoadFromFile(const char* filename)
{
	File file;
	if (file.Fopen(filename,"rt"))
	{
		if(strcmp("mathobj1.0",file.ReadString())!=0)
			return;
		m_Level = file.ReadInt();
		m_blockNum.x = file.ReadInt();
		m_blockNum.y = file.ReadInt();
		m_allMineClearNum = file.ReadInt();
		m_leftMineClearNum = file.ReadInt();
		//m_Timer=app->GetProfileInt("Save","Data1",1);

		int i,j;
		for(i=0; i<m_blockNum.x; i++)
		{
			for(j=0; j<m_blockNum.y; j++)
			{
				m_blocks[i][j].display = file.ReadInt();
				m_blocks[i][j].real = file.ReadInt();
				m_blocks[i][j].grid.x = file.ReadInt();
				m_blocks[i][j].grid.y = file.ReadInt();
			}
		}
	}
}

void MiniGameMineClear::SaveToFile(const char* filename)
{
	File file;
	if (file.Fopen(filename,"wt"))
	{
		//file.WriteString("mathobj1.0");                   file.Fprintf("\n");
		//file.WriteInt(mathType);						  file.Fprintf("\n");
		//file.WriteFloatArray(&color.r,4);				  file.Fprintf("\n");
		//file.WriteInt(lineWidth);						  file.Fprintf("\n");
		//file.WriteInt(fillMode);						  file.Fprintf("\n");
		//file.Fprintf("\n");
		//file.WriteFloatArray(&rangeX.x,2);				  file.Fprintf("\n");
		//file.WriteFloatArray(&rangeS.x,2);				  file.Fprintf("\n");
		//file.WriteFloatArray(&rangeR.x,2);				  file.Fprintf("\n");
		//file.WriteFloatArray(&rangeU.x,2);				  file.Fprintf("\n");
		//file.WriteFloatArray(&rangeV.x,2);				  file.Fprintf("\n");
		//file.WriteFloatArray(&rangeTime.x,2);			  file.Fprintf("\n");
		//file.Fprintf("\n");
		//file.WriteInt(stepNumX);						  file.Fprintf("\n");
		//file.WriteInt(stepNumS);						  file.Fprintf("\n");
		//file.WriteInt(stepNumR);						  file.Fprintf("\n");
		//file.WriteInt(stepNumU);						  file.Fprintf("\n");
		//file.WriteInt(stepNumV);						  file.Fprintf("\n");
		//file.Fprintf("\n");
		//file.WriteInt(enableAnim);						  file.Fprintf("\n");
		//file.WriteFloat(playTime);						  file.Fprintf("\n");
		//file.Fprintf("\n");
		//for (int i=0;i<FT_Max;i++)						  
		//{
		//	file.WriteString(fnExpress[i],512);      file.Fprintf("\n");
		//}
	}

	

}

第二种源码:

#ifndef  __MiniGameMineClear2__H__
#define  __MiniGameMineClear2__H__

#include "Rpg/MiniGame.h"
#include "Render/Texture.h"
//#include "Gui/GuiControlMisc.h"
#define MaxCol 50
#define MaxRow 30
class MiniGameMineClear2:public MiniGame
{
public:
	MiniGameMineClear2();	
	virtual ~MiniGameMineClear2();

public:
	enum BlockState
	{
		Intact        = 0, //初始未翻状态
		Flag_Mine     = 1, //右键标记为雷
		Flag_Question = 2, //右键标记问号

		MineClick  = 3,
		MineCross  = 4,
		MineNormal = 5,
		OpenClear  = 15,
	};
	class Block
	{
	public:
		char  display;
		char  real;
		vec2I grid;
	};
	//行或列的信息
	class LineInfo
	{
	public:
		//group是一组非雷块
		char  groupLen[50]; //各组长度
		char  gruopNum;     //组数
	};

	void OnLose();
	void OnClear();

	virtual bool Start();
	virtual bool Stop();
	virtual bool Render();
	virtual void RenderUI();
	virtual bool Update();
	virtual bool Free();
	virtual bool KeepResource(bool once,int& circle,String& nextTip);

	//三种类型结构
	virtual MiniPlayer*  CreatePlayer();
	virtual MiniPlayer*  CreateRobot ();
	virtual MiniPlayer*  CreateRole  ();

	void LoadFromFile(const char* filename);
	void SaveToFile(const char* filename);

	void OnLButtonUp();
	void OnRButtonUp();
	bool IsEnd();

private:

	Block* GetBlock(const vec2& screenPos);
	Block* GetNeiBlock(Block* block,int index);
protected:
	int m_allMineNum;
	int m_leftMineNum;
	int m_Status;
	int m_Level;

	int m_life;
	int m_score;

	vec2 m_blockNum;
	vec2 m_blockSize;

	RectF m_gameRect;
	//列主序
	Block m_blocks[MaxCol][MaxRow];
	LineInfo m_rowInfo[MaxRow];
	LineInfo m_colInfo[MaxCol];

	TexturePtr  m_texBlock;
	TexturePtr  m_texFace;
	TexturePtr  m_texBack;
	TexturePtr  m_texTxtBack;
	TexturePtr  m_texCloud;

	RectF       m_rectFace;
	RectF       m_rectLevel;

	//GuiTextureNumCtrl m_renderCtrlNum; //不加入ui,仅负责渲染

};

extern MiniGameMineClear2* G_MineClear2Game;

#endif 



#include "General/Pch.h"
#include "MineClear/MiniGameMineClear2.h"
#include "Render/RendDriver.h"
#include <stdlib.h>
#include "General/Window.h"
#include "Input/InputMgr.h"
#include "Render/Font.h"
#include "General/Timer.h"
#include "Render/MC_MovieClip.h"
#include "Render/Camera.h"
#include "Render/Shader.h"
#include "Gui/GuiMgr.h"
#include "General/File.h"
#include "General/Pce.h"

enum {DOWN, WIN, LOSE, CRY, SMILE};
enum {ACTIVE, ISWIN, ISLOSE, READY};

MiniGameMineClear2* G_MineClear2Game = NULL;

MiniGameMineClear2::MiniGameMineClear2()
{
    G_MineClear2Game = this;
    m_blockSize = vec2(24, 24);
	m_Level = 1;
}
MiniGameMineClear2::~MiniGameMineClear2()
{
	G_MineClear2Game = NULL;
}


bool MiniGameMineClear2::Start()
{
	if(!MiniGame::Start())
		return false;

    //雷的数目决定了关卡的难度
   // m_Level = 1;
    m_life = 3;
	m_score = 0;

    if(m_Level == 0)
    {
        m_blockNum.y = 10;
        m_blockNum.x = 10;
        m_allMineNum = 40;
    }
    if(m_Level == 1)
    {
        m_blockNum.y = 15;
        m_blockNum.x = 15;
		//m_allMineNum = 70;   //easy
        //m_allMineNum = 90; //normal
		m_allMineNum = 95;//130;   //hard
    }
    if(m_Level == 2)
    {
        m_blockNum.y = 20;
        m_blockNum.x = 20;
        m_allMineNum = 200;
    }


	m_blockSize = vec2(360, 360)/m_blockNum;

    G_TextureMgr->AddTexture(m_texFace,  "data/minigame/mineclear/face.png");
    G_TextureMgr->AddTexture(m_texBlock, "data/minigame/mineclear/block.png");
	G_TextureMgr->AddTexture(m_texBack,  "data/minigame/mineclear/back.png");
	G_TextureMgr->AddTexture(m_texTxtBack, "data/minigame/mineclear/backtxt.png");
	G_TextureMgr->AddTexture(m_texCloud,   "data/environment/clouds/cloud2.png");

	//
	if (m_movieScene == NULL)
	{
		LoadConfig loader(LoadConfig::GenDonotReShrinkBound, true, true);
		m_movieScene = new RendSys::MovieClip;
		m_movieScene->LoadFromFile("data/minigame/mineclear/board.movie", &loader);

		Frame frame;
		frame.SetPos(m_startPos);
		m_movieScene->SetProgramFrame(&frame);
		m_movieScene->Advance();
	}

	if (m_movieScene->IsLoadComplete() == false)
	{
		m_gameState = MS_End;
		return false;
	}

	float width__  = m_texBack->GetWidth(); 
	float height_  = m_texBack->GetHeight(); 
	SetBoardRect(RectF((G_Window->m_iWidth-width__)/2,(G_Window->m_iHeight-height_)/2,width__,height_), 
		         RectF(m_startPos.x-50,m_startPos.z-33,100,66),
				 m_startPos.y+10.1f);

	//m_renderCtrlNum.FormatProperty(
	//	"{                                    \
	//	defaultstyle = \"ButtonDefault.gui\"  \
	//	text = \"back\"                       \
	//	x = 100                               \
	//	y = 0                                 \
	//	alignTypeW = RIGHT                    \
	//	width = 100                           \
	//	height = 30                           \
	//	}"
	//	);

    m_Status = ACTIVE;

    m_leftMineNum = m_allMineNum;

    for(int c = 0; c < m_blockNum.x; c++)
    {
        for(int r = 0; r < m_blockNum.y; r++)
        {
            m_blocks[c][r].display = 0; //current display
            m_blocks[c][r].real = 0; //m_mines table   实际的
            m_blocks[c][r].grid = vec2I(c, r);
        }
    }

    vec2I block;
    for(int c = 0; c < m_allMineNum;)
    {
        block.x = Rand()  % (int) m_blockNum.x ;
        block.y = Rand() % (int) m_blockNum.y;
        if(m_blocks[block.x][block.y].real == 0)
        {
            m_blocks[block.x][block.y].real = MineNormal;
            c++;
        }
    }


    //
    for(int c = 0; c < m_blockNum.x; c++)
    {
        int groupNum = 0;
        int mineNum = 0;
        memset(m_colInfo[c].groupLen, 0, 50);
        for(int r = 0; r < m_blockNum.y; r++)
        {
            Block* block = &m_blocks[c][r];
            if(block->real != MineNormal)
            {
                mineNum++;
                if(r == m_blockNum.y - 1)
                {
                    m_colInfo[c].groupLen[groupNum++] = mineNum;
                }
            }
            else
            {
                if(mineNum > 0)
                {
                    m_colInfo[c].groupLen[groupNum++] = mineNum;
                    mineNum = 0;
                }
            }
        }
        m_colInfo[c].gruopNum = groupNum;
    }
    for(int r = 0; r < m_blockNum.y; r++)
    {
        int groupNum = 0;
        int mineNum = 0;
        memset(m_rowInfo[r].groupLen, 0, 50);
        for(int c = 0; c < m_blockNum.x; c++)
        {
            Block* block = &m_blocks[c][r];
            if(block->real != MineNormal)
            {
                mineNum++;
                if(c == m_blockNum.x - 1)
                {
                    m_rowInfo[r].groupLen[groupNum++] = mineNum;
                }
            }
            else
            {
                if(mineNum > 0)
                {
                    m_rowInfo[r].groupLen[groupNum++] = mineNum;
                    mineNum = 0;
                }
            }
        }
        m_rowInfo[r].gruopNum = groupNum;
    }

	//
	m_rectFace = RectF(G_Window->m_iWidth / 2 - 12, BoardRect2D.y - 40, 24, 24);

	//进入miniplaygui,(选人、选关卡都已在房间里进行完毕)。
	if(GetStyle()) G_GuiMgr->PushGui(GetStyle()->playGUI.c_str(),GL_DIALOG);

    //PlaySoundEx(SOUND_BEGIN);


	//设置摄像机
	CameraCtrlerTarget* ctrler = new CameraCtrlerTarget;
	ctrler->SetDistToTar(60);
	ctrler->SetTarPos(m_startPos);
	G_Camera->PushCtrler(ctrler);	
	G_Camera->SetEuler(0, -60, 0);
	//片头摄像机
	PushIntroCamera();

    return true;
}
MiniPlayer* MiniGameMineClear2::CreatePlayer()
{
	return NULL  ;
}

MiniPlayer* MiniGameMineClear2::CreateRobot()
{
	return NULL  ;
}

MiniPlayer* MiniGameMineClear2::CreateRole()
{
	return NULL;
}
bool MiniGameMineClear2::Stop()
{
	MiniGame::Stop();
    return true;
}

bool MiniGameMineClear2::Free()
{
	MiniGame::Free();
    return true;
}

bool MiniGameMineClear2::KeepResource(bool once, int& circle, String& nextTip)
{
    return true;
}

bool MiniGameMineClear2::Update()
{
    MiniGame::Update();
	{
		float width__  = m_texBack->GetWidth(); 
		float height_  = m_texBack->GetHeight(); 
		SetBoardRect(RectF((G_Window->m_iWidth-width__)/2,(G_Window->m_iHeight-height_)/2,width__,height_), 
			RectF(m_startPos.x-50,m_startPos.z-33,100,66),
			m_startPos.y+10.1f);

		m_gameRect.SetPos(BoardRect2D.GetPos() + vec2(26,23));
		m_gameRect.SetExtent(vec2(360,360));
	}

    //PlaySoundEx(SOUND_BEEP);
    if(G_Mouse->IsButtonUping(MOUSE_LEFT))
    {
        OnLButtonUp();
    }
    if(G_Mouse->IsButtonUping(MOUSE_RIGHT))
    {
		//随机收到很快的两次连续点击,貌似鼠标坏了??
        OnRButtonUp();
    }

	if (m_3dMode)
	{
		m_movieScene->Advance();
	}
	IsEnd();
    return true;
}

bool MiniGameMineClear2::Render()
{
	G_RendDriver->Color4f(1, 1, 1, 1);

	if (m_3dMode)
	{
		G_RendDriver->EndUI();
		if(m_movieScene==NULL
			||m_movieScene->IsLoadComplete()==false)
			return false;
		m_movieScene->RendClip();

		G_RendDriver->PushMatrix();
		G_RendDriver->MultMatrix(mat2Dto3D);
	}
	else
	{
		G_RendDriver->BeginUI();
		//画背景
		m_texBack->Bind();
		G_RendDriver->DrawTextureRect(RectF(BoardRect2D));

		//
		m_texCloud->Bind();
		G_RendDriver->DrawTextureRect(m_gameRect, RectF(0+m_gameTime*0.1f, 0, 1, 1));
	}

	if (G_ShaderMgr&& G_ShaderMgr->m_curEffect)
	{
		G_ShaderMgr->MapChangeParm();
	}

    //画时间和得分
    m_texLcdNumber->Bind();
	G_RendDriver->Color4f(1, 0, 0, 1);
    DrawLcd(3,m_gameTime, RectF(BoardRect2D.x+636, BoardRect2D.y+213, 39, 23));
    DrawLcd(3,m_life,     RectF(BoardRect2D.x+636, BoardRect2D.y+62, 39, 23));
	DrawLcd(3,m_score,    RectF(BoardRect2D.x+636, BoardRect2D.y+89, 39, 23));

	//画等级
	m_rectLevel = RectF(BoardRect2D.x+636, BoardRect2D.y+36, 39, 23);
	if(m_rectLevel.IsPointIn(this->GetMousePos()))
	{
		G_RendDriver->Color4f(1, 1, 0, 1);
	}
	else
	{
		G_RendDriver->Color4f(1, 0, 0, 1);
	}
	m_texLcdNumber->Bind();
	DrawLcd(3,m_Level, m_rectLevel);
	G_RendDriver->Color4f(1, 1, 1, 1);

    //画笑脸
    m_texFace->Bind();
	m_rectFace = RectF(BoardRect2D.x+609, BoardRect2D.y+347, 36, 36);
	if(m_rectFace.IsPointIn(this->GetMousePos()))
	{
		G_RendDriver->DrawTextureRect(m_rectFace, RectF(0, DOWN / 5.0f, 1, 1 / 5.0f));
	}
	else
	{
		if(m_Status==ACTIVE)
			G_RendDriver->DrawTextureRect(m_rectFace, RectF(0, SMILE / 5.0f, 1, 1 / 5.0f));
		else if(m_Status==LOSE)
			G_RendDriver->DrawTextureRect(m_rectFace, RectF(0, LOSE / 5.0f, 1, 1 / 5.0f));
		else if(m_Status==ISWIN)
			G_RendDriver->DrawTextureRect(m_rectFace, RectF(0, WIN / 5.0f, 1, 1 / 5.0f));
	}
    
	//画方块
    m_texBlock->Bind();
    for(int i = 0; i < m_blockNum.x; i++)
    {
        for(int j = 0; j < m_blockNum.y; j++)
        {
            int m = i * m_blockSize.x + m_gameRect.x;
            int n = j * m_blockSize.y + m_gameRect.y;
            G_RendDriver->DrawTextureRect(RectF(m, n, m_blockSize.x, m_blockSize.y), RectF(0, m_blocks[i][j].display / 16.0f, 1.0f, 1.0f / 16));
        }
    }

    //画选中
    Block* block = GetBlock(this->GetMousePos());
    if(block)
    {
        int m = block->grid.x * m_blockSize.x + m_gameRect.x;
        int n = block->grid.y * m_blockSize.y + m_gameRect.y;
        G_RendDriver->Color4f(0, 0, 1, 0.3f);
		if (G_ShaderMgr&& G_ShaderMgr->m_curEffect)
		{
			G_ShaderMgr->MapChangeParm();
		}
        G_RendDriver->DrawRect(RectF(m, n, m_blockSize.x, m_blockSize.y));

		G_RendDriver->Color4f(1, 1, 1, 1);
		if (G_ShaderMgr&& G_ShaderMgr->m_curEffect)
		{
			G_ShaderMgr->MapChangeParm();
		}
    }


    //画数字
    for(int c = 0; c < m_blockNum.x; c++)
    {
        char buf[512] = "";
        char buf2[32];
        for(int g = 0; g < m_colInfo[c].gruopNum; g++)
        {
            sprintf(buf2, "%d ", (int) m_colInfo[c].groupLen[g]);
            //strcat(buf,buf2);
            int x = c * m_blockSize.x + m_gameRect.x + 8;
            int y = m_gameRect.y + m_blockSize.y * m_blockNum.y + g * 18 + 15;

			if (g==0)
			{
				G_RendDriver->Color4f(1, 1, 1, 1);
				m_texTxtBack->Bind();
				G_RendDriver->DrawTextureRect(RectF(x-8, y-8, 25, 150), RectF(0, 0, 1, 1),ET_FITFRAME);
			}

            G_FontMgr->SetColor(Color(1, 0, 0, 1));
            G_FontMgr->TextAtPos(vec2(x, y), buf2);
        }
    }
    for(int r = 0; r < m_blockNum.y; r++)
    {
        char buf[512] = "";
        char buf2[32];
        for(int g = 0; g < m_rowInfo[r].gruopNum; g++)
        {
            sprintf(buf2, "%d ", (int) m_rowInfo[r].groupLen[g]);
            strcat(buf, buf2);
        }
        int x = m_gameRect.x + m_blockNum.x * m_blockSize.x + 15;
        int y = r * m_blockSize.y + m_gameRect.y;

		G_RendDriver->Color4f(1, 1, 1, 1);
		m_texTxtBack->Bind();
		G_RendDriver->DrawTextureRect(RectF(x-8, y-2, 170, 25), RectF(0, 0, 1, 1),ET_FITFRAME);

        G_FontMgr->SetColor(Color(0, 0, 1, 1));
        G_FontMgr->TextAtPos(vec2(x, y), buf);
    }


	//每隔5行或5列画一条标识线
	G_RendDriver->Color4f(1, 0, 0, 1);
	for(int c = 0; c < m_blockNum.x; c++)
	{
		if(c % 5 == 0)
		{
			int x = m_gameRect.x + c * m_blockSize.x;
			G_RendDriver->DrawLine(vec2(x, m_gameRect.y), vec2(x, m_gameRect.y + m_gameRect.height));
		}
	}
	for(int r = 0; r < m_blockNum.y; r++)
	{
		if(r % 5 == 0)
		{
			int y = m_gameRect.y + r * m_blockSize.y;
			G_RendDriver->DrawLine(vec2(m_gameRect.x, y), vec2(m_gameRect.x + m_gameRect.width, y));
		}
	}

    //每个block显示两个数字 行列

	//
	if (m_3dMode)
	{
		G_RendDriver->PopMatrix();
	}
    return true;
}

void MiniGameMineClear2::RenderUI()
{

}

void MiniGameMineClear2::OnLButtonUp()
{
	if(m_rectFace.IsPointIn(this->GetMousePos()))
	{
		//重新开始
		Start();
		return;
	}

	if(m_rectLevel.IsPointIn(this->GetMousePos()))
	{
		//重新开始
		m_Level++;
		m_Level%=3;
		//Start();
		return;
	}

    if(m_Status != ACTIVE && m_Status != READY)
        return;

    vec2 point = this->GetMousePos();
    Block* block = GetBlock(point);
    if(block)
    {
        if(m_Status == READY)
            Start();

        if(block->real == MineNormal)
        {
			if (block->display==Intact)
			{
				block->display = MineClick;
				//last mineclick = minenormal
				OnLose();
			}
        }
        else if(block->display != OpenClear)
        {
			m_score++;
            block->display = OpenClear;
			{
				//自动bingo 标记完成行的雷 (可以确定剩下的一定是雷)
				bool lineClear = true;
				for(int c = 0; c < m_blockNum.x; c++)
				{
					Block* blockit = &m_blocks[c][block->grid.y];
					if(blockit->real != MineNormal 
						&& blockit->display != OpenClear)
					{
						lineClear = false;
					}
				}
				if(lineClear == true)
				{
					for(int c = 0; c < m_blockNum.x; c++)
					{
						Block* blockit = &m_blocks[c][block->grid.y];
						if(blockit->real == MineNormal
							&& blockit->display == Intact||blockit->display == Flag_Question)
						{
							blockit->display = Flag_Mine;
						}
					}
				}

				lineClear = true;
				for(int r = 0; r < m_blockNum.y; r++)
				{
					Block* blockit = &m_blocks[block->grid.x][r];
					if(blockit->real != MineNormal 
						&& blockit->display != OpenClear)
					{
						lineClear = false;
					}
				}
				if(lineClear == true)
				{
					for(int r = 0; r < m_blockNum.y; r++)
					{
						Block* blockit = &m_blocks[block->grid.x][r];
						if(blockit->real == MineNormal
							&& (blockit->display == Intact||blockit->display == Flag_Question))
						{
							blockit->display = Flag_Mine;
						}
					}
				}
			}

			//有作弊嫌疑  即使全点开也不能确定两端一定是雷
			//{
			//	//自动在已完全翻开的group两端 标雷
			//	for(int c = 0; c < m_blockNum.x; c++)
			//	{
			//		Block* blockit = &m_blocks[c][block->grid.y];
			//		if(blockit->real != MineNormal 
			//			&& blockit->display == OpenClear )
			//		{
			//			//是否上标雷
			//			if (blockit->grid.y>0 
			//				&& m_blocks[c][blockit->grid.y-1].display==Intact
			//				&& m_blocks[c][blockit->grid.y-1].real==MineNormal)
			//			{
			//				bool groupClear = true;
			//				for (int r=blockit->grid.y+1;r<m_blockNum.y;r++)
			//				{
			//					if (m_blocks[c][r].real==MineNormal)
			//					{
			//						break;
			//					}
			//					else if (m_blocks[c][r].display!=OpenClear)
			//					{
			//						groupClear = false;
			//						break;
			//					}
			//				}
			//				if (groupClear)
			//				{
			//					m_blocks[c][blockit->grid.y-1].display= Flag_Mine;
			//				}
			//			}
			//			//是否下标雷
			//			if (blockit->grid.y<m_blockNum.y-1 
			//				&& m_blocks[c][blockit->grid.y+1].display==Intact
			//				&& m_blocks[c][blockit->grid.y+1].real==MineNormal)
			//			{
			//				bool groupClear = true;
			//				for (int r=blockit->grid.y-1;r>=0;r--)
			//				{
			//					if (m_blocks[c][r].real==MineNormal)
			//					{
			//						break;
			//					}
			//					else if (m_blocks[c][r].display!=OpenClear)
			//					{
			//						groupClear = false;
			//						break;
			//					}
			//				}
			//				if (groupClear)
			//				{
			//					m_blocks[c][blockit->grid.y+1].display= Flag_Mine;
			//				}
			//			}
			//		}
			//	}
			//
			//	for(int r = 0; r < m_blockNum.y; r++)
			//	{
			//		Block* blockit = &m_blocks[block->grid.x][r];
			//		if(blockit->real != MineNormal 
			//			&& blockit->display == OpenClear )
			//		{
			//			//是否左标雷
			//			if (blockit->grid.x>0 
			//				&& m_blocks[block->grid.x-1][r].display==Intact
			//				&& m_blocks[block->grid.x-1][r].real==MineNormal)
			//			{
			//				bool groupClear = true;
			//				for (int c=blockit->grid.x+1;c<m_blockNum.x;c++)
			//				{
			//					if (m_blocks[c][r].real==MineNormal)
			//					{
			//						break;
			//					}
			//					else if (m_blocks[c][r].display!=OpenClear)
			//					{
			//						groupClear = false;
			//						break;
			//					}
			//				}
			//				if (groupClear)
			//				{
			//					m_blocks[blockit->grid.x-1][r].display= Flag_Mine;
			//				}
			//			}
			//			//是否右标雷
			//			if (blockit->grid.x<m_blockNum.x-1 
			//				&& m_blocks[blockit->grid.x+1][r].display==Intact
			//				&& m_blocks[blockit->grid.x+1][r].real==MineNormal)
			//			{
			//				bool groupClear = true;
			//				for (int c=blockit->grid.x-1;c>=0;c--)
			//				{
			//					if (m_blocks[c][r].real==MineNormal)
			//					{
			//						break;
			//					}
			//					else if (m_blocks[c][r].display!=OpenClear)
			//					{
			//						groupClear = false;
			//						break;
			//					}
			//				}
			//				if (groupClear)
			//				{
			//					m_blocks[blockit->grid.x+1][r].display= Flag_Mine;
			//				}
			//			}
			//		}
			//	}
			//}
			OnClear();
        }
    }

}

void MiniGameMineClear2::OnRButtonUp()
{
    if(m_Status != ACTIVE && m_Status != READY) return;
    if(m_Status == READY) Start();

    vec2 point = this->GetMousePos();
    Block* block = GetBlock(point);
    if(block)
    {
        if(m_Status == READY) Start();

        switch(block->display)
        {
        case Intact:
            block->display = Flag_Mine;
            m_leftMineNum--;
            break;
        case Flag_Mine:
            block->display = Flag_Question;
            m_leftMineNum++;
            break;
        case Flag_Question:
            block->display = Intact;
            break;
        }
    }
}

void MiniGameMineClear2::OnClear()
{
	PlaySound__("data/sound/ui_click.wav");  
    IsEnd();
}

bool MiniGameMineClear2::IsEnd()
{
	所有雷被标出时过关 可以全标作弊
	//int mineNum = 0;
	//for(int i=0; i<m_blockNum.x; i++)
	//{
	//	for(int j=0; j<m_blockNum.y; j++)
	//	{
	//		if( m_blocks[i][j].display==Flag_Mine && m_blocks[i][j].real==MineNormal)
	//			mineNum++;
	//	}
	//}


	//所有非雷被翻开时过关
	int clearNum = 0;
	for(int i = 0; i < m_blockNum.x; i++)
	{
		for(int j = 0; j < m_blockNum.y; j++)
		{
			if(m_blocks[i][j].display == OpenClear && m_blocks[i][j].real != MineNormal)
				clearNum++;
		}
	}

	if(  //mineNum == m_allMineNum||
		clearNum == (m_blockNum.x * m_blockNum.y - m_allMineNum))
	{
		m_Status = ISWIN;

		m_Level++;
		m_Level%=3;
		return true;
	}
	return false;
}

void MiniGameMineClear2::OnLose()
{
	PlaySound__("data/sound/event_exploid02.wav");

	m_life--;
	if (m_life<=0)
	{
		for(int i = 0; i < m_blockNum.x; i++)
		{
			for(int j = 0; j < m_blockNum.y; j++)
			{
				if(m_blocks[i][j].real == MineNormal)
				{
					//未翻开的翻开
					if(m_blocks[i][j].display == Intact)
						m_blocks[i][j].display = MineNormal;
					//已排除的
					else if(m_blocks[i][j].display == Flag_Mine)
						m_blocks[i][j].display = Flag_Mine;
					//当前翻错的
					else
						m_blocks[i][j].display = MineClick;

				}
				else
				{
					//标记错的打叉
					if(m_blocks[i][j].display == Flag_Mine)
						m_blocks[i][j].display = MineCross;
				}
			}
		}

		m_Status = ISLOSE;
	}

//	PlaySoundEx(SOUND_LOSE);
}



MiniGameMineClear2::Block*  MiniGameMineClear2::GetBlock(const vec2& screenPos)
{
    int col = (screenPos.x - m_gameRect.x) / m_blockSize.x;
    int ln = (screenPos.y - m_gameRect.y) / m_blockSize.y;
    if(col < 0 || col >= m_blockNum.x
            || ln < 0 || ln >= m_blockNum.y)
    {
        return NULL;
    }
    return &m_blocks[col][ln];
}

MiniGameMineClear2::Block* MiniGameMineClear2::GetNeiBlock(Block* block, int index)
{
    int xmove[] = {-1, -1, 0, 1, -1, 0, 1, 1, 0};
    int ymove[] = {-1, 0, -1, -1, 1, 1, 0, 1, 0};
    int col = block->grid.x + xmove[index];
    int ln = block->grid.y + ymove[index];
    if(col < 0 || col >= m_blockNum.x
            || ln < 0 || ln >= m_blockNum.y)
    {
        return NULL;
    }
    return &m_blocks[col][ln];
}


void MiniGameMineClear2::LoadFromFile(const char* filename)
{
	//File file;
	//if (file.Fopen(filename,"rt"))
	//{
	//	if(strcmp("mathobj1.0",file.ReadString())!=0)
	//		return;
	//	m_Level = file.ReadInt();
	//	m_blockNum.x = file.ReadInt();
	//	m_blockNum.y = file.ReadInt();
	//	m_allMineClearNum = file.ReadInt();
	//	m_leftMineClearNum = file.ReadInt();
	//	//m_Timer=app->GetProfileInt("Save","Data1",1);

	//	int i,j;
	//	for(i=0; i<m_blockNum.x; i++)
	//	{
	//		for(j=0; j<m_blockNum.y; j++)
	//		{
	//			m_blocks[i][j].display = file.ReadInt();
	//			m_blocks[i][j].real = file.ReadInt();
	//			m_blocks[i][j].grid.x = file.ReadInt();
	//			m_blocks[i][j].grid.y = file.ReadInt();
	//		}
	//	}
	//}
}

void MiniGameMineClear2::SaveToFile(const char* filename)
{
	File file;
	if (file.Fopen(filename,"wt"))
	{
		//file.WriteString("mathobj1.0");                   file.Fprintf("\n");
		//file.WriteInt(mathType);						  file.Fprintf("\n");
		//file.WriteFloatArray(&color.r,4);				  file.Fprintf("\n");
		//file.WriteInt(lineWidth);						  file.Fprintf("\n");
		//file.WriteInt(fillMode);						  file.Fprintf("\n");
		//file.Fprintf("\n");
		//file.WriteFloatArray(&rangeX.x,2);				  file.Fprintf("\n");
		//file.WriteFloatArray(&rangeS.x,2);				  file.Fprintf("\n");
		//file.WriteFloatArray(&rangeR.x,2);				  file.Fprintf("\n");
		//file.WriteFloatArray(&rangeU.x,2);				  file.Fprintf("\n");
		//file.WriteFloatArray(&rangeV.x,2);				  file.Fprintf("\n");
		//file.WriteFloatArray(&rangeTime.x,2);			  file.Fprintf("\n");
		//file.Fprintf("\n");
		//file.WriteInt(stepNumX);						  file.Fprintf("\n");
		//file.WriteInt(stepNumS);						  file.Fprintf("\n");
		//file.WriteInt(stepNumR);						  file.Fprintf("\n");
		//file.WriteInt(stepNumU);						  file.Fprintf("\n");
		//file.WriteInt(stepNumV);						  file.Fprintf("\n");
		//file.Fprintf("\n");
		//file.WriteInt(enableAnim);						  file.Fprintf("\n");
		//file.WriteFloat(playTime);						  file.Fprintf("\n");
		//file.Fprintf("\n");
		//for (int i=0;i<FT_Max;i++)						  
		//{
		//	file.WriteString(fnExpress[i],512);      file.Fprintf("\n");
		//}
	}
}

 

完