Rat49 / BootCamp

Project made by BootCampers power
4 stars 3 forks source link

Implement 'Top Scores' Leaderboard #34

Open vcutman opened 6 years ago

vcutman commented 6 years ago

PlayFab

Account credentials will be sent directly to the assignees. Leaderboard link: https://developer.playfab.com/en-us/EFAC/leaderboards/VG9wIFNjb3Jlcw%3d%3d Title ID: EFAC Statistic name: Top Scores

Task

Notes

Getting started guide: https://api.playfab.com/docs/getting-started/windows-c-getting-started-guide API Documentation: https://api.playfab.com/documentation/client

Login to PlayFab

PlayFabClientAPI::LoginWithCustomID

Update user display name

PlayFabClientAPI::UpdateUserTitleDisplayName

Upload new score

PlayFabClientAPI::UpdatePlayerStatistics

Get LeaderBoard

PlayFabClientAPI::GetLeaderboard

vcutman commented 6 years ago

Example


#include "playfab/PlayFabClientDataModels.h"
#include "playfab/PlayFabClientApi.h"
#include "playfab/PlayFabSettings.h"
#include <windows.h>

using namespace PlayFab;
using namespace ClientModels;

bool finished = false;
std::list<PlayerLeaderboardEntry> leaderBoard;

void OnLoginSuccess(const LoginResult& result, void* customData)
{
    printf("Logged in\n");
    finished = true;
}

void OnNameUpdateSuccess(const UpdateUserTitleDisplayNameResult& result, void* customData)
{
    printf("User title was updated\n");
    finished = true;
}

void OnPlayerStatisticsUpdateSuccess(const UpdatePlayerStatisticsResult& result, void* customData)
{
    printf("Player statistic was updated\n");
    finished = true;
}

void OnGetLeaderboardSuccess(const GetLeaderboardResult& result, void* customData)
{
    printf("Got leaderboard: %s \n");
    leaderBoard = result.Leaderboard;
    finished = true;
}

void OnFail(const PlayFabError& error, void* customData)
{
    printf("Something went wrong!\n");
    printf("Here's some debug information:\n");
    printf(error.GenerateReport().c_str());
    printf("\n");
    finished = true;
}

int main()
{
    PlayFabSettings::titleId = WidenString("EFAC");

    LoginWithCustomIDRequest request;
    request.CreateAccount = true;
    request.CustomId = "Petrov";
    request.LoginTitlePlayerAccountEntity = 

    finished = false;
    PlayFabClientAPI::LoginWithCustomID(request, OnLoginSuccess, OnFail);
    while (PlayFabClientAPI::Update() != 0)
        Sleep(1);

    UpdateUserTitleDisplayNameRequest updateNameRequest;
    updateNameRequest.DisplayName = "Petrov";

    finished = false;
    PlayFabClientAPI::UpdateUserTitleDisplayName(updateNameRequest, OnNameUpdateSuccess, OnFail);
    while (PlayFabClientAPI::Update() != 0)
        Sleep(1);

    UpdatePlayerStatisticsRequest updatePlayerStatisticRequest;
    StatisticUpdate s;
    s.StatisticName = "Top Scores";
    s.Value = 1000;

    const std::list<StatisticUpdate> statistics = { s };
    updatePlayerStatisticRequest.Statistics = statistics;

    finished = false;
    PlayFabClientAPI::UpdatePlayerStatistics(updatePlayerStatisticRequest, OnPlayerStatisticsUpdateSuccess, OnFail);
    while (PlayFabClientAPI::Update() != 0)
        Sleep(1);

    GetLeaderboardRequest getLeaderBoardRequest;
    getLeaderBoardRequest.StatisticName = "Top Scores";

    PlayFabClientAPI::GetLeaderboard(getLeaderBoardRequest, OnGetLeaderboardSuccess, OnFail);
    while (PlayFabClientAPI::Update() != 0)
        Sleep(1);

    printf("Press enter to exit\n");
    getchar();
    return 0;
}