MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    //populate highscores list
    HighScore* scores = new HighScore();
    if(scores->load()){
        for(unsigned int i = 0; i < scores->getScores().size(); ++i ) {
            Score *score = scores->getScores().at(i);
            QString QName = QString::fromStdString(score->getName());
            QString QScore = QString::number(score->getScore());
            ui->lstScores->addItem(QName + " -- " + QScore);

        }
    }
    else                //no file exists
        scores->save(); //creates new highscores file file

    //connect(ui->btnNewGame, SIGNAL(click()), this, SLOT(openGameWindow()));
    //set the help and score screens to be invisible
    ui->brwHelp->hide();
    ui->boxHighScores->hide();
}
Beispiel #2
0
 std::shared_ptr<dick::StateNode> next_state() override
 {
     HighScore hs = HighScore::load("high_score", m_context->m_const.highscore_max_entries);
     if (hs.can_insert(m_context->m_var.m_ball_count, m_context->m_var.m_score)) {
         return make_highscore_input_state(m_context);
     } else {
         return make_highscore_display_state(m_context);
     }
 }
void ScreenNameEntryTraditional::Init()
{
    if( PREFSMAN->m_sTestInitialScreen.Get() == m_sName )
    {
        GAMESTATE->m_bSideIsJoined[PLAYER_1] = true;
        GAMESTATE->m_bSideIsJoined[PLAYER_2] = true;
        GAMESTATE->m_MasterPlayerNumber = PLAYER_1;
        GAMESTATE->m_PlayMode.Set( PLAY_MODE_REGULAR );
        GAMESTATE->SetCurrentStyle( GAMEMAN->GameAndStringToStyle( GAMEMAN->GetDefaultGame(),"versus") );
        for( int z = 0; z < 3; ++z )
        {
            StageStats ss;
            const vector<Song*> &apSongs = SONGMAN->GetAllSongs();
            ss.m_vpPlayedSongs.push_back( apSongs[rand()%apSongs.size()] );
            ss.m_vpPossibleSongs = ss.m_vpPlayedSongs;
            ss.m_pStyle = GAMESTATE->GetCurrentStyle();
            ss.m_playMode = GAMESTATE->m_PlayMode;
            ASSERT( ss.m_vpPlayedSongs[0]->GetAllSteps().size() );
            StepsType st = GAMESTATE->GetCurrentStyle()->m_StepsType;

            FOREACH_PlayerNumber( p )
            {
                Steps *pSteps = ss.m_vpPlayedSongs[0]->GetAllSteps()[0];
                ss.m_player[p].m_iStepsPlayed = 1;
                GAMESTATE->m_pCurSteps[p].Set( pSteps );
                ss.m_player[p].m_iPossibleDancePoints = 100;
                ss.m_player[p].m_iActualDancePoints = 100;
                ss.m_player[p].m_iScore = 100;
                ss.m_player[p].m_iPossibleDancePoints = 1000;
                ss.m_player[p].m_iActualDancePoints = 985;
                ss.m_player[p].m_vpPossibleSteps.push_back( pSteps );

                HighScore hs;
                hs.SetGrade( Grade_Tier03 );
                hs.SetPercentDP( ss.m_player[p].GetPercentDancePoints() );
                hs.SetScore( ss.m_player[p].m_iScore );
                hs.SetDateTime( DateTime::GetNowDateTime() );
                int a, b;
                PROFILEMAN->AddStepsScore( ss.m_vpPlayedSongs[0], pSteps, p, hs, a, b );
                PROFILEMAN->AddStepsScore( ss.m_vpPlayedSongs[0], pSteps, p, hs, a, b );
                PROFILEMAN->AddStepsScore( ss.m_vpPlayedSongs[0], pSteps, p, hs, a, b );
                PROFILEMAN->AddStepsScore( ss.m_vpPlayedSongs[0], pSteps, p, hs, a, b );
                PROFILEMAN->AddStepsScore( ss.m_vpPlayedSongs[0], pSteps, p, hs, a, b );
                PROFILEMAN->AddCategoryScore( st, RANKING_A, p, hs, a, b );
            }

            STATSMAN->m_vPlayedStageStats.push_back( ss );
        }

    }
Beispiel #4
0
void HighScoreList::AddHighScore( HighScore hs, int &iIndexOut, bool bIsMachine )
{
	int i;
	for( i=0; i<(int)vHighScores.size(); i++ )
	{
		if( hs >= vHighScores[i] )
			break;
	}
	const int iMaxScores = bIsMachine ? 
		PREFSMAN->m_iMaxHighScoresPerListForMachine : 
		PREFSMAN->m_iMaxHighScoresPerListForPlayer;
	if( i < iMaxScores )
	{
		vHighScores.insert( vHighScores.begin()+i, hs );
		iIndexOut = i;

		// Delete extra machine high scores in RemoveAllButOneOfEachNameAndClampSize
		// and not here so that we don't end up with less than iMaxScores after 
		// removing HighScores with duplicate names.
		//
		if( !bIsMachine )
			ClampSize( bIsMachine );
	}
	HighGrade = min( hs.GetGrade(), HighGrade );
}
    void on_key(dick::Key key, bool down) override
    {
        if (!down) {
            return;
        }

        if (key >= dick::Key::A && key <= dick::Key::Z) {
            m_name.push_back(
                static_cast<int>(key) -
                static_cast<int>(dick::Key::A) +
                'A');

        } else if (key == dick::Key::SPACE) {
            m_name.push_back(' ');

        } else if (key == dick::Key::BACKSPACE && !m_name.empty()) {
            m_name.pop_back();

        } else if (key == dick::Key::ENTER) {
            m_high_score.add_entry(
                m_context->m_var.m_ball_count,
                { m_context->m_var.m_score, m_name });
            HighScore::store("high_score", m_high_score);
            t_transition_required = true;
        }
    }
Beispiel #6
0
bool HighScore::operator>=( const HighScore& other ) const
{
	/* Make sure we treat AAAA as higher than AAA, even though the score
 	 * is the same. */
	if( PREFSMAN->m_bPercentageScoring )
	{
		if( GetPercentDP() != other.GetPercentDP() )
			return GetPercentDP() >= other.GetPercentDP();
	}
	else
	{
		if( GetScore() != other.GetScore() )
			return GetScore() >= other.GetScore();
	}

	return GetGrade() >= other.GetGrade();
}
 HighScoreDisplayState(KulkiContext* context) :
     m_context { context },
     m_high_score { HighScore::load("high_score", m_context->m_const.highscore_max_entries) },
     m_ball_counts { m_high_score.get_ball_counts() },
     m_ball_index { 0 },
     m_period { 5.0 },
     m_timer { m_period }
 {
     std::sort(begin(m_ball_counts), end(m_ball_counts));
     m_rebuild_ui();
 }
    std::unique_ptr<dick::GUI::Widget> m_make_score_container()
    {
        const double text_height = al_get_font_line_height(m_context->m_const.menu_font);
        double max_width = 0;

        std::vector<HighScoreEntry> entries =
            m_high_score.get_entries_for_balls(m_ball_counts[m_ball_index]);
        std::reverse(begin(entries), end(entries));

        auto name_rail = m_context->m_gui.make_container_rail(
                dick::GUI::Direction::DOWN,
                text_height * 1.125);

        auto score_rail = m_context->m_gui.make_container_rail(
                dick::GUI::Direction::DOWN,
                text_height * 1.125);

        for (const auto& entry: entries) {
            double name_width = al_get_text_width(
                    m_context->m_const.menu_font,
                    entry.name.c_str());
            if (name_width > max_width) {
                max_width = name_width;
            }
            name_rail->insert(
                m_context->m_gui.make_label_ex(
                    entry.name,
                    m_context->m_const.menu_font));
            score_rail->insert(
                m_context->m_gui.make_label_ex(
                    std::to_string(entry.score),
                    m_context->m_const.menu_font));
        }

        score_rail->set_offset({ 2 * max_width, 0.0 });

        auto container = m_context->m_gui.make_container_free();
        container->insert(std::move(name_rail));
        container->insert(std::move(score_rail));

        auto panel = m_context->m_gui.make_container_panel();
        panel->insert(std::unique_ptr<dick::GUI::Widget> { container.release() });

        std::unique_ptr<dick::GUI::Widget> result = std::move(panel);

        return result;
    }
float ScreenRanking::SetPage( PageToShow pts )
{
	bool bBanner = false; 
	bool bBannerFrame = false;
	bool bShowCategory = false; 
	bool bShowCourseTitle = false; 
	bool bShowStepsType = false; 
	bool bShowBullets = false; 
	bool bShowNames = false;
	bool bShowScores = false; 
	bool bShowPoints = false; 
	bool bShowTime = false;
	bool bShowDifficulty = false; 
	bool bShowStepsScore = false;
	bool bShowCourseDifficulty = false;
	bool bShowCourseScore = false;
	switch( pts.type )
	{
	case PAGE_TYPE_CATEGORY:
		bBanner = false; 
		bBannerFrame = false;
		bShowCategory = true;
		bShowCourseTitle = false;
		bShowStepsType = true;
		bShowBullets = true;
		bShowNames = true;
		bShowScores = true;
		bShowPoints = false;
		bShowTime = false;
		bShowDifficulty = false;
		bShowStepsScore = false;
		break;
	case PAGE_TYPE_TRAIL:
		bBanner = true; 
		bBannerFrame = true;
		bShowCategory = false;
		bShowCourseTitle = true;
		bShowStepsType = true;
		bShowBullets = true;
		bShowNames = true;
		bShowScores = !pts.pCourse->IsOni();
		bShowPoints = pts.pCourse->IsOni();
		bShowTime = pts.pCourse->IsOni();
		bShowDifficulty = false;
		bShowStepsScore = false;
		break;
	case PAGE_TYPE_ALL_STEPS:
		bBanner = false; 
		bBannerFrame = false;
		bShowCategory = false;
		bShowCourseTitle = false;
		bShowStepsType = true;
		bShowBullets = false;
		bShowNames = false;
		bShowScores = false;
		bShowPoints = false;
		bShowTime = false;
		bShowDifficulty = true;
		bShowStepsScore = true;
		break;
	case PAGE_TYPE_ALL_COURSES:
		bShowStepsType = true;
		bShowCourseScore = true;
		bShowCourseDifficulty = true;
		break;
	default:
		ASSERT(0);
	}


	// Reset
	m_Banner.SetHidden( !bBanner );
	if( bBanner )
	{
		m_Banner.Reset();
		SET_XY_AND_ON_COMMAND( m_Banner );
	}

	m_sprBannerFrame.SetHidden( !bBannerFrame );
	if( bBannerFrame )
	{
		m_sprBannerFrame.Reset();
		SET_XY_AND_ON_COMMAND( m_sprBannerFrame );
	}

	m_textCategory.SetHidden( !bShowCategory );
	if( bShowCategory )
	{
		m_textCategory.Reset();
		SET_XY_AND_ON_COMMAND( m_textCategory );
	}

	m_textCourseTitle.SetHidden( !bShowCourseTitle );
	if( bShowCourseTitle )
	{
		m_textCourseTitle.Reset();
		SET_XY_AND_ON_COMMAND( m_textCourseTitle );
	}

	m_textStepsType.SetHidden( !bShowStepsType );
	if( bShowStepsType )
	{
		m_textStepsType.Reset();
		SET_XY_AND_ON_COMMAND( m_textStepsType );
	}

	// UGLY: We have to call AddChild every time we re-load an AutoActor
	// because the internal Actor* changes.
	if( (Actor*)m_sprPageType )
		this->RemoveChild( m_sprPageType );
	m_sprPageType.Load( THEME->GetPathG(m_sName, "PageType "+PageTypeToString(pts.type)) );
	m_sprPageType->SetName( "PageType" );
	this->AddChild( m_sprPageType );
	SET_XY_AND_ON_COMMAND( m_sprPageType );

	{
		for( int l=0; l<NUM_RANKING_LINES; l++ )
		{
			m_sprBullets[l].SetHidden( !bShowBullets );
			if( bShowBullets )
			{
				m_sprBullets[l].Reset();
				m_sprBullets[l].StopAnimating();
				m_sprBullets[l].SetState( l );
				m_sprBullets[l].SetXY( BULLET_X(l), BULLET_Y(l) );
				ON_COMMAND( m_sprBullets[l] );
			}

			m_textNames[l].SetHidden( !bShowNames );
			if( bShowNames )
			{
				m_textNames[l].Reset();
				m_textNames[l].SetXY( NAME_X(l), NAME_Y(l) );
				m_textNames[l].SetDiffuse( STEPS_TYPE_COLOR(pts.colorIndex) );
				ON_COMMAND( m_textNames[l] );
			}

			m_textScores[l].SetHidden( !bShowScores );
			if( bShowScores )
			{
				m_textScores[l].Reset();
				m_textScores[l].SetXY( SCORE_X(l), SCORE_Y(l) );
				m_textScores[l].SetDiffuse( STEPS_TYPE_COLOR(pts.colorIndex) );
				ON_COMMAND( m_textScores[l] );
			}
			
			m_textPoints[l].SetHidden( !bShowPoints );
			if( bShowPoints )
			{
				m_textPoints[l].Reset();
				m_textPoints[l].SetXY( POINTS_X(l), POINTS_Y(l) );
				m_textPoints[l].SetDiffuse( STEPS_TYPE_COLOR(pts.colorIndex) );
				ON_COMMAND( m_textPoints[l] );
			}
			
			m_textTime[l].SetHidden( !bShowTime );
			if( bShowTime )
			{
				m_textTime[l].Reset();
				m_textTime[l].SetXY( TIME_X(l), TIME_Y(l) );
				m_textTime[l].SetDiffuse( STEPS_TYPE_COLOR(pts.colorIndex) );
				ON_COMMAND( m_textTime[l] );
			}
		}
	}

	{
		for( vector<Difficulty>::iterator dc_iter=m_vDiffsToShow.begin(); dc_iter!=m_vDiffsToShow.end(); dc_iter++ )
		{
			m_sprDifficulty[*dc_iter]->SetHidden( !bShowDifficulty );
			if( bShowDifficulty )
			{
				m_sprDifficulty[*dc_iter]->Reset();
				m_sprDifficulty[*dc_iter]->SetXY( DIFFICULTY_X(*dc_iter), DIFFICULTY_Y );
				ON_COMMAND( m_sprDifficulty[*dc_iter] );
			}
		}

		m_ListScoreRowItems.SetHidden( !bShowStepsScore );
		if( bShowStepsScore )
		{
			m_ListScoreRowItems.Reset();
			SET_XY_AND_ON_COMMAND( m_ListScoreRowItems );

			vector<Actor*> vpActors;
			for( unsigned i=0; i<m_vpStepsScoreRowItem.size(); i++ )
				vpActors.push_back( m_vpStepsScoreRowItem[i] );
			m_ListScoreRowItems.Load( vpActors, SONG_SCORE_ROWS_TO_SHOW, SCREEN_WIDTH, ROW_SPACING_Y, false, SONG_SCORE_SECONDS_PER_ROW, 0, false );

			for( unsigned s=0; s<m_vpStepsScoreRowItem.size(); s++ )
			{
				StepsScoreRowItem *pStepsScoreRowItems = m_vpStepsScoreRowItem[s];
				pStepsScoreRowItems->m_sprSongFrame.Reset();
				pStepsScoreRowItems->m_sprSongFrame.SetXY( SONG_FRAME_OFFSET_X, SONG_FRAME_OFFSET_Y );
				pStepsScoreRowItems->m_sprSongFrame.SetUseZBuffer( true );
				ON_COMMAND( pStepsScoreRowItems->m_sprSongFrame );

				pStepsScoreRowItems->m_textSongTitle.Reset();
				pStepsScoreRowItems->m_textSongTitle.SetXY( SONG_TITLE_OFFSET_X, SONG_TITLE_OFFSET_Y );
				pStepsScoreRowItems->m_textSongTitle.SetUseZBuffer( true );
				ON_COMMAND( pStepsScoreRowItems->m_textSongTitle );

				for( vector<Difficulty>::iterator dc_iter=m_vDiffsToShow.begin(); dc_iter!=m_vDiffsToShow.end(); dc_iter++ )
				{
					pStepsScoreRowItems->m_textStepsScore[*dc_iter].Reset();
					pStepsScoreRowItems->m_textStepsScore[*dc_iter].SetXY( STEPS_SCORE_OFFSET_X(*dc_iter), STEPS_SCORE_OFFSET_Y );
					pStepsScoreRowItems->m_textStepsScore[*dc_iter].SetUseZBuffer( true );
					pStepsScoreRowItems->m_textStepsScore[*dc_iter].SetDiffuse( STEPS_TYPE_COLOR(pts.colorIndex) );
					ON_COMMAND( pStepsScoreRowItems->m_textStepsScore[*dc_iter] );
				}
			}
		}
	}

	{
		FOREACH_ShownCourseDifficulty(d)
		{
			m_sprCourseDifficulty[d]->SetHidden( !bShowCourseDifficulty );
			if( bShowCourseDifficulty )
			{
				m_sprCourseDifficulty[d]->Reset();
				m_sprCourseDifficulty[d]->SetXY( COURSE_DIFFICULTY_X(d), COURSE_DIFFICULTY_Y );
				ON_COMMAND( m_sprCourseDifficulty[d] );
			}
		}

		m_ListCourseRowItems.SetHidden( !bShowCourseScore );
		if( bShowCourseScore )
		{
			m_ListCourseRowItems.Reset();
			SET_XY_AND_ON_COMMAND( m_ListCourseRowItems );

			vector<Actor*> vpActors;
			for( unsigned i=0; i<m_vpCourseScoreRowItem.size(); i++ )
				vpActors.push_back( m_vpCourseScoreRowItem[i] );
			m_ListCourseRowItems.Load( vpActors, SONG_SCORE_ROWS_TO_SHOW, SCREEN_WIDTH, ROW_SPACING_Y, false, SONG_SCORE_SECONDS_PER_ROW, 0, false );

			for( unsigned s=0; s<m_vpCourseScoreRowItem.size(); s++ )
			{
				CourseScoreRowItem *pCourseScoreRowItem = m_vpCourseScoreRowItem[s];
				pCourseScoreRowItem->m_sprSongFrame.Reset();
				pCourseScoreRowItem->m_sprSongFrame.SetXY( SONG_FRAME_OFFSET_X, SONG_FRAME_OFFSET_Y );
				pCourseScoreRowItem->m_sprSongFrame.SetUseZBuffer( true );
				ON_COMMAND( pCourseScoreRowItem->m_sprSongFrame );

				pCourseScoreRowItem->m_textSongTitle.Reset();
				pCourseScoreRowItem->m_textSongTitle.SetXY( SONG_TITLE_OFFSET_X, SONG_TITLE_OFFSET_Y );
				pCourseScoreRowItem->m_textSongTitle.SetUseZBuffer( true );
				ON_COMMAND( pCourseScoreRowItem->m_textSongTitle );

				FOREACH_ShownCourseDifficulty(d)
				{
					pCourseScoreRowItem->m_textStepsScore[d].Reset();
					pCourseScoreRowItem->m_textStepsScore[d].SetXY( COURSE_SCORE_OFFSET_X(d), COURSE_SCORE_OFFSET_Y );
					pCourseScoreRowItem->m_textStepsScore[d].SetUseZBuffer( true );
					pCourseScoreRowItem->m_textStepsScore[d].SetDiffuse( STEPS_TYPE_COLOR(pts.colorIndex) );
					ON_COMMAND( pCourseScoreRowItem->m_textStepsScore[d] );
				}
			}
		}
	}

	// get ranking feat list
	

	//
	// init page
	//
	switch( pts.type )
	{
	case PAGE_TYPE_CATEGORY:
		{
			m_textCategory.SetText( ssprintf("Type %c", 'A'+pts.category) );
			m_textStepsType.SetText( GameManager::StepsTypeToThemedString(pts.nt) );

			for( int l=0; l<NUM_RANKING_LINES; l++ )
			{
				HighScoreList& hsl = PROFILEMAN->GetMachineProfile()->GetCategoryHighScoreList(pts.nt,pts.category);
				HighScore hs;
				bool bRecentHighScore = false;
				if( l < (int)hsl.vHighScores.size() )
				{
					hs = hsl.vHighScores[l];
					CString *psName = &hsl.vHighScores[l].sName;
					bRecentHighScore = find( GAMESTATE->m_vpsNamesThatWereFilled.begin(), GAMESTATE->m_vpsNamesThatWereFilled.end(), psName ) != GAMESTATE->m_vpsNamesThatWereFilled.end();
				}
				else
				{
					hs.sName = NO_SCORE_NAME;				
				}

				m_textNames[l].SetText( hs.GetDisplayName() );
				m_textScores[l].SetText( ssprintf("%09i",hs.iScore) );
				m_textNames[l].SetDiffuse( STEPS_TYPE_COLOR(pts.colorIndex) );
				m_textScores[l].SetDiffuse( STEPS_TYPE_COLOR(pts.colorIndex) );

				if( bRecentHighScore )
				{
					m_textNames[l].SetEffectGlowBlink(0.1f);
					m_textScores[l].SetEffectGlowBlink(0.1f);
				}
				else
				{
					m_textNames[l].SetEffectNone();
					m_textScores[l].SetEffectNone();
				}
			}
		}
		return SECONDS_PER_PAGE;
	case PAGE_TYPE_TRAIL:
		{
			m_textCourseTitle.SetText( pts.pCourse->GetFullDisplayTitle() );
			m_Banner.LoadFromCourse( pts.pCourse );
			m_textStepsType.SetText( GameManager::StepsTypeToThemedString(pts.nt) );

			const HighScoreList &hsl = PROFILEMAN->GetMachineProfile()->GetCourseHighScoreList( pts.pCourse, pts.pTrail );
			for( int l=0; l<NUM_RANKING_LINES; l++ )
			{
				HighScore hs;
				bool bRecentHighScore = false;
				if( l < (int)hsl.vHighScores.size() )
				{
					hs = hsl.vHighScores[l];
					const CString *psName = &hsl.vHighScores[l].sName;
					bRecentHighScore = find( GAMESTATE->m_vpsNamesThatWereFilled.begin(), GAMESTATE->m_vpsNamesThatWereFilled.end(), psName ) != GAMESTATE->m_vpsNamesThatWereFilled.end();
				}
				else
				{
					hs.sName = NO_SCORE_NAME;				
				}

				m_textNames[l].SetText( hs.GetDisplayName() );
				if( pts.pCourse->IsOni() )
				{
					m_textPoints[l].SetText( ssprintf("%04d",hs.iScore) );
					m_textTime[l].SetText( SecondsToMMSSMsMs(hs.fSurviveSeconds) );
					m_textScores[l].SetText( "" );
				} else {
					m_textPoints[l].SetText( "" );
					m_textTime[l].SetText( "" );
					m_textScores[l].SetText( ssprintf("%09d",hs.iScore) );
				}
				m_textNames[l].SetDiffuse( STEPS_TYPE_COLOR(pts.colorIndex) );
				m_textPoints[l].SetDiffuse( STEPS_TYPE_COLOR(pts.colorIndex) );
				m_textTime[l].SetDiffuse( STEPS_TYPE_COLOR(pts.colorIndex) );
				m_textScores[l].SetDiffuse( STEPS_TYPE_COLOR(pts.colorIndex) );

				if( bRecentHighScore )
				{
					m_textNames[l].SetEffectGlowBlink(0.1f);
					m_textScores[l].SetEffectGlowBlink(0.1f);
				}
				else
				{
					m_textNames[l].SetEffectNone();
					m_textScores[l].SetEffectNone();
				}
			}
		}
		return SECONDS_PER_PAGE;
	case PAGE_TYPE_ALL_STEPS:
		{
			m_textStepsType.SetText( GameManager::StepsTypeToThemedString(pts.nt) );

			for( unsigned s=0; s<m_vpStepsScoreRowItem.size(); s++ )
			{
				StepsScoreRowItem *pStepsScoreRowItem = m_vpStepsScoreRowItem[s];
				const Song* pSong = pStepsScoreRowItem->m_pSong;

				pStepsScoreRowItem->m_textSongTitle.SetText( pSong->GetFullDisplayTitle() );

				for( vector<Difficulty>::iterator dc_iter = m_vDiffsToShow.begin(); dc_iter != m_vDiffsToShow.end(); dc_iter++ )
				{							
					const Steps* pSteps = pSong->GetStepsByDifficulty( pts.nt, *dc_iter, false );
					BitmapText* pTextStepsScore = &pStepsScoreRowItem->m_textStepsScore[*dc_iter];

					if( pSteps == NULL )
					{
						pTextStepsScore->SetHidden( true );
					}
					else
					{
						HighScoreList &hsl = PROFILEMAN->GetMachineProfile()->GetStepsHighScoreList(pSong,pSteps);
						HighScore hs = hsl.GetTopScore();
						bool bRecentHighScore = false;
						if( !hsl.vHighScores.empty() )
						{
							hs = hsl.GetTopScore();
							const CString *psName = &hsl.GetTopScore().sName;
							bRecentHighScore = find( GAMESTATE->m_vpsNamesThatWereFilled.begin(), GAMESTATE->m_vpsNamesThatWereFilled.end(), psName ) != GAMESTATE->m_vpsNamesThatWereFilled.end();
						}
						else
						{
							hs.sName = NO_SCORE_NAME;				
						}

						CString s;
						s = hs.GetDisplayName() + "\n";
						s += ssprintf( "%0*.*f%%", PERCENT_TOTAL_SIZE, PERCENT_DECIMAL_PLACES, hs.fPercentDP*100 );
						pTextStepsScore->SetText( s );
					}
				}
			}
		}
		return m_ListScoreRowItems.GetSecondsForCompleteScrollThrough();
	case PAGE_TYPE_ALL_COURSES:
		{
			m_textStepsType.SetText( GameManager::StepsTypeToThemedString(pts.nt) );

			for( unsigned c=0; c<m_vpCourseScoreRowItem.size(); c++ )
			{
				CourseScoreRowItem *pCourseScoreRowItem = m_vpCourseScoreRowItem[c];
				const Course* pCourse = pCourseScoreRowItem->m_pCourse;

				pCourseScoreRowItem->m_textSongTitle.SetText( pCourse->GetFullDisplayTitle() );
				FOREACH_ShownCourseDifficulty( cd )
				{
					BitmapText* pTextStepsScore = &pCourseScoreRowItem->m_textStepsScore[cd];

					Trail *pTrail = pCourse->GetTrail( pts.nt, cd );
					pTextStepsScore->SetHidden( pTrail==NULL );
					if( pTrail == NULL )
						continue;

					const HighScoreList &hsl = PROFILEMAN->GetMachineProfile()->GetCourseHighScoreList( pCourse, pTrail );

					HighScore hs;
					bool bRecentHighScore = false;
					if( !hsl.vHighScores.empty() )
					{
						hs = hsl.vHighScores[0];
						const CString *psName = &hsl.GetTopScore().sName;
						bRecentHighScore = find( GAMESTATE->m_vpsNamesThatWereFilled.begin(), GAMESTATE->m_vpsNamesThatWereFilled.end(), psName ) != GAMESTATE->m_vpsNamesThatWereFilled.end();
					}
					else
					{
						hs.sName = NO_SCORE_NAME;				
					}

					CString s;
					s = hs.GetDisplayName() + "\n";
					s += ssprintf( "%0*.*f%%", PERCENT_TOTAL_SIZE, PERCENT_DECIMAL_PLACES, hs.fPercentDP*100 );
					pTextStepsScore->SetText( s );
				}
			}
		}
		return m_ListCourseRowItems.GetSecondsForCompleteScrollThrough();
	default:
		ASSERT(0);
		return 0;
	}
}
Beispiel #10
0
HighScoresScreen::HighScoresScreen(SDLScreen* sdl_screen):Screen(sdl_screen)
{
	SDL_Surface* bkg=0;
	lb_title_=0;
	lb_totexcl_=0;

	ifstream in;

	Brush* brushs[2];
	brushs[0]=brushs[1]=0;
	list<Window*> rows;
	Label* nick=0,*points=0;
	Window* row=0;

	try
	{
		bkg=Util::loadImage("images/bkg_highscores.png");

		SDL_Color c1={230,230,230,0};
		lb_totexcl_=new Label(0,0,1,"fonts/vera.ttf",12,c1,tge::Label::BLENDED);
		lb_totexcl_->setText("www.totex.cl");

		SDL_Color c2={110,150,230,0};
		lb_title_=new Label(0,0,1,"fonts/polosemi.ttf",40,c2,tge::Label::BLENDED);
		lb_title_->setText("Mejores Puntajes");

		in.open(getHomeFile("high_scores").c_str(),std::ios::binary);
		if(!in.is_open())
			throw runtime_error("no se pudo abrir archivo \"high_scores\"");
		list<HighScore> high_scores;
		while(in.good())
		{
			HighScore hs;
			hs.readFrom(in);
			if(!in.eof())
				high_scores.push_back(hs);
		}
		in.close();

		SDL_Color cr0={27,27,105,0},cr1={92,92,191,0};
		brushs[0]=new Brush(cr0);
		brushs[1]=new Brush(cr1);
		list<HighScore>::iterator i;
		int c=0,row_y=HS_ROW_Y0;
		ostringstream ostr;
		for(i=high_scores.begin();i!=high_scores.end();i++,c++)
		{
			nick=new Label(HS_ROW_MARGIN_X,HS_ROW_MARGIN_Y,1,"fonts/vera.ttf",16,c1,tge::Label::BLENDED);
			points=new Label(0,HS_ROW_MARGIN_Y,1,"fonts/vera.ttf",16,c1,tge::Label::BLENDED);
			nick->setText((*i).getNick());
			ostr<<(*i).getPoints();
			points->setText(ostr.str());
			ostr.str("");
			row=new Window(HS_ROW_X,row_y,getWidth()-2*HS_ROW_X,2*HS_ROW_MARGIN_Y+nick->getHeight(),1);
			row_y+=row->getHeight();
			row->setBackground(*brushs[c%2]);
			row->setBackgroundAlpha(100);
			row->addWidget(nick);
			row->addWidget(points);
			points->setX(row->getWidth()-points->getWidth()-HS_ROW_MARGIN_X);
			rows.push_back(row);
			nick=points=0;
			row=0;
		}
		delete brushs[0];
		delete brushs[1];
	}
	catch(const exception& ex)
	{
		if(bkg)
			SDL_FreeSurface(bkg);
		if(lb_totexcl_)
			delete lb_totexcl_;
		if(lb_title_)
			delete lb_title_;

		if(in.is_open())
			in.close();

		if(nick)
			delete nick;
		if(points)
			delete points;
		if(row)
			delete row;

		if(brushs[0])
			delete brushs[0];
		if(brushs[1])
			delete brushs[1];

		list<Window*>::iterator i;
		for(i=rows.begin();i!=rows.end();i++)
			delete *i;

		throw runtime_error(string("HighScoresScreen::HighScoresScreen(...): ")+ex.what());
	}

	setBackground(bkg);

	lb_totexcl_->setX(5);
	lb_totexcl_->setY(getHeight()-lb_totexcl_->getHeight()-3);
	addWidget(lb_totexcl_);
	lb_title_->setX((getWidth()-lb_title_->getWidth())/2);
	lb_title_->setY(10);
	addWidget(lb_title_);

	list<Window*>::iterator i;
	for(i=rows.begin();i!=rows.end();i++)
		addWidget(*i);
}
Beispiel #11
0
Screen* GameScreen::processEvents(bool& quit)
{
	if(confirm_exit_)
	{
		ConfirmDialog::ActionCode code=confirm_exit_->processEvents();
		switch(code)
		{
			case ConfirmDialog::YES:
				if(confirm_exit_->getFlags())
				{
					quit=true;
					return 0;
				}
				else
					return new MenuScreen(getSDLScreen());
			case ConfirmDialog::NO:
				refreshRect(confirm_exit_->getRect());
				removeWidget(confirm_exit_);
				delete confirm_exit_;
				confirm_exit_=0;
				return 0;
			case ConfirmDialog::NOTHING:
				return 0;
		}
	}
	else if(pause_)
	{
		if(pause_->processEvents())
		{
			refreshRect(pause_->getRect());
			removeWidget(pause_);
			delete pause_;
			pause_=0;
		}
		return 0;
	}
	else if(dlg_nick_)
	{
		InputDialog::ActionCode code=dlg_nick_->processEvents();
		switch(code)
		{
			case InputDialog::OK:
				if(!Util::trim(dlg_nick_->getText()).size())
					return 0;
				else
				{
					fstream file;
					try
					{
						file.open(getHomeFile("high_scores").c_str(),std::ios::binary|std::ios::in);
						if(!file.is_open())
							throw runtime_error("no se pudo abrir archivo \"high_scores\"");

						list<HighScore> high_scores;
						while(file.good())
						{
							HighScore hs;
							hs.readFrom(file);
							if(!file.eof())
								high_scores.push_back(hs);
						}
						file.clear();
						file.close();

						HighScore hs(Util::trim(dlg_nick_->getText()),matrix_->getPoints());
						high_scores.push_back(hs);
						high_scores.sort();

						file.open(getHomeFile("high_scores").c_str(),std::ios::binary|std::ios::out);
						if(!file.is_open())
							throw runtime_error("no se pudo abrir archivo \"high_scores\"");
						list<HighScore>::reverse_iterator i;
						int c=0;
						for(i=high_scores.rbegin();i!=high_scores.rend() && c<HS_NUM;i++,c++)
							(*i).writeTo(file);
						file.close();
					}
					catch(const exception& ex)
					{
						if(file.is_open())
							file.close();
						throw runtime_error(string("GameScreen::processEvents(...): ")+ex.what());
					}
					return new HighScoresScreen(getSDLScreen());
				}
			case InputDialog::CANCEL:
				refreshRect(dlg_nick_->getRect());
				removeWidget(dlg_nick_);
				delete dlg_nick_;
				dlg_nick_=0;
				return 0;
			case InputDialog::NOTHING:
				return 0;
		}
	}

	SDL_Event event;
	while(SDL_PollEvent(&event))
		if(event.type==SDL_KEYDOWN)
		{
			switch(event.key.keysym.sym)
			{
				case SDLK_ESCAPE:
					try
					{
						if(game_over_)
							return new MenuScreen(getSDLScreen());
						else
						{
							confirmExit(0);
							return 0;
						}
					}
					catch(const exception& ex)
					{
						throw runtime_error(string("GameScreen::processEvents(...): ")+ex.what());
					}
				case SDLK_PAUSE:
					try
					{
						if(!game_over_)
						{
							pause();
							return 0;
						}
					}
					catch(const exception& ex)
					{
						throw runtime_error(string("GameScreen::processEvents(...): ")+ex.what());
					}
				default:
					if(matrix_ && !matrix_->isDead())
						matrix_->key(event.key.keysym.sym);
					break;
			}
		}
		else if(event.type==SDL_QUIT)
			confirmExit(1);
	return 0;
}
Beispiel #12
0
void GameScreen::ticks(int t)
{
	if(game_over_)
		game_over_->ticks(t);
	if(confirm_exit_)
	{
		confirm_exit_->ticks(t);
		return;
	}
	else if(pause_)
	{
		pause_->ticks(t);
		return;
	}
	else if(dlg_nick_)
	{
		dlg_nick_->ticks(t);
		return;
	}
	else if(matrix_)
	{
		if(state_==PLAYING)
		{
			matrix_->ticks(t);
			if(matrix_->isDead())
			{
				state_=GAMEOVER;

				vector<SDL_Surface*>* surfaces=new vector<SDL_Surface*>();
				try
				{
					surfaces->reserve(6);
					ostringstream ostr;
					for(int i=0;i<6;i++)
					{
						ostr<<"images/gameover"<<i<<".png";
						SDL_Surface* tmp=Util::loadImage(ostr.str(),true);
						surfaces->push_back(tmp);
						ostr.str("");
					}

					int w=surfaces->at(0)->w;
					int h=surfaces->at(0)->h;
					Rapidity rapidity(1,5);
					game_over_=new Animation((getWidth()-w)/2,(getHeight()-h)/2,w,h
									,1,Animation::LIFO ,surfaces,rapidity);
					addWidget(game_over_);
				}
				catch(const exception& ex)
				{
					vector<SDL_Surface*>::iterator i;
					for(i=surfaces->begin();i!=surfaces->end();i++)
						SDL_FreeSurface(*i);
					throw runtime_error(string("GameScreen::ticks(...): ")+ex.what());
				}

				ifstream in;
				try
				{
					in.open(getHomeFile("high_scores").c_str(),std::ios::binary);
					if(!in.is_open())
						throw runtime_error("no se pudo abrir archivo \"high_scores\"");

					list<HighScore> high_scores;
					while(in.good())
					{
						HighScore hs;
						hs.readFrom(in);
						if(!in.eof())
							high_scores.push_back(hs);
					}
					in.close();

					if(matrix_->getPoints() && (high_scores.size()<HS_NUM ||
							(*high_scores.rbegin()).getPoints()<matrix_->getPoints()))
						getNick();
				}
				catch(const exception& ex)
				{
					if(in.is_open())
						in.close();
					throw runtime_error(string("GameScreen::ticks(...): ")+ex.what());
				}

			}
		}
		try
		{
			ostringstream ostr;
			ostr<<"Nivel "<<matrix_->getLevel();
			lb_level_->setText(ostr.str());
			ostr.str("");
			ostr<<matrix_->getPoints()<<" pts";
			lb_points_->setText(ostr.str());

			if(!matrix_->isDead())
			{
				SDL_Surface* srf=matrix_->getNextPiece();
				next_piece_->setSurface(srf);
				next_piece_->setPosition(PANEL_X+(PANEL_W-srf->w)/2
						,PANEL_Y+lb_next_piece_->getY()+lb_next_piece_->getHeight()+5);
			}
		}
		catch(const exception& ex)
		{
			throw runtime_error(string("GameScreen::ticks(...): ")+ex.what());
		}
	}
}
Beispiel #13
0
int main(int argc, char** argv){

	initSDL();
	
	const int SCREEN_FPS = 60;
	const int SCREEN_TICK_PER_FRAME = 1000 / SCREEN_FPS;

	// Resource handler
	DataHandler gameDataHandler;

	// Load assets
	SDL_Texture* title = nullptr;
	title = LoadImage("data\\title.png");
	


	// Game variables
	bool quit = false;
	int gameState = 0;
	
	// Game classes
	rendererClass gameRenderer;
	KeyboardHandler keyboard;
	HighScore highscore;

	// FPS capper
	Timer frameTimer;
	Timer capTimer;
	int countedFrames = 0;

	// Start counting frames since game start
	frameTimer.Start();

	// Notification text object
	std::stringstream notificationText;
	textClass notification;
	notification.x = 180;
	notification.y = 120;

	//Debug
	std::stringstream teksti;
	textClass debugtext;
	debugtext.x = 200;
	debugtext.y = 200;


	// end debug
	Level level1;
	level1.loadLevel("data\\test.dat");

	
	highscore.readHighScoreFile("data\\score.dat");


	while(keyboard.quitPressed == false && quit == false) {	
		
		// Start counting frames since gameloop start
		capTimer.Start();

		// Clear screen
		clearScreen();


		// Check gamestates
		switch (gameState)
		{
			// Title screen
			case 0:
				ApplySurface( 20, 50, title);

				// Check if the user presses Enter to start a game
				if(keyboard.isPressed(SDL_SCANCODE_RETURN)) {
					gameState = 1;
				}
				break;
			// Start new game
			case 1: 
			{
				// Start level
				level1.initLevel();
				
				gameState = 2;
				break;
			}
			// Start game
			case 2:
			{
				
				if (!level1.playLevel(gameRenderer)) {
					if (level1.levelCompleted == true) {
						gameState = 4;
					}
					else {
						gameState = 3;
					}
				}

				break;
			}
			// Death screen
			case 3:

				// Set you are dead text
				notificationText.str("");
				notificationText << "You are dead! Play again? ( Y / N )";
				notification.setMessage(notificationText);
				notification.drawObject();
				highscore.displayHighScore();

				if(keyboard.isPressed(SDL_SCANCODE_Y)) {
					gameState = 1;
				}
				else if (keyboard.isPressed(SDL_SCANCODE_N)) {
					quit = true;
				}

				break;
			// Level1  complete
			case 4:
				notificationText.str("");
				notificationText << "Level complete! Press enter for level 2 ";
				notification.setMessage(notificationText);
				notification.drawObject();

				if(keyboard.isPressed(SDL_SCANCODE_RETURN)) {
					gameState = 5;
				}
				else if (keyboard.isPressed(SDL_SCANCODE_N)) {
					quit = true;
				}
			// Level 2
			case 5:
				break;
			// Level 2 complete
			case 6:
				break;
			// Level 3
			case 7:
				break;
			// Game complete
			case 8:
				break;

			default:
				break;
		}
		
		//Calculate and correct fps
		float avgFPS = countedFrames / ( frameTimer.getTicks() / 1000.f );
		if( avgFPS > 2000000 )
		{
			avgFPS = 0;
		}
		
		// Handle keyboard for player
		keyboard.handleKeyboardEvents(*level1.playerObject, gameRenderer);

		// Draw all the gameObjects
		gameRenderer.drawRenderQueue();

		// Handle game logic
		gameRenderer.handleLogicQueue();
		
		// Update screen
		updateScreen();
		

		// Add a counted frame
		++countedFrames;

		//If frame finished early
		int frameTicks = capTimer.getTicks();
		if( frameTicks < SCREEN_TICK_PER_FRAME )
		{
			//Wait remaining time
			SDL_Delay( SCREEN_TICK_PER_FRAME - frameTicks );
		}

	}

	// Quit SDL
    SDL_Quit();
 
    return 0;
}
Beispiel #14
0
void unitTests() {

    HighScore scores;
    scores.addScore("Robert", 10);
    scores.addScore("Phillip", 30);
    scores.addScore("Michael", 20);
    Score* s = scores.getScores().at(0);

    assert(s->getName() == "Phillip");
    scores.addScore("Rebecca", 5);
    s = scores.getScores().back();
    assert(s->getName() == "Rebecca");
    scores.save();

    HighScore testScores;
    testScores.load();
    testScores.addScore("Rhonda", 65);
    s = testScores.getScores().at(0);

    assert(s->getName() == "Rhonda");
    assert(s->getScore() == 65);
    testScores.save();
    remove ("highscores.txt");

    //model test for starting a new game.
    Model::instance()->singleGameStart("easy", false);
    assert(Model::instance()->getById(0) != NULL);

    assert(Model::instance()->load());
}