X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/af88eefff25f06bec4ccf69618d033b377bfd06f..c829d62b6945c74edaf25210720129b8b749639d:/demos/forty/game.cpp diff --git a/demos/forty/game.cpp b/demos/forty/game.cpp index 9e4911741f..d1d38e9d48 100644 --- a/demos/forty/game.cpp +++ b/demos/forty/game.cpp @@ -35,7 +35,7 @@ #include "game.h" Game::Game(int wins, int games, int score) : - m_inPlay(FALSE), + m_inPlay(false), m_moveIndex(0), m_redoIndex(0), m_bmap(0), @@ -72,6 +72,30 @@ Game::Game(int wins, int games, int score) : } +void Game::Layout() +{ + int i; + + m_pack->SetPos(2, 2 + 4 * (CardHeight + 2)); + + m_discard->SetPos(2, 2 + 5 * (CardHeight + 2)); + + for (i = 0; i < 8; i++) + { + m_foundations[i]->SetPos(2 + (i / 4) * (CardWidth + 2), + 2 + (i % 4) * (CardHeight + 2)); + } + + for (i = 0; i < 10; i++) + { + m_bases[i]->SetPos(8 + (i + 2) * (CardWidth + 2), 2); + } + delete m_bmap; + delete m_bmapCard; + m_bmap = 0; + m_bmapCard = 0; +} + // Make sure we delete all objects created by the game object Game::~Game() { @@ -139,7 +163,7 @@ void Game::DoMove(wxDC& dc, Pile* src, Pile* dest) { if (src == dest) { - wxMessageBox("Game::DoMove() src == dest", "Debug message", + wxMessageBox(_T("Game::DoMove() src == dest"), _T("Debug message"), wxOK | wxICON_EXCLAMATION); } m_moves[m_moveIndex].src = src; @@ -151,13 +175,13 @@ void Game::DoMove(wxDC& dc, Pile* src, Pile* dest) } else { - wxMessageBox("Game::DoMove() Undo buffer full", "Debug message", + wxMessageBox(_T("Game::DoMove() Undo buffer full"), _T("Debug message"), wxOK | wxICON_EXCLAMATION); } if (!m_inPlay) { - m_inPlay = TRUE; + m_inPlay = true; m_numGames++; } DisplayScore(dc); @@ -169,18 +193,18 @@ void Game::DoMove(wxDC& dc, Pile* src, Pile* dest) if (frame) { - wxNode *node = frame->GetChildren().First(); - if (node) canvas = (wxWindow*)node->Data(); + wxNode *node = (wxNode *)frame->GetChildren().GetFirst(); + if (node) canvas = (wxWindow*)node->GetData(); } // This game is over - m_inPlay = FALSE; + m_inPlay = false; // Redraw the score box to update games won DisplayScore(dc); - if (wxMessageBox("Do you wish to play again?", - "Well Done, You have won!", wxYES_NO | wxICON_QUESTION) == wxYES) + if (wxMessageBox(_T("Do you wish to play again?"), + _T("Well Done, You have won!"), wxYES_NO | wxICON_QUESTION) == wxYES) { Deal(); canvas->Refresh(); @@ -188,7 +212,7 @@ void Game::DoMove(wxDC& dc, Pile* src, Pile* dest) else { // user cancelled the dialog - exit the app - ((wxFrame*)canvas->GetParent())->Close(TRUE); + ((wxFrame*)canvas->GetParent())->Close(true); } } } @@ -217,25 +241,25 @@ void Game::DisplayScore(wxDC& dc) int w, h; { long width, height; - dc.GetTextExtent("Average score:m_x", &width, &height); + dc.GetTextExtent(_T("Average score:m_x"), &width, &height); w = width; h = height; } dc.DrawRectangle(x + w, y, 20, 4 * h); - char str[80]; - sprintf(str, "%d", m_currentScore); - dc.DrawText("Score:", x, y); + wxString str; + str.Printf(_T("%d"), m_currentScore); + dc.DrawText(_T("Score:"), x, y); dc.DrawText(str, x + w, y); y += h; - sprintf(str, "%d", m_numGames); - dc.DrawText("Games played:", x, y); + str.Printf(_T("%d"), m_numGames); + dc.DrawText(_T("Games played:"), x, y); dc.DrawText(str, x + w, y); y += h; - sprintf(str, "%d", m_numWins); - dc.DrawText("Games won:", x, y); + str.Printf(_T("%d"), m_numWins); + dc.DrawText(_T("Games won:"), x, y); dc.DrawText(str, x + w, y); y += h; @@ -244,8 +268,8 @@ void Game::DisplayScore(wxDC& dc) { average = (2 * (m_currentScore + m_totalScore) + m_numGames ) / (2 * m_numGames); } - sprintf(str, "%d", average); - dc.DrawText("Average score:", x, y); + str.Printf(_T("%d"), average); + dc.DrawText(_T("Average score:"), x, y); dc.DrawText(str, x + w, y); } @@ -291,7 +315,7 @@ void Game::Deal() m_totalScore += m_currentScore; } m_currentScore = 0; - m_inPlay = FALSE; + m_inPlay = false; } @@ -500,21 +524,21 @@ void Game::LButtonDblClk(wxDC& dc, int x, int y) // i.e. m_pack, discard and bases are empty bool Game::HaveYouWon() { - if (m_pack->GetTopCard()) return FALSE; - if (m_discard->GetTopCard()) return FALSE; + if (m_pack->GetTopCard()) return false; + if (m_discard->GetTopCard()) return false; for(int i = 0; i < 10; i++) { - if (m_bases[i]->GetTopCard()) return FALSE; + if (m_bases[i]->GetTopCard()) return false; } m_numWins++; m_totalScore += m_currentScore; m_currentScore = 0; - return TRUE; + return true; } // See whether the card under the cursor can be moved somewhere else -// Returns TRUE if it can be moved, FALSE otherwise +// Returns 'true' if it can be moved, 'false' otherwise bool Game::CanYouGo(int x, int y) { Pile* pile = WhichPile(x, y); @@ -529,7 +553,7 @@ bool Game::CanYouGo(int x, int y) { if (m_foundations[i]->AcceptCard(card) && m_foundations[i] != pile) { - return TRUE; + return true; } } for(i = 0; i < 10; i++) @@ -538,12 +562,12 @@ bool Game::CanYouGo(int x, int y) m_bases[i]->AcceptCard(card) && m_bases[i] != pile) { - return TRUE; + return true; } } } } - return FALSE; + return false; } @@ -618,12 +642,12 @@ void Game::LButtonUp(wxDC& dc, int x, int y) bool Game::DropCard(int x, int y, Pile* pile, Card* card) { - bool retval = FALSE; + bool retval = false; if (pile->Overlap(x, y)) { if (pile->AcceptCard(card)) { - retval = TRUE; + retval = true; } } return retval; @@ -774,8 +798,8 @@ void Pack::Redraw(wxDC& dc) { Pile::Redraw(dc); - char str[10]; - sprintf(str, "%d ", m_topCard + 1); + wxString str; + str.Printf(_T("%d "), m_topCard + 1); dc.SetBackgroundMode( wxSOLID ); dc.SetTextBackground(FortyApp::BackgroundColour()); @@ -792,7 +816,7 @@ void Pack::AddCard(Card* card) } else { - wxMessageBox("Pack::AddCard() Undo error", "Forty Thieves: Warning", + wxMessageBox(_T("Pack::AddCard() Undo error"), _T("Forty Thieves: Warning"), wxOK | wxICON_EXCLAMATION); } card->TurnCard(facedown); @@ -819,20 +843,20 @@ Base::Base(int x, int y) : Pile(x, y, 0, 12) bool Base::AcceptCard(Card* card) { - bool retval = FALSE; + bool retval = false; if (m_topCard >= 0) { if (m_cards[m_topCard]->GetSuit() == card->GetSuit() && m_cards[m_topCard]->GetPipValue() - 1 == card->GetPipValue()) { - retval = TRUE; + retval = true; } } else { // pile is empty - ACCEPT - retval = TRUE; + retval = true; } return retval; } @@ -853,20 +877,20 @@ Foundation::Foundation(int x, int y) : Pile(x, y, 0, 0) bool Foundation::AcceptCard(Card* card) { - bool retval = FALSE; + bool retval = false; if (m_topCard >= 0) { if (m_cards[m_topCard]->GetSuit() == card->GetSuit() && m_cards[m_topCard]->GetPipValue() + 1 == card->GetPipValue()) { - retval = TRUE; + retval = true; } } else if (card->GetPipValue() == 1) { // It's an ace and the pile is empty - ACCEPT - retval = TRUE; + retval = true; } return retval; }