Changeset 195


Ignore:
Timestamp:
05/01/2009 09:03:29 PM (3 years ago)
Author:
guyru
Message:

Re-factor the check whether the dice were rolled before each scoring.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/MainFrame.cpp

    r194 r195  
    658658        wxString out; 
    659659        short int temp; 
    660         if(m_rolls < 3){ 
    661                 YahtzeeBonus(); 
    662                 switch(event.GetId()) { 
    663                 case ID_ACES: 
    664                         temp = m_score_dice.Aces(); 
    665                         break; 
    666                 case ID_TWOS: 
    667                         temp = m_score_dice.Twos(); 
    668                         break; 
    669                 case ID_THREES: 
    670                         temp = m_score_dice.Threes(); 
    671                         break; 
    672                 case ID_FOURS: 
    673                         temp = m_score_dice.Fours(); 
    674                         break; 
    675                 case ID_FIVES: 
    676                         temp = m_score_dice.Fives(); 
    677                         break; 
    678                 case ID_SIXES: 
    679                         temp = m_score_dice.Sixes(); 
    680                         break; 
    681                 } 
    682          
    683                 out.Printf(wxT("%i"),temp); 
    684                 wxTextCtrl *text_ctrl = dynamic_cast<wxTextCtrl*>(FindWindow(event.GetId() - ID_ACES + ID_ACESTEXT)); 
    685                 text_ctrl->SetValue(out); 
    686                 text_ctrl->SetBackgroundColour(*wxWHITE); 
    687                 text_ctrl->Refresh(); 
    688                  
    689                 PostScore(event.GetId()); 
    690         } 
    691         else  
    692                 wxMessageBox(wxT("First you need to roll, and after you roll you may score"), wxT("Open Yahtzee"), wxOK | wxICON_INFORMATION, this); 
     660        if (!IsValidClick()) 
     661                return; 
     662 
     663        YahtzeeBonus(); 
     664 
     665        switch(event.GetId()) { 
     666        case ID_ACES: 
     667                temp = m_score_dice.Aces(); 
     668                break; 
     669        case ID_TWOS: 
     670                temp = m_score_dice.Twos(); 
     671                break; 
     672        case ID_THREES: 
     673                temp = m_score_dice.Threes(); 
     674                break; 
     675        case ID_FOURS: 
     676                temp = m_score_dice.Fours(); 
     677                break; 
     678        case ID_FIVES: 
     679                temp = m_score_dice.Fives(); 
     680                break; 
     681        case ID_SIXES: 
     682                temp = m_score_dice.Sixes(); 
     683                break; 
     684        } 
     685         
     686        out.Printf(wxT("%i"),temp); 
     687        wxTextCtrl *text_ctrl = dynamic_cast<wxTextCtrl*>(FindWindow(event.GetId() - ID_ACES + ID_ACESTEXT)); 
     688        text_ctrl->SetValue(out); 
     689        text_ctrl->SetBackgroundColour(*wxWHITE); 
     690        text_ctrl->Refresh(); 
     691         
     692        PostScore(event.GetId()); 
    693693} 
    694694 
     
    699699void MainFrame::On3ofakindButton(wxCommandEvent& event) 
    700700{ 
    701         if(m_rolls>=3) { 
    702                 wxMessageBox(wxT("First you need to roll, and after you roll you may score"), wxT("Open Yahtzee"), wxOK | wxICON_INFORMATION, this); 
    703                 return; 
    704         } 
     701        if (!IsValidClick()) 
     702                return; 
     703         
    705704        YahtzeeBonus(); 
    706705        wxString out; 
     
    721720void MainFrame::On4ofakindButton(wxCommandEvent& event) 
    722721{ 
    723         if(m_rolls>=3) { 
    724                 wxMessageBox(wxT("First you need to roll, and after you roll you may score"), wxT("Open Yahtzee"), wxOK | wxICON_INFORMATION, this); 
    725                 return; 
    726         } 
     722        if (!IsValidClick()) 
     723                return; 
     724         
    727725        YahtzeeBonus(); 
    728726        wxString out; 
     
    745743        wxString out; 
    746744 
    747         if(m_rolls>=3) { 
    748                 wxMessageBox(wxT("First you need to roll, and after you roll you may score"), wxT("Open Yahtzee"), wxOK | wxICON_INFORMATION, this); 
    749                 return; 
    750         } 
     745        if (!IsValidClick()) 
     746                return; 
     747         
    751748        YahtzeeBonus(); 
    752749 
     
    768765        wxString out; 
    769766 
    770         if(m_rolls>=3) { 
    771                 wxMessageBox(wxT("First you need to roll, and after you roll you may score"), wxT("Open Yahtzee"), wxOK | wxICON_INFORMATION, this); 
    772                 return; 
    773         } 
     767        if (!IsValidClick()) 
     768                return; 
    774769 
    775770        YahtzeeBonus(); 
     
    792787        wxString out; 
    793788         
    794         if(m_rolls>=3) { 
    795                 wxMessageBox(wxT("First you need to roll, and after you roll you may score"), wxT("Open Yahtzee"), wxOK | wxICON_INFORMATION, this); 
    796                 return; 
    797         } 
     789        if (!IsValidClick()) 
     790                return; 
    798791 
    799792        YahtzeeBonus(); 
     
    817810        wxString out; 
    818811         
    819         if(m_rolls>=3) { 
    820                 wxMessageBox(wxT("First you need to roll, and after you roll you may score"), wxT("Open Yahtzee"), wxOK | wxICON_INFORMATION, this); 
    821                 return; 
    822         } 
     812        if (!IsValidClick()) 
     813                return; 
    823814         
    824815        if (m_score_dice.IsYahtzee()) m_yahtzee = true; 
     
    839830{ 
    840831        wxString out; 
    841         if(m_rolls < 3){ 
    842                 YahtzeeBonus(); 
    843          
    844                 out.Printf(wxT("%i"),m_score_dice.Chance()); 
    845                 wxTextCtrl *text_ctrl = dynamic_cast<wxTextCtrl*>(FindWindow(ID_CHANCETEXT)); 
    846                 text_ctrl->SetValue(out); 
    847                 text_ctrl->SetBackgroundColour(*wxWHITE); 
    848                 text_ctrl->Refresh(); 
    849                 PostScore(event.GetId()); 
    850         } 
    851         else  
    852                 wxMessageBox(wxT("First you need to roll, and after you roll you may score"), wxT("Open Yahtzee"), wxOK | wxICON_INFORMATION, this); 
    853  
     832        if (!IsValidClick()) 
     833                return; 
     834 
     835        YahtzeeBonus(); 
     836 
     837        out.Printf(wxT("%i"),m_score_dice.Chance()); 
     838        wxTextCtrl *text_ctrl = dynamic_cast<wxTextCtrl*>(FindWindow(ID_CHANCETEXT)); 
     839        text_ctrl->SetValue(out); 
     840        text_ctrl->SetBackgroundColour(*wxWHITE); 
     841        text_ctrl->Refresh(); 
     842        PostScore(event.GetId()); 
    854843} 
    855844 
     
    13441333} 
    13451334 
     1335bool MainFrame::IsValidClick() 
     1336{ 
     1337        if (m_rolls >= 3) { 
     1338                wxMessageBox(wxT("First you need to roll, and after you roll you may score."), 
     1339                        wxT("Open Yahtzee"), wxOK | wxICON_INFORMATION, this); 
     1340                return false; 
     1341        } 
     1342        return true; 
     1343} 
     1344 
    13461345MainFrame::~MainFrame() { 
    13471346        // free pointers 
  • trunk/src/MainFrame.h

    r194 r195  
    9898        void ConnectEventTable(); 
    9999        void AddControlsAndLayout(); 
     100        /** 
     101         * Check if a click on a score button is valid or should 
     102         * be ignored. 
     103         * \returns true if the click is valid and should be scored. 
     104         */ 
     105        bool IsValidClick(); 
    100106 
    101107        void OnRollButton (); 
Note: See TracChangeset for help on using the changeset viewer.