package br.odb.menu;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import br.odb.knights.GameConfigurations;
import br.odb.knights.GameLevelLoader;
import br.odb.knights.R;

public class KnightsOfAlentejoSplashActivity extends Activity implements
		OnClickListener {

	volatile byte level = 0;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		findViewById(R.id.btStart).setOnClickListener(this);
		findViewById(R.id.btnCredits).setOnClickListener(this);
		findViewById(R.id.btnHowToPlay).setOnClickListener(this);

	}

	@Override
	public void onClick(View v) {

		switch (v.getId()) {
		case R.id.btStart:
			playNextLevel();
			break;
		case R.id.btnCredits:
			showCredits();
			break;
		case R.id.btnHowToPlay:
			showHowToPlay();
			break;
		}
	}

	private void showHowToPlay() {
		Intent intent = new Intent(this, ShowHowToPlayActivity.class);
		startActivity(intent);
	}

	private void showCredits() {
		Intent intent = new Intent(this, ShowCreditsActivity.class);
		startActivity(intent);
	}

	public void playNextLevel() {
		GameConfigurations.getInstance().startNewSession();
		Intent intent = new Intent(getBaseContext(), GameActivity.class);
		intent.putExtra("level", level);
		startActivityForResult(intent, 1);
	}

	protected void onActivityResult(int requestCode, int resultCode, Intent data) {

		if (requestCode == 1 && data != null ) {
			
			int good = data.getIntExtra( "good", 0 );

			
			if ( good == 1 ) {
				
				++level;
				Log.d( "alentejo", "Now, playing level " + level );
				
				if (level > GameLevelLoader.LIMIT) {
					showGameEnding();
				} else {
					playNextLevel();
				}
			} else if ( good == 2 ) {
				level = 0;
				showGameOver();
			}
		} else {
			level = 0;
		}

	}

	private void showGameOver() {
		Intent intent = new Intent(this, ShowOutcomeActivity.class);
		intent.putExtra("good", false);
		this.startActivity(intent);
	}

	private void showGameEnding() {
		Intent intent = new Intent(this, ShowOutcomeActivity.class);
		intent.putExtra("good", true);
		this.startActivity(intent);
	}
}
@@ -395,16 +395,81 @@
 ener %7B%0A%0A
+%09public static final String SUCCESFUL_LEVEL_COMPLETION = %22good%22;%0A
 %09volatil
@@ -1719,23 +1719,42 @@
 ntExtra(
- %22good%22
+SUCCESFUL_LEVEL_COMPLETION
 , 0 );%0A%0A
@@ -1801,68 +1801,8 @@
 el;%0A
-%09%09%09%09Log.d( %22alentejo%22, %22Now, playing level %22 + level );%0A%09%09%09%09
 %0A%09%09%09
@@ -2118,22 +2118,42 @@
 utExtra(
-%22good%22
+SUCCESFUL_LEVEL_COMPLETION
 , false)
@@ -2302,22 +2302,42 @@
 utExtra(
-%22good%22
+SUCCESFUL_LEVEL_COMPLETION
 , true);

Refactor on the literal used to represent a succesful level completion