Metro Nuggets

Bitesized Windows Phone 7, Windows Phone 8 and Windows 8 tidbits

Introducing the ScoreoidPortable PCL

For a game I’ve been writing the last few weeks, I’ve been using an online scoring system in order to keep a track of people’s best scores whilst playing the game. What I’ve been using is Scoreoid, which is a cross platform scoring platform. It’s actually pretty easy to get yourself set up with Scoreoid, but that’s not the purpose of this post.

Their API is a REST based one and has a pretty expansive list of calls, from player creation, to score creation to leaderboards, etc. Initially, I looked to see whether anyone had already created any kind of helper library for Scoreoid and found Scoreoid for Windows 8 which I had to tweak in order to use it in my Windows Phone game. Unfortunately, the number of methods it had implemented was somewhat limited, I guess Rudy only implemented the ones he needed, so I found I was going to be adding a lot to his existing code base. In the end, I decided I’d write my own version and have the library how I wanted it (naming conventions etc).

So that’s what I did.

The Solution

As with all the libraries I write at the moment, ScoreoidPortable is (as the name suggests) a) Portable, and b) open source (Fork it on GitHub if you’d like).

The library itself also uses the BCL Async bits from Microsoft, including the beta version of the HttpClient that supports automatic decompression. So what does that mean? Well, it means at the moment, this library should be considered a “proof of concept” one as the version of HttpClient I’m using has no Go-Live licence (yet). But hey, I’m no licence enforcer, I can’t know what every person is doing Smile

What about platforms? What platforms does it support? Everything. I try to get as much coverage with my libraries as I can, so this supports .NET 4.0.3+, Silverlight 5 (sorry, not 4), Windows Phone 7.5, Windows Phone 8 and Windows Store apps (not the javascript variety). Which does make this library the one stop shop for Scoreoid in the .NET world.

So, some code:

        private readonly IScoreoidClient _scoreoidClient;
        private const string ScoreoidApiKey = "YOURAPIKEY";
        private const string ScoreoidGameId = "YOURGAMESID";

        // Constructor
        public MainPage()
        {
            InitializeComponent();
            _scoreoidClient = new ScoreoidClient(ScoreoidApiKey, ScoreoidGameId);
        }

That’s it for creating the client, easy, right. If you then wanted to get a list of all the players in your game, you’d do something like this:

        private async Task<List> GetGamePlayers()
        {
            var players = await _scoreoidClient.GetGamePlayersAsync(SortBy.Score);
            return players;
        } 

And voila, done, again. In that example, I’ve included a SortBy option, and there are a number of other filtering options, but they are all optional for that call. What about submitting a score? Is that easy, too? Loaded question Winking smile

        private async Task SubmitScore(int yourScore)
        {
            var score = new Score
            {
                TheScore = yourScore.ToString(),
                Difficulty = 3,
                Platform = "WP8"
            };

            var response = await _scoreoidClient.CreateScoreAsync("scottisafool", score);

            return response;
        }

There. Now, the keen-eyed amongst you will notice that we take the score and turn it into a string. This is due to a known issue with the Scoreoid API that I’m told will be addressed in the next release of the API.

There are plenty of other methods in there for you to get your gamedev teeth into, and hopefully this library will make things much easier for you to create games across many .NET platforms and being able to reuse the same code (well, as much of it as you can).

So where do you get this from? Nuget of course. You can download the code and compile it yourself, I guess, but really, who has the time for that. If you search for it in Visual Studio, please remember to choose “Include pre-release” or you won’t find it, not until the HttpClient package it uses goes RTW.

ScoreoidNuget

SL

About these ads

5 responses to “Introducing the ScoreoidPortable PCL

  1. Pingback: Introducing the ScoreoidPortable PCL

  2. Pingback: Introducing the ScoreoidPortable PCL | Answer My Query

  3. Pingback: Windows Store Developer Links – 2013-07-02 | Dan Rigby

  4. Pingback: Cross-Platform Portable Class Libraries with .NET are Happening - Scott Hanselman

  5. Pingback: .Net 跨平台可移植类库正在进行 - Scott Hanselman的中文博客 - Site Home - MSDN Blogs

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: