void Game::DoMove(wxDC& dc, Pile* src, Pile* dest) { if (m_moveIndex < MaxMoves) { if (src == dest) { wxMessageBox(wxT("Game::DoMove() src == dest"), wxT("Debug message"), wxOK | wxICON_EXCLAMATION); } m_moves[m_moveIndex].src = src; m_moves[m_moveIndex].dest = dest; m_moveIndex++; // when we do a move any moves in redo buffer are discarded m_redoIndex = m_moveIndex; } else { wxMessageBox(wxT("Game::DoMove() Undo buffer full"), wxT("Debug message"), wxOK | wxICON_EXCLAMATION); } if (!m_inPlay) { m_inPlay = true; m_numGames++; } DisplayScore(dc); if (HaveYouWon()) { wxWindow *frame = wxTheApp->GetTopWindow(); wxWindow *canvas = (wxWindow *) NULL; if (frame) { wxWindowList::compatibility_iterator node = frame->GetChildren().GetFirst(); if (node) canvas = (wxWindow*)node->GetData(); } // This game is over m_inPlay = false; // Redraw the score box to update games won DisplayScore(dc); if (wxMessageBox(wxT("Do you wish to play again?"), wxT("Well Done, You have won!"), wxYES_NO | wxICON_QUESTION) == wxYES) { Deal(); canvas->Refresh(); } else { // user cancelled the dialog - exit the app ((wxFrame*)canvas->GetParent())->Close(true); } } }
// Redraw the m_pack, discard pile, the bases and the foundations void Game::Redraw(wxDC& dc) { int i; m_pack->Redraw(dc); m_discard->Redraw(dc); for (i = 0; i < 8; i++) { m_foundations[i]->Redraw(dc); } for (i = 0; i < 10; i++) { m_bases[i]->Redraw(dc); } DisplayScore(dc); if (m_bmap == 0) { m_bmap = new wxBitmap(CardWidth, CardHeight); m_bmapCard = new wxBitmap(CardWidth, CardHeight); // Initialise the card bitmap to the background colour wxMemoryDC memoryDC; memoryDC.SelectObject(*m_bmapCard); memoryDC.SetPen( *wxTRANSPARENT_PEN ); memoryDC.SetBrush(FortyApp::BackgroundBrush()); memoryDC.DrawRectangle(0, 0, CardWidth, CardHeight); memoryDC.SelectObject(*m_bmap); memoryDC.DrawRectangle(0, 0, CardWidth, CardHeight); memoryDC.SelectObject(wxNullBitmap); } }
void DrawObjects(void) { // Draw the Star Field SpaceMap1->DrawTrans(Screen->GetBack()); // Draw the Player Player->Draw(Screen->GetBack(), 0, 0, CDXBLT_TRANS); // Draw all the sprites in the list Sprites.Draw(Screen->GetBack(), 0, 0, CDXBLT_TRANS); // If debugging Display the FPS if (FPSFlag == 1) DisplayFPS(); // Display text on the back buffer DisplayScore(); DisplayHighScore(); DisplayLives(); DisplaySpaceyMsg(); // Flip the Flippin screen buffers Screen->Flip(); // calculate the FPS after all drawing and page flipping have been performed. GetFPS(); }
// Undo the last move void Game::Undo(wxDC& dc) { if (m_moveIndex > 0) { m_moveIndex--; Card* card = m_moves[m_moveIndex].dest->RemoveTopCard(dc); m_moves[m_moveIndex].src->AddCard(dc, card); DisplayScore(dc); } }
// Redraw the m_pack, discard pile, the bases and the foundations void Game::Redraw(wxDC& dc) { int i; m_pack->Redraw(dc); m_discard->Redraw(dc); #if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */ # pragma ivdep # pragma swp # pragma unroll # pragma prefetch # if 0 # pragma simd noassert # endif #endif /* VDM auto patch */ for (i = 0; i < 8; i++) { m_foundations[i]->Redraw(dc); } #if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */ # pragma ivdep # pragma swp # pragma unroll # pragma prefetch # if 0 # pragma simd noassert # endif #endif /* VDM auto patch */ for (i = 0; i < 10; i++) { m_bases[i]->Redraw(dc); } DisplayScore(dc); if (m_bmap == 0) { m_bmap = new wxBitmap(CardWidth, CardHeight); m_bmapCard = new wxBitmap(CardWidth, CardHeight); // Initialise the card bitmap to the background colour wxMemoryDC memoryDC; memoryDC.SelectObject(*m_bmapCard); memoryDC.SetPen( *wxTRANSPARENT_PEN ); memoryDC.SetBrush(FortyApp::BackgroundBrush()); memoryDC.DrawRectangle(0, 0, CardWidth, CardHeight); memoryDC.SelectObject(*m_bmap); memoryDC.DrawRectangle(0, 0, CardWidth, CardHeight); memoryDC.SelectObject(wxNullBitmap); } }
// Redo the last move void Game::Redo(wxDC& dc) { if (m_moveIndex < m_redoIndex) { Card* card = m_moves[m_moveIndex].src->RemoveTopCard(dc); if (m_moves[m_moveIndex].src == m_pack) { m_pack->Redraw(dc); card->TurnCard(faceup); } m_moves[m_moveIndex].dest->AddCard(dc, card); DisplayScore(dc); m_moveIndex++; } }
/* Fonction de gestion de l'affichage du plateau de jeu * @param SDL_Surface* window * Surface de la fenetre * @param S_GameConfig gameConfig * Structure de configuration du jeu * @return int * 1 si on doit quitter le programme, 0 sinon */ int DisplayBoard(SDL_Surface* window, S_GameConfig gameConfig) { SDL_Surface *board_bg = IMG_Load(DESIGN_PATH "board.png"); S_GameState gameState; InitGameState(&gameState, gameConfig); // Initialisation du score gameState.scoreP1 = 0; gameState.scoreP2 = 0; SDL_Rect position; position.x = 0; position.y = 0; SDL_BlitSurface(board_bg, NULL, window, &position); DisplayCheckers(window, gameState); DisplayBoardOverlays(window, gameState); DisplayScore(window, gameState); // On initialise les IA if (gameConfig.mode != HUMAN_HUMAN) { gameConfig.aiFunctions[1].AI_StartMatch((unsigned int)(gameConfig.points)); gameConfig.aiFunctions[1].AI_StartGame(); } if (gameConfig.mode == AI_AI) { gameConfig.aiFunctions[0].AI_StartMatch((unsigned int)(gameConfig.points)); gameConfig.aiFunctions[0].AI_StartGame(); } // finish = On revient au menu // quit = On quitte le programme int quit = 0, finish = 0; SDL_Event event; int oldTime = SDL_GetTicks(); int time; while(!finish) { // Affichage if (event.type == SDL_MOUSEBUTTONUP || event.type == SDL_MOUSEBUTTONDOWN || gameState.refresh) { SDL_BlitSurface(board_bg, NULL, window, &position); DisplayCheckers(window, gameState); DisplayBoardOverlays(window, gameState); DisplayScore(window, gameState); gameState.refresh = 0; } SDL_Flip(window); // Gestion des evenements E_BoardSelected button = EventsBoard(&event, &gameState); if (button == QUIT_BOARD) { finish = 1; quit = 1; // On desalloue les IA if (gameConfig.mode != HUMAN_HUMAN) gameConfig.aiFunctions[1].AI_EndGame(); if (gameConfig.mode == AI_AI) gameConfig.aiFunctions[0].AI_EndGame(); } else if (button == MENU_BOARD) finish = 1; // Gestion de la vitesse de jeu entre IA if (gameConfig.mode == AI_AI && gameState.currentStage == SELECT_ZONE_SRC && gameConfig.option) { time = SDL_GetTicks(); if ((time - oldTime) > 1000) { AI_EventsBoard(&gameState); oldTime = time; } } else AI_EventsBoard(&gameState); SDL_Delay(5); } // On desalloue les IA if (gameConfig.mode != HUMAN_HUMAN) gameConfig.aiFunctions[1].AI_EndMatch(); if (gameConfig.mode == AI_AI) gameConfig.aiFunctions[0].AI_EndMatch(); SDL_FreeSurface(board_bg); return quit; }