tag:blogger.com,1999:blog-282813109824903902024-03-06T06:39:15.502+01:00Code CraftsProgramming tools and techniques. Game development ideas.Anonymoushttp://www.blogger.com/profile/02065941173640249899noreply@blogger.comBlogger4125tag:blogger.com,1999:blog-28281310982490390.post-62419670807194240382013-06-23T19:02:00.000+02:002013-06-29T11:54:26.851+02:00Build a desktop online translator with Bing<h4>
<span style="font-size: large;">Introduction</span></h4>
<br />
Somebody on <a href="http://www.codeacademy.com/" target="_blank">Codeacademy</a> wanted a little help building a dictionary application for Windows 8. As a matter of fact, online dictionary/translator function in similar ways. Since I already worked on such functionality, I thought I would try to do it again, let's go!<br />
<br />
<h4>
<span style="font-size: large;">
1. Check online translation services</span></h4>
<div>
<br />
Nowadays, all online translation services seem to require a key for API use. Since Google Translate became paid only, Bing seems the best free option at the moment.<br />
<br /></div>
<div>
<h4>
<span style="font-size: large;">2. How the BING Translator API works...</span></h4>
<br />
It's much more difficult <a href="http://gtranslate.net/forum/microsoft-translator-api-service-announcement-for-bing-appid-t1964.html" target="_blank">now that appID no longer works</a>.<br />
<br />
Resources:</div>
<div>
<div>
<br />
<ol>
<li>Wang Pidong's blog: <a href="http://wangpidong.blogspot.fr/2012/04/how-to-use-new-bing-translator-api-with.html" target="_blank">How to use new Bing translator API</a>.</li>
<li>MSDN blog: <a href="http://blogs.msdn.com/b/translation/p/gettingstarted1.aspx" target="_blank">Bing Translator API, getting started</a>.</li>
<li>MSDN Microsoft Translator: <a href="http://msdn.microsoft.com/en-us/library/hh454950.aspx" target="_blank">Obtaining an access token</a>.</li>
<li>MSDN documentation on the protocol: <a href="http://msdn.microsoft.com/en-us/library/ff512387.aspx" target="_blank">HTTP interface in C#</a></li>
<li>Microsoft Bing Translator Language Codes and Names: <a href="http://www.emreakkas.com/internationalization/microsoft-translator-api-languages-list-language-codes-and-names" target="_blank">[1]</a>, <a href="http://msdn.microsoft.com/en-us/library/hh456380.aspx" target="_blank">[2]</a>.</li>
</ol>
</div>
<div>
</div>
</div>
<div>
Basically you want to copy the C# code from steps 3 & 4, to create classes and functions that will handle the http stuff and deserialisation (JSON and raw string) for you.<br />
<br />
Since we're using the WPF template for the project, you will probably need to add references to:<br />
<br />
<ul>
<li>System.Configuration</li>
<li>System.Runtime.Serialization</li>
<li>System.Net</li>
<li>System.Web</li>
</ul>
<div>
<br /></div>
<h4>
<span style="font-size: large;">3. Verify the registration process</span></h4>
<div>
<br /></div>
<div>
The registration process for the service is a bit painful. You must have something like this in your Azure Marketplace account for it to work : </div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjuBSg199XISByrvfzeSzvjDKErhIS_3AT4d-v4XhyphenhyphenbbHRZcPJDE6Hsi_XeZHAKJmP7-CeSAOzqAN2-4gm5S-FzV_xG88bpfB8zCZUisckWSTpWUQKjW3_S1qZoTamlFgS0UubWg7frWQY/s1600/Windows+Azure+Marketplace.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="Windows Azure Marketplace data" border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjuBSg199XISByrvfzeSzvjDKErhIS_3AT4d-v4XhyphenhyphenbbHRZcPJDE6Hsi_XeZHAKJmP7-CeSAOzqAN2-4gm5S-FzV_xG88bpfB8zCZUisckWSTpWUQKjW3_S1qZoTamlFgS0UubWg7frWQY/s1600/Windows+Azure+Marketplace.png" height="252" title="" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
Notice the two rows for both Bing Search API & Microsoft Translator.</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
</div>
<h4>
<span style="font-size: large;">4. Build a WPF interface</span></h4>
<div>
<br />
If we want to get fancy we can create to ComboBox controls databounds to the languages lists (checks links in section 2.5).<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg5-r12D8E3c7TvDRx_QXxLb62hsNXLwTSpGFjDBQs9yMWJOdGZcdPLB3J-ofBeMi1HAe2AIU25fTxSYvd0-obGPwmEW8bD85zizm-UuG1zzBqpPBHSAb8Kdepf1h4jnRuvaJaCojmUEVA/s1600/WPFOnlineTranslator.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="WPF interface" border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg5-r12D8E3c7TvDRx_QXxLb62hsNXLwTSpGFjDBQs9yMWJOdGZcdPLB3J-ofBeMi1HAe2AIU25fTxSYvd0-obGPwmEW8bD85zizm-UuG1zzBqpPBHSAb8Kdepf1h4jnRuvaJaCojmUEVA/s1600/WPFOnlineTranslator.png" height="64" title="" width="320" /></a></div>
<br />
<br /></div>
<h4>
<span style="font-size: large;">5. Implement custom configuration</span></h4>
<div>
<br />
Obviously, I can't give out my personal Bing keys. You will have to fill both the ClienID and the ClientSecret in exe.config.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://blogs.msdn.com/cfs-filesystemfile.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-91-16-metablogapi/6567.clip_5F00_image014_5F00_24729FC4.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="Windows Azure Marketplace application registration" border="0" src="http://blogs.msdn.com/cfs-filesystemfile.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-91-16-metablogapi/6567.clip_5F00_image014_5F00_24729FC4.png" height="212" title="" width="320" /></a></div>
<br /></div>
<div>
<h4>
<span style="font-size: large;">Conclusion</span></h4>
<br />
You will find the sample application at <a href="https://docs.google.com/file/d/0B00MGoM14sU9YWhSQnFsUk5RUUk/edit?usp=sharing" target="_blank">WPFOnlineTranslator</a>. You can also download the <a href="http://www.codeproject.com/script/Articles/ViewDownloads.aspx?aid=612002" target="_blank">source code</a> on <a href="http://www.codeproject.com/" target="_blank">the code project</a>. Have fun! =)</div>
Anonymoushttp://www.blogger.com/profile/02065941173640249899noreply@blogger.com0tag:blogger.com,1999:blog-28281310982490390.post-66914370585754128352013-06-23T11:20:00.000+02:002013-06-26T10:23:56.557+02:00Retrieve contacts with Google Contacts API (Python)I recently registered an account on <a href="http://www.codecademy.com/" target="_blank">codecademy</a>. It was so fun that I completed all Python courses in one day! They also have a course for Python API which I also completed.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEie59q2ei82QyZNlcbyWESJ0QrmsSGOVkLKF5i0v-hKz4dkhUKDK2pPiAIoOJ8V-ifcaXKHn4jZsi9MZzCViB8OrwLQ7odT9Mdho4LH_fWJpphZ9cBPa1iPrVj1349oHbq6F2HtBDKbXdU/s1600/codeacademy.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="Codeacademy badges" border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEie59q2ei82QyZNlcbyWESJ0QrmsSGOVkLKF5i0v-hKz4dkhUKDK2pPiAIoOJ8V-ifcaXKHn4jZsi9MZzCViB8OrwLQ7odT9Mdho4LH_fWJpphZ9cBPa1iPrVj1349oHbq6F2HtBDKbXdU/s1600/codeacademy.png" height="170" title="" width="320" /></a></div>
<br />
As an experiment, I thought of trying to retrieve contacts using GMail API. It was really easy. Here are the steps and requirements:<br />
<ol>
<li><a href="http://www.python.org/getit/" target="_blank">Python 2.7</a> installation</li>
<li>Google Data Python Library installation (run setup.py install) from <a href="https://developers.google.com/gdata/articles/python_client_lib" target="_blank">https://developers.google.com/gdata/articles/python_client_lib</a></li>
<li>Download <a href="https://gdata-python-client.googlecode.com/hg/samples/contacts/contacts_example.py">contacts_example.py</a> from <a href="https://developers.google.com/google-apps/contacts/v3/" target="_blank">Contacts API v3</a></li>
<li>Create test account on GMail</li>
<li>Run contacts_example.py. You will be prompted for username and password.</li>
</ol>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgJ3ippf4am1wv-CAW7lepYeXAwYZc-0JoG_ChqHP2dYH5iBpyFe2ejrTAiII34Eq8q8R3w5g6ZN1AuS2LgTs_BLwhDcPlmwEyrVcLCzOB0tClqlp8cbUeSwW1SK1x16mLrOzRpJz8W_-k/s1600/contacts_example.py.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="contacts_examples.py" border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgJ3ippf4am1wv-CAW7lepYeXAwYZc-0JoG_ChqHP2dYH5iBpyFe2ejrTAiII34Eq8q8R3w5g6ZN1AuS2LgTs_BLwhDcPlmwEyrVcLCzOB0tClqlp8cbUeSwW1SK1x16mLrOzRpJz8W_-k/s1600/contacts_example.py.png" height="214" title="" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
As a last step you wil want to customize the script to fit your needs. Have fun!</div>
<div>
<br /></div>
Anonymoushttp://www.blogger.com/profile/02065941173640249899noreply@blogger.com0tag:blogger.com,1999:blog-28281310982490390.post-37714603134061325082013-06-21T08:16:00.000+02:002013-06-21T09:30:54.723+02:00Grandia's initiative bar<div class="separator" style="clear: both; text-align: center;">
<span style="font-size: large;">The inspiration</span></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://assets2.ignimgs.com/2002/03/09/grandia2_030802_032-372396_640w.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://assets2.ignimgs.com/2002/03/09/grandia2_030802_032-372396_640w.jpg" height="300" width="400" /></a></div>
<br />
For a game idea I had in mind for a very long time, I wanted to use the battle system of the Grandia series.<br />
In the picture above you can see in the bottom right, what is called the IP Bar. Basically, there are 3 phases : WAIT, COM, ACT. Each character (player or computer):<br />
<br />
<ul>
<li>enters the wait phase</li>
<li>selects a command from combo / critical / special move or magic / defend / evade / flee</li>
<li>performs the selected action</li>
</ul>
<div>
What is really beautiful about this system is that it's the best compromise between real-time anc turn-based game mechanics. All actions are performed live, but there is a stop to enter your command. This means you have time to plan your actions. But for what purpose ? Here are the cool things you can do:</div>
<div>
<ul>
<li>Normal attacks (combo) results in a small knockback. Initiative is frozen until the character recovers from the hit. This also means that if attacked by many characters at once, not only the damage can add up, but the target is momentarily disabled.</li>
<li>Cancel an enemy's command by performing a critical attack during the buildup of its action phase.</li>
<li>Counter, if your critical lands as the target is in execution (end of action phase). Counters often results in knockdowns, which put the target on the ground. Nothing they can do until they get up!</li>
</ul>
<div>
Overall, I think the amount of control you have during the fight (if you play it smart), makes any battle really fun. The developers also did something for lazy dudes: you can define a combat strategy for the team, and just watch the AI do the job (handy versus weak enemies).</div>
</div>
<div>
<br /></div>
<div>
Additional information: <a href="http://uk.ign.com/wikis/grandia-ii">Grandia II on IGN</a></div>
<div>
<br /></div>
<div>
<br /></div>
<div style="text-align: center;">
<span style="font-size: large;">The implementation</span></div>
<div>
<br /></div>
<div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEghhfdWeG_Q6_4nVTNDh03iylM9SzQQWGETsvyNCPrCBTc-Kn08nHY_Gq4gsabQFLl0tHVqoBfNz2fAfoab9ye0VgW8_63T9Jvk2c3ZrYaKuU-KMQGuXcGi86hzLJRP6HiRFucl17j3taI/s1600/InitiativeBar.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEghhfdWeG_Q6_4nVTNDh03iylM9SzQQWGETsvyNCPrCBTc-Kn08nHY_Gq4gsabQFLl0tHVqoBfNz2fAfoab9ye0VgW8_63T9Jvk2c3ZrYaKuU-KMQGuXcGi86hzLJRP6HiRFucl17j3taI/s1600/InitiativeBar.png" height="99" width="320" /></a></div>
<br />
Using C# and WPF, i developed an animated initiative bar control. <a href="https://docs.google.com/file/d/0B00MGoM14sU9YUZsek0tSnU5X3c/edit?usp=sharing">InitiativeBar.zip</a></div>
Anonymoushttp://www.blogger.com/profile/02065941173640249899noreply@blogger.com0tag:blogger.com,1999:blog-28281310982490390.post-23421319901152219022013-06-19T07:30:00.002+02:002013-06-21T08:17:47.537+02:00Mastermind in C#<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhd2DxWQsQ8qnwSCNE5xd251LOKe5WpDwwJPJrdOzYdwo_Sb_YFqPxRJjR7-zBfIS2TGHufW-yK9Hzi1ZtX8PqlM9QNOj-LxFIP88SzUd5BNMWPI9Jg4sqQ9uWvYC-a03wmUD4XU6XpVrA/s1600/Mastermind.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhd2DxWQsQ8qnwSCNE5xd251LOKe5WpDwwJPJrdOzYdwo_Sb_YFqPxRJjR7-zBfIS2TGHufW-yK9Hzi1ZtX8PqlM9QNOj-LxFIP88SzUd5BNMWPI9Jg4sqQ9uWvYC-a03wmUD4XU6XpVrA/s1600/Mastermind.png" height="320" width="210" /></a></div>
<br />
<br />
I thought, as a small project, it would be interesting to implement this game. I always had a lot of fun playing it as a child. It took only one day of development, for the first post on this blog. Enjoy!<br />
<br />
Informations about the game : <a href="http://en.wikipedia.org/wiki/Mastermind_(board_game)">Mastermind (board game)</a><br />
Compiled binaries (Windows, .NET Framework) : <a href="https://docs.google.com/file/d/0B00MGoM14sU9VmxacmlUTkJZb1k/edit?usp=sharing" target="_blank">Mastermind.zip</a><br />
<div>
<br /></div>
<div>
Ideas to make it more fun or challenging :</div>
<div>
<ul>
<li>High scores (based on timer and number of tries)</li>
<li>Multi-player mode (with tournaments)</li>
<li>AI personalities</li>
<li>Tutorial</li>
</ul>
<div>
Exploration: this is a game of imperfect information. I already wrote a chess AI. I don't know yet what it would be like to create one to break the code as fast as possible. But it could be fun, I'll try later!</div>
</div>
Anonymoushttp://www.blogger.com/profile/02065941173640249899noreply@blogger.com0