Android Open Source - Briscola First Nemesis Select Activity






From Project

Back to project page Briscola.

License

The source code is released under:

GNU General Public License

If you think the Android project Briscola listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.gmail.craptik.briscola;
//w ww  . j av a 2  s .c om
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

public class FirstNemesisSelectActivity extends Activity
{
  private Player firstPlayer;
  private Player nemesisCaller;

  @Override
  protected void onCreate(Bundle savedInstanceState)
  {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_first_nemesis_select);
  }

  @Override
  protected void onResume()
  {
    super.onResume();

    GameData gameData = NewGameActivity.getGameData();

    TextView firstPlayerTextView = (TextView) findViewById(R.id.first_nemesis_player_one);
    firstPlayerTextView.setText(gameData.getPlayers().get(0).getName());

    TextView secondPlayerTextView = (TextView) findViewById(R.id.first_nemesis_player_two);
    secondPlayerTextView.setText(gameData.getPlayers().get(1).getName());

    TextView thirdPlayerTextView = (TextView) findViewById(R.id.first_nemesis_player_three);
    thirdPlayerTextView.setText(gameData.getPlayers().get(2).getName());

    TextView fourthPlayerTextView = (TextView) findViewById(R.id.first_nemesis_player_four);
    fourthPlayerTextView.setText(gameData.getPlayers().get(3).getName());

    TextView fifthPlayerTextView = (TextView) findViewById(R.id.first_nemesis_player_five);
    fifthPlayerTextView.setText(gameData.getPlayers().get(4).getName());

    firstPlayer = gameData.getFirst();
    nemesisCaller = gameData.getNemesisCaller();

    if(firstPlayer != null)
    {
      int ixFirst = gameData.findPlayer(firstPlayer);
      RadioGroup firstRadioGroup = (RadioGroup) findViewById(R.id.first_nemesis_first_radio_group);
      RadioButton button = (RadioButton) ((FrameLayout) firstRadioGroup.getChildAt(ixFirst == -1 ? 5 : ixFirst)).getChildAt(0);
      onFirstRadioButtonClicked(button);
    }

    boolean nemesisPresent = gameData.isNemesisPresent();
    RadioGroup nemesisRadioGroup = (RadioGroup) findViewById(R.id.first_nemesis_nemesis_radio_group);
    for(int i = 0; i < nemesisRadioGroup.getChildCount() - 1; i++)
    {
      ((RadioButton) ((FrameLayout) nemesisRadioGroup.getChildAt(i)).getChildAt(0)).setEnabled(nemesisPresent);
    }

    boolean noNemesisCallerSelected = ((RadioButton) ((FrameLayout) nemesisRadioGroup.getChildAt(5)).getChildAt(0)).isChecked();
    ((RadioButton) ((FrameLayout) nemesisRadioGroup.getChildAt(5)).getChildAt(0)).setEnabled(nemesisPresent || !noNemesisCallerSelected);

    if(nemesisPresent)
    {
      if(nemesisCaller != null)
      {
        int ixNemesisCaller = gameData.findPlayer(gameData.getNemesisCaller());
        RadioButton button = (RadioButton) ((FrameLayout) nemesisRadioGroup.getChildAt(ixNemesisCaller == -1 ? 5 : ixNemesisCaller)).getChildAt(0);
        onNemesisRadioButtonClicked(button);
      }
    }
    else
    {
      nemesisCaller = null;
    }
  }

  public void onFirstRadioButtonClicked(View view)
  {
    RadioGroup firstRadioGroup = (RadioGroup) findViewById(R.id.first_nemesis_first_radio_group);
    for(int i = 0; i < firstRadioGroup.getChildCount(); i++)
    {
      ((RadioButton) ((FrameLayout) firstRadioGroup.getChildAt(i)).getChildAt(0)).setChecked(false);
    }

    ((RadioButton) view).setChecked(true);

    GameData gameData = NewGameActivity.getGameData();
    switch(view.getId())
    {
      case R.id.first_nemesis_first_radio_one:
      {
        firstPlayer = gameData.getPlayers().get(0);
        break;
      }
      case R.id.first_nemesis_first_radio_two:
      {
        firstPlayer = gameData.getPlayers().get(1);
        break;
      }
      case R.id.first_nemesis_first_radio_three:
      {
        firstPlayer = gameData.getPlayers().get(2);
        break;
      }
      case R.id.first_nemesis_first_radio_four:
      {
        firstPlayer = gameData.getPlayers().get(3);
        break;
      }
      case R.id.first_nemesis_first_radio_five:
      {
        firstPlayer = gameData.getPlayers().get(4);
        break;
      }
      case R.id.first_nemesis_first_radio_no_one:
      {
        firstPlayer = null;
        break;
      }
      default:
      {
        // Really should have each case...
        firstPlayer = null;
        assert false;
        break;
      }
    }
  }

  public void onNemesisRadioButtonClicked(View view)
  {
    RadioGroup nemesisRadioGroup = (RadioGroup) findViewById(R.id.first_nemesis_nemesis_radio_group);
    for(int i = 0; i < nemesisRadioGroup.getChildCount(); i++)
    {
      ((RadioButton) ((FrameLayout) nemesisRadioGroup.getChildAt(i)).getChildAt(0)).setChecked(false);
    }

    ((RadioButton) view).setChecked(true);

    GameData gameData = NewGameActivity.getGameData();
    switch(view.getId())
    {
      case R.id.first_nemesis_nemesis_radio_one:
      {
        nemesisCaller = gameData.getPlayers().get(0);
        break;
      }
      case R.id.first_nemesis_nemesis_radio_two:
      {
        nemesisCaller = gameData.getPlayers().get(1);
        break;
      }
      case R.id.first_nemesis_nemesis_radio_three:
      {
        nemesisCaller = gameData.getPlayers().get(2);
        break;
      }
      case R.id.first_nemesis_nemesis_radio_four:
      {
        nemesisCaller = gameData.getPlayers().get(3);
        break;
      }
      case R.id.first_nemesis_nemesis_radio_five:
      {
        nemesisCaller = gameData.getPlayers().get(4);
        break;
      }
      case R.id.first_nemesis_nemesis_radio_no_one:
      {
        nemesisCaller = null;
        break;
      }
      default:
      {
        // Really should have each case...
        nemesisCaller = null;
        assert false;
        break;
      }
    }
  }

  public void confirm(View view)
  {
    GameData gameData = NewGameActivity.getGameData();

    gameData.setFirst(firstPlayer);
    gameData.setNemesisCaller(nemesisCaller);

    if(gameData.isNemesisPresent())
    {
      int ixNemesis = gameData.findNemesis();
      Player nemesis = null;

      if(ixNemesis != -1)
      {
        nemesis = gameData.getPlayers().get(ixNemesis);
      }
      else
      {
        // How can the found index of nemesis be invalid?...
        assert false;
        return;
      }

      if(nemesisCaller != null && nemesisCaller.getName().equals("Nemesis"))
      {
        if(firstPlayer != null)
        {
          if(firstPlayer.getName().equals("Nemesis"))
          {
            // TODO: Need to ask for who dealt and put nemesis to the left of them
            assert false;
          }
          else
          {
            gameData.getPlayers().remove(ixNemesis);
            int ixNemesisCaller = gameData.getPlayers().lastIndexOf(firstPlayer);
            gameData.getPlayers().add(ixNemesisCaller + 1, nemesis);
          }
        }
      }
      else
      {
        gameData.getPlayers().remove(ixNemesis);
        int ixNemesisCaller = gameData.getPlayers().lastIndexOf(nemesisCaller);
        gameData.getPlayers().add(ixNemesisCaller + 1, nemesis);
      }
    }

    finish();
  }
}




