Sekagra – A Programming Blog
24Apr/121

Getting Started with Android Development

I managed to get a used HTC HD2 a while ago. As I only got it in order to play around with Android development, it still is a very good smartphone. You may wonder I mention the HD2 in conjuction with Android, because it is originally a Windows Phone. However, it is capable of running many different operating systems due to mods, which made it very popular among custom ROM developers. Therefore, there is a fair amount of frequently updated Android NAND ROMs available.

The most straight forward way to develop on Android is definitely Java. Although there is Mono for Android to make it easier for .NET developers like me, I am fine with using Java. A simple step-by-step guide on how to setup Eclipse, Java and the Android SDK can be found on the official Android website here.

For my first two Apps I rebuild two of my Perl scripts: the Binary Clock and the Subnet Calculator.

 

 

 

 

 

 

 

 

 

The rewritten code in Java stayed roughly the same as in Perl, with some minor improvements, that were possible because of what Java offers in terms of object-oriented programming.

21Feb/120

An object-oriented approach to Pac-Man

A few weeks ago I was trying to find a small sample application to display object-orientation and its principles. My goal was to find something suitable for people that haven't started programming long ago and are still used to solve problems the imperative way. (It was meant to be used for our trainees at work.)

However, I was unable to find proper solutions for my specific case, so I ended up writing my own application: An object-oriented Pac-Man implementation, using C# and WPF.

I tried to combine everything of the basic object-oriented stuff like inheritance, polymorphism, encapsulation as well as additional C# specific techniques in it. Besides that, I commented as hard as possible and kept everything that seemed unimportant out, so that the program has only about 200 lines of code.

Here is an overview over all classes and methods:

2Jan/120

Choi Sooyoung >.<

Tagged as: , No Comments
7Dec/110

Playing embedded audio files in WPF

When writing my little Tetris clone, I had to implement a way of playing audio files. To achieve a task like this you can make use of the two classes System.Media.SoundPlayer and System.Windows.Media.MediaPlayer. Depending on your scenario, either class can be preverable, however the MediaPlayer is newer and (as the namespace indicates) available in WPF.

I won't list the exact the differences of both, but the SoundPlayer was impossible for me to use, as it cannot play more than one file simultaneously, even with multiple instances. In addition to that, it seems you can't play .mp3 files with it, too.

So to use the MediaPlayer class, all you have to do is open up an audio file and start playing it like this:

Unfortunately the MediaPlayer class isn't perfect either. You can only play files directly from the file system, not those embedded as a "Resource" in your assembly. In some cases, like my Tetris, you want your final program to be only a single .exe file, because an installation routine seems over the top and shipping a .zip with the sound files just lying around seems messy. So my approach was to create a new MediaPlayer that can take an URI to a resource file and write this to the users temporary directory, before playing it.

27Nov/110

WPF Tetris (Update: Version 1.1)

After getting some experience in WPF due to projects at work and smaller WPF applications I did on my own (e.g. Turing Machine Simulator), I decided to write a Tetris clone. I wanted it to be roughly like the original GameBoy version, not in terms of looks but in terms of mechanics. So I copied elements like the score calculation.

The game saves the top 10 highscores and allows the player to assign custom key settings.

Screenshot of the game itself.

I don't want to dive into the code deeply here, as it is a lot bigger in terms of size as the stuff I released previously. The code may be not as "object-oriented" as it could be, but better than for example the Turing machine. Maybe I'm going to pick some technical details and explain them in a separate post like e.g. the handling of sound effects, as there were some shenanigans around those.

21Nov/110

Turning Machine Simulator

So now I'm done with posting all the old stuff. This one is new and therefore written in C# (Version 4.0). A Turing machine simulator in form of a WPF application. It allows to run programs at different speed levels and create them with a simple editor. Created sequences can be saved in a XML file, so every text editor can edit them.

A few words to the Turing machine in general. It is a theoretical model named after Alan Turing who described it in 1936. Although it is not intended to be a real computing machine, but rather a thought experiment, it can compute every calculation a modern CPU can, nothing more and nothing less.

Its informal definition describes it as a machine that mechanically operates on an endless tape. The tape is divided into cells and the machine's head can read and write one of those at a time. The head can be moved exactly one cell to either the right or left in each step. The machine has a state register which holds the current state the machine is in. A finite set of instructions that are executed one by one (one in each step) changes those states. Every operation is fully determined by a finite set of elementary instructions such as "in state 42, if you read 0, write a 1, shift to the right and change into state 43".

20Nov/110

ClipCursor – Lock your cursor into a window

ClipCursor is a function in the Windows API, which makes it possible to define a rectangle on the monitor and lock the mouse pointer in it.

Originally I came up with the idea to write a program based on this function, for Warcraft III. Like in the most strategy games you navigate over the map by moving the mouse pointer to the very outside of the screen. However, when playing in windowed mode, you would end up constantly move out of the window, so it is necessary to somehow restrict the mouse movement.

When I released it for the first time on my old site as "Warcraft III ClipCursor", you could only use it for that purpose.  Now I have added some new code, so you can define the window you want to clip by yourself.

18Nov/110

Binary clock in Perl

This is the last one of my little Perl-Tk series. A binary clock which, for a better understanding, shows the common decimal time above the binary notation.

It's a 24-hour clock and represents every digit with enabled or disabled squares. For every digit there is only the amount of squares in the corresponding column, that is needed. For example: The digit for ten-hours can either be 0, 1 or 2, therefore two binary digits are enough. The digit for single hours however has to display values between 0 and 9, so a total of four binary digits are needed.Screenshot of the binary clock in Perl.

The complete binary notation for time shown is: 10 0001 : 001 0111 : 010 0101

18Nov/110

Moe Renamer

Another Perl program which is about the same age as my Subnet Calculator and is using Perl-Tk to provide a GUI as well.

The script and its functionality are based on a free-ware renaming tool called Joe (pun intended). You can load multiple files and rename them quick and easy. To create the new file you can use a mask with different patterns like the date, time or a consecutive number.

Like my other Perl scripts you'll need an interpreter to execute this. If you are using Linux, Perl is most likely already part of your system. For Windows users I suggest getting the latest version of ActivePerl (here).

In addition to that you'll need the Tk package, which is available via CPAN.

18Nov/110

Sieve of Atkin

Here is an implementation of the so-called "Sieve of Atkin", an optimized version of the sieve of Eratosthenes. Further information about the algorithm itself can be found on Wikipedia.

I wrote this one in standard C in order to test the raw power of the language. To compile the source code I used MinGW (the Windows version of gcc).