GameView.java :  » Game » dominion-dot-com » com » dot » dominion » view » Android Open Source

Android Open Source » Game » dominion dot com 
dominion dot com » com » dot » dominion » view » GameView.java
package com.dot.dominion.view;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;

import com.dot.dominion.Constants;
import com.dot.dominion.Game;
import com.dot.dominion.R;
import com.dot.dominion.domain.Hand;
import com.dot.dominion.domain.PlayingDeck;

//Needs to be updated after God Class
public class GameView extends Activity implements OnClickListener {
  private Game _game;
  private ImageAdapter boardView;
  private ImageView[] board;
  
  //For testing purposes
  private static final int MY_NUMBER = Constants.PLAYER_ONE;
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //setContentView( R.layout.gameview );
      setContentView( R.layout.game );
      
      _game = (Game) getApplication();
      
      board = new ImageView[Constants.TESTING_BOARD_SIZE];
      
      initializeBoard();
      initializeButtons();
  }
  
  @Override
  public void onDestroy() {
    super.onDestroy();
    
    _game = null;
  }
  
  @Override
  public void onActivityResult(int requestCode, int resultCode, Intent data){
    switch( requestCode ) {
      case Constants.HAND_VIEW:
        break;
    }
  }
  
  public void onClick( View view ) {
    switch( view.getId() ) {
      case R.id.field_button:
        break;
      case R.id.hand_button:
        Intent handView = new Intent(this, HandView.class);
        handView.putExtra(Constants.PLAYER_NUMBER, MY_NUMBER);
        startActivityForResult(handView, Constants.HAND_VIEW);
        break;
      case R.id.board_button:
        break;
      case R.id.player_button:
        break;
      case R.id.discard_button:
        break;
    }
  }

  private void initializeBoard() {
      Game _game = (Game) getApplication();
      
      board[0] = (ImageView) findViewById( R.id.game_slot0 );
      board[1] = (ImageView) findViewById( R.id.game_slot1 );
      board[2] = (ImageView) findViewById( R.id.game_slot2 );
      board[3] = (ImageView) findViewById( R.id.game_slot3 );
      board[4] = (ImageView) findViewById( R.id.game_slot4 );
      board[5] = (ImageView) findViewById( R.id.game_slot5 );
      
      /*
      board[6] = (ImageView) findViewById( R.id.game_slot6 );
      board[7] = (ImageView) findViewById( R.id.game_slot7 );
      board[8] = (ImageView) findViewById( R.id.game_slot8 );
      board[9] = (ImageView) findViewById( R.id.game_slot9 );
      board[10] = (ImageView) findViewById( R.id.game_slot10 );
      board[11] = (ImageView) findViewById( R.id.game_slot11 );
      board[12] = (ImageView) findViewById( R.id.game_slot12 );
      board[13] = (ImageView) findViewById( R.id.game_slot13 );
      board[14] = (ImageView) findViewById( R.id.game_slot14 );
      board[15] = (ImageView) findViewById( R.id.game_slot15 );
      */
      
      for(int i = 0; i < Constants.TESTING_BOARD_SIZE; i++) {
        board[i].setImageResource(_game.viewSupplyPile(i).getPictureId());
      }
      
      _game = null;
  }
  
  private void initializeButtons() {
      View fieldButton = (View) findViewById( R.id.field_button );
      fieldButton.setOnClickListener( this );
      
      View handButton = (View) findViewById( R.id.hand_button );
      handButton.setOnClickListener( this );
      
      View playerButton = (View) findViewById( R.id.player_button );
      playerButton.setOnClickListener( this );
      
      View discardButton = (View) findViewById( R.id.discard_button );
      discardButton.setOnClickListener( this );
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.