void GuessMyNumber::OnGuessClick() { // Validate number. unsigned int buf_number( 0 ); std::stringstream sstr( static_cast<std::string>( m_number_entry->GetText() ) ); sstr >> buf_number; if( buf_number < 1 || buf_number > 100 ) { m_hint_label->SetText( "Enter a number from 1 to 100." ); return; } ++m_tries; UpdateUI(); unsigned char number( static_cast<unsigned char>( buf_number ) ); if( number < m_number ) { m_hint_label->SetText( "My number is higher." ); } else if( number > m_number ) { m_hint_label->SetText( "My number is lower." ); } else { m_hint_label->SetText( "Correct!" ); m_guess_button->Show( false ); } m_number_entry->SetText( "" ); }
void GuessMyNumber::ResetGame() { m_tries = 0; m_number = static_cast<unsigned char>( std::rand() % 100 + 1 ); m_hint_label->SetText( "-" ); UpdateUI(); m_guess_button->Show( true ); }