两款扫雷游戏3D版源码
生活随笔
收集整理的這篇文章主要介紹了
两款扫雷游戏3D版源码
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
14號,不該胡說,今天鍋真壞了,研究下怎么用茶壺煮水餃.....
這是兩種類型的掃雷游戲,說是3D版其實還是2D版貼在了桌面上而已。有部分提示功能,無聯機功能。
第一種類型是經典玩法,每個格子中的數字代表周圍九宮格中雷的數目。
第二種掃雷游戲,在每一行的右邊有一排數字代表該行中空格的布局,每一列下面也有一排數字代表該列中空格的布局。每點到一個雷會損失一條生命。?
第一種源碼:
#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-8Num7,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 displaym_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;//當前翻錯的elsem_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; //normalm_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 displaym_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 = minenormalOnLose();}}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;//當前翻錯的elsem_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");//}} }?
完?
總結
以上是生活随笔為你收集整理的两款扫雷游戏3D版源码的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 小树T3打印机
- 下一篇: Pushmail:这个可以有