Home » Posts tagged "Asokoban"

Asokoban screenshoots!

Well, maybe it’s a bit late to post them – after all it’s been a whole month since uploading Asokoban on github, but hey. Better late than never, as they say in my country (:

Duu duuun! Read more


The most challenging part of Asokoban was creating a map to play on.

Now I wonder if it wasn’t an overkill but with experience from WinForms I decided to implement map with a Canvas on a custom View called MapView, because sokoban is a game that does not require much frame-rate speed – map should be redrawed after each move, and time gap between moves varies according to time player spend on thinking. Read more

Common menu in android apps

Little trick, that goes well with DRY rule.
Every activity on android can contain menu defined in onCreateOptionsMenu(Menu menu) and onOptionsItemSelected(MenuItem item) methods. But what to do if we have multiple activities that share the same menu? Copy and paste methods? Better not. API Guides at android developers come with a trick: when multiple activities need to provide the same, common, menu a best way to do it is through inheritance.

In Asokoban I wanted a common menu with “about” and “highscores” options, that would show basic info about program, and highscores activity. And in-game activity menu should also contain a restart option. How?
I created a MenuActivity as a “empty” activity that implemented only methods connected with menu. Standard and one that implements tasks specific for options item. Example:

public class MenuActivity extends Activity {

	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.menu, menu);
		return true;
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case R.id.menu_about:
			return true;
		case R.id.menu_highscores:
			return true;
		return super.onOptionsItemSelected(item);
	private void showAbout(){
		AlertDialog.Builder builder = new AlertDialog.Builder(this);
		AlertDialog dialog = builder.create();
	private void showScores(){
		Intent intent = new Intent(this, HighscoreActivity.class);

Then all that’s left is to extend this class for every activity in program. And – in case of ingame activity with reset function – override onCreate and OnSelected methods with additional menu content. Example:

public boolean onCreateOptionsMenu(Menu menu) {
return true;

That warehouse.

We Interrupt notes about pongoid to proudly present: Asokoban. A simple sokoban clone made for my ‘mobile programming’ at university.
It was first app I ever made for phones with android so code is little messy and it’s clearly far from optimal, but I’m still learning.

For now game contains 2 levels, and simple highscore system made with shared preferences.

I plan to write more about implementation in the next few notes.