Hello!
Immediately I will ask for an apology for the style of my writing and ignorance of the Russian language - unfortunately I have never been a blog writer, but the desire to leave comments on Habré is a strong motivator. Besides the fact that I am not a writer, I am also not a programmer, but a civil engineer who sometimes indulges in writing a couple of lines of code — such is a hobby among others. But about the construction I wrote enough at the time of preparation and protection of the disser, and there is no more desire to return to it.
And in this article I want to describe the personal experience of creating a single toy with the implementation of a multiplayer game that allows you to support various platforms (I write on .NET, so first of all my experience concerns Windows / WP, but this method is perfect for other platforms, I have working prototypes of the described game for Android / iOS, but so far there is no desire to pay for 1k usd for commercial packages Xamarin). And yes - in this introductory article (which was originally planned exclusively in the sandbox) I will not disclose technical details, since in this case I’m risking not finishing it for a long time. Who knows, maybe I still have time and the opportunity to write a more detailed sequel.
First, a little history. It all started back in 2005 (4 ?, 6?), When I, in the company of my wife's friends, played knuffel, a dice game that I liked so much that I wanted to make my own computer implementation without fail. In those days, I knew VB.NET quite well and took my first steps in C #, so the first version was ready the next day.
"Knifel" - the first versionOf course, I understood that this was a “silent horror” and therefore I continued to improve myself and went to read smart books. In
one of them, I got the idea of ​​a dice controller, which formed the basis of all my subsequent knippels. I remember that the second version of the game was very successful at my work for some time - it happened that they even lingered to throw computer bones. That Windows Forms game has long been abandoned, and I don’t even know where the source code is, but it is still available for download on some sites.
')
"Kniffel" - the second versionThe story continued in 2010 when, having mastered Silverlight, I decided to make an application for VKontakte from the “Kliffel”. But, of course, playing on the same network on one computer is not an option, then for the first time I was faced with the need to implement a network game. The main problem is that the standard http request-response scheme is not applicable here, since the server needs to inform several clients about the game status. Fortunately, in Silverlight for solving this task there is an option almost out of the box and it is called Duplex WCF service. Having implemented client-server communications through a duplex service, I got a fairly stable game, but only for a while ...
"Knifel" - the third version, online game vkontakteThe weak point of the system was the server part, which I placed on a shared hosting, where my website had access to something around 5% of the CPU time of the weakest processor. Many people liked the game and gained some popularity, and with it the number of users simultaneously online has increased. The server began to simply reset the session, the game began to end, hang. It became impossible to play. Then I did not know how to solve this problem and therefore I decided to just “score” ...
Well, last year, I finally “flew into the clouds”. While doing several projects using AWS and Windows Azure, I thought that this could be a great solution for reanimation of a book store.
At about the same time, my wife became the owner of the Windows Phone phone, and I became “delighted with him”. I really liked the whole concept of the system, so I bought the Windows background for myself and started porting the book on it, and on Windows 8 at the same time - the benefit is the same Silverlight in WP, and XAML / # in WinRT too. So using MVVM pattern and relatively small effort, I got three applications - for Windows Phone, Windows 8 and (rewrote) Silverlight. In applications, 95% of the code is in common cs files with # ifan specific points. It is very convenient for unit testing and support - it is enough to change something in just one project and just make sure that everything works. The problem remained only in the network game - it was impossible to use my duplex service on all platforms, especially considering the potential expansion to iOS and Android. The solution I needed was a universal one to fit into my concept of “common code for all platforms”.
Such a solution was found - WebSockets. Web sockets are natively supported by .NET 4.5, so there were no problems with the implementation in the server part and for Windows 8. And for Silverlight and Windows Phone, I found the implementation as an open source library of
WebSocket4Net . The same library is for Monotouch and Mono for Android. C Html / JS is still as simple: I have successfully tested communication with my server from the simplest web page.
Well, the server - in Windows Azure. It all works well - you can perfectly play simultaneously from all supported platforms, there are of course jambs, but how can it be without them ...
"Knifel" (more precisely already "Magical Yatzy") - the current version, a multiplayer game between Windows 8, Windows RT, WP7 and WP8This is the “sandbox” article that turned out to be - largely autobiographical and in some places, possibly stupid ... well, as I can.
Ps. After the publication of the game in the international arena and claims from the German copyright holder, I had to abandon the name “knuffel” and move to a more neutral “international non-proprietary name“ Yatzy ”, this has nothing to do with the matter, but still ...