Java Source Code List

com.gmail.craptik.briscola.ActionAdapter.java
com.gmail.craptik.briscola.ActionItem.java
com.gmail.craptik.briscola.CallCardCupsSelectActivity.java
com.gmail.craptik.briscola.CallCardFeathersSelectActivity.java
com.gmail.craptik.briscola.CallCardSuitSelectActivity.java
com.gmail.craptik.briscola.CallCardSunsSelectActivity.java
com.gmail.craptik.briscola.CallCardSwordsSelectActivity.java
com.gmail.craptik.briscola.CalleeSelectActivity.java
com.gmail.craptik.briscola.CallerBidSelectActivity.java
com.gmail.craptik.briscola.Card.java
com.gmail.craptik.briscola.ECardNumber.java
com.gmail.craptik.briscola.ECardSuit.java
com.gmail.craptik.briscola.EGameProgress.java
com.gmail.craptik.briscola.FirstNemesisSelectActivity.java
com.gmail.craptik.briscola.GameData.java
com.gmail.craptik.briscola.IDatabase.java
com.gmail.craptik.briscola.MainActivity.java
com.gmail.craptik.briscola.NewGameActivity.java
com.gmail.craptik.briscola.PlayerAdapter.java
com.gmail.craptik.briscola.Player.java
com.gmail.craptik.briscola.PlayersSelectActivity.java
com.gmail.craptik.briscola.SQLGameDatabase.java
com.gmail.craptik.briscola.ScoreSelectActivity.java
com.gmail.craptik.briscola.TestDatabase.java