Click here to Skip to main content
15,889,842 members
Articles / Mobile Apps / Android

Nim Challenge

Rate me:
Please Sign up or sign in to vote.
5.00/5 (2 votes)
26 Jul 2012Apache7 min read 33.6K   1.2K   15  
Nim game for Android devices
package gr.sullenart.games.nimchallenge;

import gr.sullenart.games.nimchallenge.ads.AdsManager;
import gr.sullenart.games.nimchallengeplus.GameFeatures;
import android.app.Activity;
import android.content.Intent;
import android.graphics.PorterDuff;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;

public class NimGameSelect extends Activity {
	
	private AdsManager adsManager = new AdsManager();
	
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.game_select);

        Button classicButton = (Button) findViewById(R.id.classicButton);
        classicButton.getBackground().setColorFilter(0xF00000FF, PorterDuff.Mode.MULTIPLY);
        Button customButton = (Button) findViewById(R.id.customButton);
        customButton.getBackground().setColorFilter(0xF00000FF, PorterDuff.Mode.MULTIPLY);        
        Button variationsButton = (Button) findViewById(R.id.variationsButton);
        variationsButton.getBackground().setColorFilter(0xF00000FF, PorterDuff.Mode.MULTIPLY);
        Button challenge1Button = (Button) findViewById(R.id.challenge1Button);
        challenge1Button.getBackground().setColorFilter(0xF00000FF, PorterDuff.Mode.MULTIPLY);
        Button challenge2Button = (Button) findViewById(R.id.challenge2Button);
        challenge2Button.getBackground().setColorFilter(0xF00000FF, PorterDuff.Mode.MULTIPLY);
        Button challenge3Button = (Button) findViewById(R.id.challenge3Button);
        challenge3Button.getBackground().setColorFilter(0xF00000FF, PorterDuff.Mode.MULTIPLY);

        classicButton.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				Intent intent  = new Intent("gr.sullenart.games.nimchallenge.GAME");
				intent.putExtra("game", "classic");
				startActivity(intent);
			}
		});
        
        customButton.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				Intent intent  = new Intent("gr.sullenart.games.nimchallenge.NIM_EDIT_BOARDS");
				startActivity(intent);
			}
		});        

        variationsButton.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				Intent intent  = new Intent("gr.sullenart.games.nimchallenge.GAME");
				intent.putExtra("game", "variations");
				startActivity(intent);
			}
		});

        challenge1Button.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				Intent intent  = new Intent("gr.sullenart.games.nimchallenge.GAME");
				intent.putExtra("game", "challenge1");
				startActivity(intent);
			}
		});

        challenge2Button.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				Intent intent  = new Intent("gr.sullenart.games.nimchallenge.GAME");
				intent.putExtra("game", "challenge2");
				startActivity(intent);
			}
		});

        challenge3Button.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				Intent intent  = new Intent("gr.sullenart.games.nimchallenge.GAME");
				intent.putExtra("game", "challenge3");
				startActivity(intent);
			}
		});

        if (!GameFeatures.getExtendedGamesEnabled()) {
	        challenge2Button.setEnabled(false);
	        challenge2Button.setTextColor(0xFFCCCCCC);
	        challenge2Button.getBackground().setColorFilter(0xFF000000, PorterDuff.Mode.MULTIPLY);
	        challenge2Button.setCompoundDrawablesWithIntrinsicBounds(R.drawable.clock2_gray, 0, 0, 0);
	        challenge3Button.setEnabled(false);
	        challenge3Button.setTextColor(0xFFCCCCCC);
	        challenge3Button.getBackground().setColorFilter(0xFF000000, PorterDuff.Mode.MULTIPLY);
	        challenge3Button.setCompoundDrawablesWithIntrinsicBounds(R.drawable.clock3_gray, 0, 0, 0);
        }
        
        DisplayMetrics metrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(metrics);

        int height = metrics.heightPixels;
        int width = metrics.widthPixels;
        
        if (height > width && height <=400) {
        	((ImageView) findViewById(R.id.logo_header)).getLayoutParams().height = 0;
        }
        
        
        LinearLayout layout = (LinearLayout)findViewById(R.id.banner_layout);
        adsManager.addAdsView(this, layout);        
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Apache License, Version 2.0


Written By
Software Developer (Senior) Self employed
Greece Greece
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions