void InGameState::ReceiveMessage(const GameStateMessage& aMessage) { switch (aMessage.GetGameState()) { case eGameState::RELOAD_LEVEL: myLoadingScreen->Reset(); myLevel = myLevelFactory->LoadCurrentLevel(); break; case eGameState::COMPLETE_LEVEL: if (myLevelFactory->IsLastLevel() == false) { CompleteLevel(); } else { CompleteGame(); } break; case eGameState::LOAD_NEXT_LEVEL: myLoadingScreen->Reset(); myLevel = myLevelFactory->LoadNextLevel(); break; } }
void GameController::CoordinateReleased() { for(int i=0;i<getLevel();++i) for(int j=0;j<getLevel();++j) setBlockColor(QPoint(i,j),GameData::BgColor); for(int i=0;i<getColorNumber()*2;++i) setBlockColor(gameSetting->Points[i],GameData::ColorSet[i/2]); for(int i=0;i<pipeManager->size();++i) { Pipe* pipe = pipeManager->at(i); if(pipeManager->currentPipe!=pipe) { while(!pipe->empty()) { QPoint _coordinate(pipe->back()); STATE _state = getBlockState(_coordinate); if((_state&WAY)==0||(_state&BREAK)!=0||(_state&CURRENT)!=0) pipe->pop_back(); else break; } } for(int j=0;j<pipe->size();++j) setBlockColor(pipe->at(j),pipe->Color); } for(int i=0;i<this->getLevel();++i) for(int j=0;j<this->getLevel();++j) setBlockState(QPoint(i,j),~(CURRENT|BREAK)); ++gameSetting->moves; emit UpdatePipeDisplay(); emit UpdateBlockDisplay(); if(CheckWin()) emit CompleteGame(); }
//------------------------------------------------------------------------------------------------- int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int cmdShow) { srand((unsigned)time(0)); HINSTANCE hAppInst = hInst; //init window HWND hWnd = CWindow::Inst().Init(hAppInst, CFG_AppName, CFG_AppName, CFG_WndWidth, CFG_WndHeight); if (!hWnd) return -1; //init mutexs g_hMutexExit = CreateMutex(NULL, FALSE, NULL); if (!g_hMutexExit) return -2; g_hMutexGame = CreateMutex(NULL, FALSE, NULL); if (!g_hMutexGame) return -3; //create thread for update the game and draw frame g_hThreadGame = CreateThread(NULL, 0, &ThreadFunc, hWnd, 0, NULL); if (!g_hThreadGame) return -4; //cycle for process received messages int ret = CWindow::Inst().WaitAndProcMessages(); //wait for game thread completion CompleteGame(); while (1) { DWORD exitCode = 0; BOOL res = GetExitCodeThread(g_hThreadGame, &exitCode); if (!res || exitCode!=STILL_ACTIVE) break; Sleep(10); } //release resources CloseHandle(g_hThreadGame); CloseHandle(g_hMutexGame); CloseHandle(g_hMutexExit); CWindow::Inst().Destroy(); return ret; }