EVT_MOUSE_EVENTS(FortyCanvas::OnMouseEvent)
END_EVENT_TABLE()
-FortyCanvas::FortyCanvas(wxWindow* parent, int x, int y, int w, int h) :
- wxScrolledWindow(parent, -1, wxPoint(x, y), wxSize(w, h)),
- m_helpingHand(TRUE),
- m_rightBtnUndo(TRUE),
+FortyCanvas::FortyCanvas(wxWindow* parent, const wxPoint& pos, const wxSize& size) :
+ wxScrolledWindow(parent, wxID_ANY, pos, size),
+ m_helpingHand(true),
+ m_rightBtnUndo(true),
m_playerDialog(0),
- m_leftBtnDown(FALSE)
+ m_leftBtnDown(false)
{
#ifdef __WXGTK__
m_font = wxTheFontList->FindOrCreateFont(12, wxROMAN, wxNORMAL, wxNORMAL);
else
{
// user cancelled the dialog - exit the app
- ((wxFrame*)GetParent())->Close(TRUE);
+ ((wxFrame*)GetParent())->Close(true);
}
}
#endif
else
{
// user cancelled the dialog - exit the app
- ((wxFrame*)GetParent())->Close(TRUE);
+ ((wxFrame*)GetParent())->Close(true);
}
}
}
wxMessageBox(_T("Are you sure you want to\nabandon the current game?"),
_T("Warning"), wxYES_NO | wxICON_QUESTION) == wxNO)
{
- return FALSE;
+ return false;
}
- return TRUE;
+ return true;
}
void FortyCanvas::OnMouseEvent(wxMouseEvent& event)
{
if (m_leftBtnDown)
{
- m_leftBtnDown = FALSE;
+ m_leftBtnDown = false;
ReleaseMouse();
m_game->LButtonUp(dc, mouseX, mouseY);
}
{
if (!m_leftBtnDown)
{
- m_leftBtnDown = TRUE;
+ m_leftBtnDown = true;
CaptureMouse();
m_game->LButtonDown(dc, mouseX, mouseY);
}
{
if (m_leftBtnDown)
{
- m_leftBtnDown = FALSE;
+ m_leftBtnDown = false;
ReleaseMouse();
m_game->LButtonUp(dc, mouseX, mouseY);
}
}
else if (event.RightDown() && !event.LeftIsDown())
{
- // only allow right button undo if m_rightBtnUndo is TRUE
+ // only allow right button undo if m_rightBtnUndo is true
if (m_rightBtnUndo)
{
if (event.ControlDown() || event.ShiftDown())
class FortyCanvas: public wxScrolledWindow
{
public:
- FortyCanvas(wxWindow* parent, int x, int y, int w, int h);
+ FortyCanvas(wxWindow* parent, const wxPoint& pos, const wxSize& size);
virtual ~FortyCanvas();
virtual void OnDraw(wxDC& dc);
break;
}
m_pipValue = 1 + (value - 1) % 13;
- m_status = TRUE;
+ m_status = true;
}
else
{
- m_status = FALSE;
+ m_status = false;
}
} // Card::Card()
scorefil.cpp
</sources>
<wx-lib>html</wx-lib>
+ <wx-lib>adv</wx-lib>
<wx-lib>core</wx-lib>
<wx-lib>base</wx-lib>
<win32-res>forty.rc</win32-res>
bool FortyApp::OnInit()
{
- bool largecards = FALSE;
+ bool largecards = false;
+
wxSize size(668,510);
if ((argc > 1) && (!wxStrcmp(argv[1],_T("-L"))))
{
- largecards = TRUE;
+ largecards = true;
size = wxSize(1000,750);
}
FortyFrame* frame = new FortyFrame(
0,
_T("Forty Thieves"),
- -1, -1, size.x, size.y,largecards
+ wxDefaultPosition,
+ size,
+ largecards
);
// Show the frame
- frame->Show(TRUE);
+ frame->Show(true);
frame->GetCanvas()->ShowPlayerDialog();
- return TRUE;
+ return true;
}
const wxColour& FortyApp::BackgroundColour()
}
// My frame constructor
-FortyFrame::FortyFrame(wxFrame* frame, const wxString& title, int x, int y, int w, int h,bool largecards):
- wxFrame(frame, -1, title, wxPoint(x, y), wxSize(w, h))
+FortyFrame::FortyFrame(wxFrame* frame, const wxString& title, const wxPoint& pos, const wxSize& size, bool largecards):
+ wxFrame(frame, wxID_ANY, title, pos, size)
{
#ifdef __WXMAC__
wxApp::s_macAboutMenuItemId = wxID_ABOUT ;
optionsMenu->Append(RIGHT_BUTTON_UNDO,
_T("&Right button undo"),
_T("Enables/disables right mouse button undo and redo"),
- TRUE
+ true
);
optionsMenu->Append(HELPING_HAND,
_T("&Helping hand"),
_T("Enables/disables hand cursor when a card can be moved"),
- TRUE
+ true
);
optionsMenu->Append(LARGE_CARDS,
_T("&Large cards"),
_T("Enables/disables large cards for high resolution displays"),
- TRUE
+ true
);
- optionsMenu->Check(HELPING_HAND, TRUE);
- optionsMenu->Check(RIGHT_BUTTON_UNDO, TRUE);
- optionsMenu->Check(LARGE_CARDS, largecards ? TRUE : FALSE);
+ optionsMenu->Check(HELPING_HAND, true);
+ optionsMenu->Check(RIGHT_BUTTON_UNDO, true);
+ optionsMenu->Check(LARGE_CARDS, largecards ? true : false);
wxMenu* helpMenu = new wxMenu;
helpMenu->Append(wxID_HELP_CONTENTS, _T("&Help Contents"), _T("Displays information about playing the game"));
if (largecards)
Card::SetScale(1.3);
- m_canvas = new FortyCanvas(this, 0, 0, 400, 400);
- wxLayoutConstraints* constr = new wxLayoutConstraints;
- constr->left.SameAs(this, wxLeft);
- constr->top.SameAs(this, wxTop);
- constr->right.SameAs(this, wxRight);
- constr->height.SameAs(this, wxHeight);
- m_canvas->SetConstraints(constr);
+ m_canvas = new FortyCanvas(this, wxDefaultPosition, size);
+
+ wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
+ topsizer->Add( m_canvas, 1, wxEXPAND | wxALL, 0);
+ SetSizer( topsizer );
+ topsizer->SetSizeHints( this );
CreateStatusBar();
}
void
FortyFrame::Exit(wxCommandEvent&)
{
- Close(TRUE);
+ Close(true);
}
void
#if wxUSE_HTML
if (wxFileExists(wxT("about.htm")))
{
- FortyAboutDialog dialog(this, -1, wxT("Forty Thieves Instructions"));
+ FortyAboutDialog dialog(this, wxID_ANY, wxT("Forty Thieves Instructions"));
if (dialog.ShowModal() == wxID_OK)
{
}
item0->Add( item2, 0, wxALIGN_RIGHT|wxALL, 5 );
- parent->SetAutoLayout( TRUE );
parent->SetSizer( item0 );
parent->Layout();
item0->Fit( parent );
item0->SetSizeHints( parent );
#endif
- return TRUE;
+ return true;
}
class FortyFrame: public wxFrame
{
public:
- FortyFrame(wxFrame* frame, const wxString& title, int x, int y, int w, int h,bool largecards);
+ FortyFrame(wxFrame* frame, const wxString& title, const wxPoint& pos, const wxSize& size, bool largecards);
virtual ~FortyFrame();
void OnCloseWindow(wxCloseEvent& event);
#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),
if (!m_inPlay)
{
- m_inPlay = TRUE;
+ m_inPlay = true;
m_numGames++;
}
DisplayScore(dc);
}
// This game is over
- m_inPlay = FALSE;
+ m_inPlay = false;
// Redraw the score box to update games won
DisplayScore(dc);
else
{
// user cancelled the dialog - exit the app
- ((wxFrame*)canvas->GetParent())->Close(TRUE);
+ ((wxFrame*)canvas->GetParent())->Close(true);
}
}
}
m_totalScore += m_currentScore;
}
m_currentScore = 0;
- m_inPlay = FALSE;
+ m_inPlay = false;
}
// 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);
{
if (m_foundations[i]->AcceptCard(card) && m_foundations[i] != pile)
{
- return TRUE;
+ return true;
}
}
for(i = 0; i < 10; i++)
m_bases[i]->AcceptCard(card) &&
m_bases[i] != pile)
{
- return TRUE;
+ return true;
}
}
}
}
- return FALSE;
+ return false;
}
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;
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;
}
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;
}
{
for (int i = 0; i <= m_topCard; i++)
{
- if (card == m_cards[i]) return TRUE;
+ if (card == m_cards[i]) return true;
}
- return FALSE;
+ return false;
}
// Calculate how far x, y is from top card in the pile
if (x >= cardX - Card::GetWidth() && x <= cardX + Card::GetWidth() &&
y >= cardY - Card::GetHeight() && y <= cardY + Card::GetHeight())
{
- return TRUE;
+ return true;
}
- return FALSE;
+ return false;
}
virtual Card* RemoveTopCard(wxDC& pDC, int xOffset = 0, int yOffset = 0);
// Functions to add a card to the top of a pile
- virtual bool AcceptCard(Card*) { return FALSE; }
+ virtual bool AcceptCard(Card*) { return false; }
virtual void AddCard(Card* card); // Add card to top of pile
virtual void AddCard(wxDC& pDC, Card* card); // Add card + redraw it
void SetPos(int x,int y) {m_x = x;m_y = y;};
wxWindow* parent,
ScoreFile* file
) :
- wxDialog(parent, -1, _T("Player Selection"),
- wxDefaultPosition, wxSize(320, 200),
+ wxDialog(parent, wxID_ANY, _T("Player Selection"),
+ wxDefaultPosition, wxDefaultSize,
wxDIALOG_MODAL | wxDEFAULT_DIALOG_STYLE),
m_scoreFile(file)
{
- // enable constraints
- SetAutoLayout (TRUE);
-
- wxStaticText* msg = new wxStaticText(this, -1, _T("Please select a name or type a new one:"));
+ wxStaticText* msg = new wxStaticText(this, wxID_ANY, _T("Please select a name or type a new one:"));
wxListBox* list = new wxListBox(
this, ID_LISTBOX,
list->Append(players[i]);
}
- m_textField = new wxTextCtrl(this, -1, _T(""), wxDefaultPosition, wxDefaultSize, 0);
+ m_textField = new wxTextCtrl(this, wxID_ANY, _T(""), wxDefaultPosition, wxDefaultSize, 0);
m_OK = new wxButton(this, wxID_OK, _T("OK"));
m_cancel = new wxButton(this, wxID_CANCEL, _T("Cancel"));
- wxLayoutConstraints* layout;
-
- // Constrain the msg at the top of the window
- layout = new wxLayoutConstraints;
- layout->left.SameAs (this, wxLeft, 10);
- layout->top.SameAs (this, wxTop, 10);
- layout->height.AsIs();
- layout->width.AsIs();
- msg->SetConstraints(layout);
-
- // Constrain the OK button
- layout = new wxLayoutConstraints;
- layout->left.SameAs (this, wxLeft, 10);
- layout->bottom.SameAs (this, wxBottom, 10);
- layout->height.AsIs();
- layout->width.AsIs();
- m_OK->SetConstraints(layout);
-
- // Constrain the OK button
- layout = new wxLayoutConstraints;
- layout->left.RightOf (m_OK, 10);
- layout->bottom.SameAs (this, wxBottom, 10);
- layout->height.AsIs();
- layout->width.AsIs();
- m_cancel->SetConstraints(layout);
-
- // Constrain the Name text entry field
- layout = new wxLayoutConstraints;
- layout->left.SameAs (this, wxLeft, 10);
- layout->right.SameAs (this, wxRight, 10);
- layout->bottom.SameAs (m_OK, wxTop, 10);
- layout->height.AsIs();
- m_textField->SetConstraints(layout);
-
- // Constrain the list of players
- layout = new wxLayoutConstraints;
- layout->left.SameAs (this, wxLeft, 10);
- layout->right.SameAs (this, wxRight, 10);
- layout->top.Below (msg, 10);
- layout->bottom.SameAs (m_textField, wxTop, 10);
- list->SetConstraints(layout);
-
- wxString prevPlayer = m_scoreFile->GetPreviousPlayer();
- if ((prevPlayer.Length() > 0) && (list->FindString(prevPlayer) != -1))
- {
- list->SetStringSelection(prevPlayer);
- m_textField->SetValue(prevPlayer);
- }
+ wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
+ button_sizer->Add( m_OK, 0, wxALL, 10 );
+ button_sizer->Add( m_cancel, 0, wxALL, 10 );
- m_textField->SetFocus();
+ wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
+ topsizer->Add( msg, 0, wxALL , 10 );
+ topsizer->Add( list, 1, wxEXPAND | wxLEFT | wxRIGHT, 10 );
+ topsizer->Add( m_textField, 0, wxEXPAND | wxLEFT | wxRIGHT | wxTOP, 10 );
+ topsizer->Add( button_sizer, 0, wxALIGN_LEFT );
- Layout();
+ SetSizer( topsizer );
+
+ topsizer->SetSizeHints( this );
CentreOnParent();
}
{
/*
m_player = "";
- Show(TRUE);
+ Show(true);
*/
return m_player;
}
#include "scorefil.h"
#include "scoredg.h"
+#define USE_GRID_FOR_SCORE 0
+
+#if USE_GRID_FOR_SCORE
+#include "wx/grid.h"
+#else
class ScoreCanvas : public wxScrolledWindow
{
public:
- ScoreCanvas(wxWindow* parent, ScoreFile* scoreFile);
+ ScoreCanvas(wxWindow* parent, ScoreFile* scoreFile, const wxPoint& pos, wxSize& size);
virtual ~ScoreCanvas();
void OnDraw(wxDC& dc);
wxString m_text;
};
-
-ScoreCanvas::ScoreCanvas(wxWindow* parent, ScoreFile* scoreFile) :
- wxScrolledWindow(parent)
+ScoreCanvas::ScoreCanvas(wxWindow* parent, ScoreFile* scoreFile, const wxPoint& pos, wxSize& size) :
+ wxScrolledWindow(parent, -1, pos, size, wxSUNKEN_BORDER)
{
+ SetBackgroundColour(*wxWHITE);
#ifdef __WXGTK__
m_font = wxTheFontList->FindOrCreateFont(12, wxROMAN, wxNORMAL, wxNORMAL);
#else
m_font = wxTheFontList->FindOrCreateFont(10, wxSWISS, wxNORMAL, wxNORMAL);
#endif
- wxArrayString players;
+ wxArrayString players;
scoreFile->GetPlayerList( players);
wxString os;
if (*str) str++;
}
}
+#endif
BEGIN_EVENT_TABLE(ScoreDialog, wxDialog)
EVT_CLOSE(ScoreDialog::OnCloseWindow)
END_EVENT_TABLE()
-ScoreDialog::ScoreDialog(
- wxWindow* parent,
- ScoreFile* file
- ) :
- wxDialog(parent, -1, _("Scores"),
- wxDefaultPosition, wxSize(310, 200),
+ScoreDialog::ScoreDialog(wxWindow* parent, ScoreFile* file) :
+ wxDialog(parent, wxID_ANY, _("Scores"),
+ wxDefaultPosition, wxSize(400, 300),
wxDIALOG_MODAL | wxDEFAULT_DIALOG_STYLE),
m_scoreFile(file)
{
- // enable constraints
- SetAutoLayout (TRUE);
-
- ScoreCanvas* list = new ScoreCanvas(this, m_scoreFile);
- m_OK = new wxButton(this, wxID_OK, _("OK"));
-
- wxLayoutConstraints* layout;
-
- // Constrain the OK button
- layout = new wxLayoutConstraints;
- layout->left.SameAs (this, wxLeft, 10);
- layout->bottom.SameAs (this, wxBottom, 10);
- layout->height.AsIs();
- layout->width.AsIs();
- m_OK->SetConstraints(layout);
-
- // Constrain the list of players
- layout = new wxLayoutConstraints;
- layout->left.SameAs (this, wxLeft, 10);
- layout->right.SameAs (this, wxRight, 10);
- layout->top.SameAs (this, wxTop, 10);
- layout->bottom.SameAs (m_OK, wxTop, 10);
- list->SetConstraints(layout);
-
- Layout();
+ // create grid with players
+ wxArrayString players;
+ file->GetPlayerList(players);
+
+ wxSize sz = wxSize(400, 300);
+
+#if USE_GRID_FOR_SCORE
+ wxGrid* list = new wxGrid(this, wxID_ANY, wxDefaultPosition, sz, 0);
+ list->CreateGrid(players.Count(), 4);
+ for (unsigned int i = 0; i < players.Count(); i++)
+ {
+ int wins, games, score;
+ wxString string_value;
+
+ file->ReadPlayersScore(players[i], wins, games, score);
+ int average = 0;
+ if (games > 0)
+ {
+ average = (2 * score + games) / (2 * games);
+ }
+ list->SetCellValue(i,0,players[i]);
+ string_value.Printf( _T("%u"), wins );
+ list->SetCellValue(i,1,string_value);
+ string_value.Printf( _T("%u"), games );
+ list->SetCellValue(i,2,string_value);
+ string_value.Printf( _T("%u"), average );
+ list->SetCellValue(i,3,string_value);
+ }
+ list->SetColLabelValue(0, _T("Players"));
+ list->SetColLabelValue(1, _T("Wins"));
+ list->SetColLabelValue(2, _T("Games"));
+ list->SetColLabelValue(3, _T("Score"));
+ list->SetEditable(false);
+ list->AutoSizeColumns();
+ list->AutoSizeRows();
+ list->SetRowLabelSize(0);
+ list->EnableDragRowSize(false);
+ list->EnableDragColSize(false);
+ list->EnableDragGridSize(false);
+#else
+ ScoreCanvas* list = new ScoreCanvas(this, m_scoreFile, wxDefaultPosition, sz);
+#endif
+
+ // locate and resize with sizers
+ wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
+ topsizer->Add( list, 1, wxALL|wxGROW, 10 );
+ topsizer->Add( new wxButton(this, wxID_OK, _("OK")), 0, wxALIGN_CENTER_HORIZONTAL|wxALL , 10 );
+
+ SetSizer( topsizer );
+
+ GetSizer()->Fit(this);
+ GetSizer()->SetSizeHints(this);
+
+ CentreOnParent();
}
ScoreDialog::~ScoreDialog()
void ScoreDialog::Display()
{
- Show(TRUE);
+ Show(true);
}
void ScoreDialog::OnCloseWindow(wxCloseEvent& WXUNUSED(event))