Back to project page Briscola.
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.
package com.gmail.craptik.briscola; //from w ww . j av a2 s . c om import java.util.ArrayList; import android.app.Activity; import android.content.Intent; import android.content.res.Resources; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.Button; import android.widget.ListView; import android.widget.Toast; public class NewGameActivity extends Activity { private ListView listView; private EGameProgress gameProgress; private static GameData gameData; private static final int BUTTON_IX_PLAYERS = 0; private static final int BUTTON_IX_FIRST_NEMESIS = 1; private static final int BUTTON_IX_CALLER_BID = 2; private static final int BUTTON_IX_CALLED_CARD = 3; private static final int BUTTON_IX_CALLEE = 4; private static final int BUTTON_IX_CALLER_SCORE = 5; private static final int BUTTON_IX_COUNT = 6; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_new_game); gameProgress = EGameProgress.NONE; gameData = new GameData(); Resources res = getResources(); ArrayList<ActionItem> values = new ArrayList<ActionItem>(BUTTON_IX_COUNT); values.add(BUTTON_IX_PLAYERS, new ActionItem(res.getString(R.string.get_players), res.getString(R.string.get_players_desc))); values.add(BUTTON_IX_FIRST_NEMESIS, new ActionItem(res.getString(R.string.first_and_nemesis), res.getString(R.string.first_and_nemesis_desc))); values.add(BUTTON_IX_CALLER_BID, new ActionItem(res.getString(R.string.caller_and_bid), res.getString(R.string.caller_and_bid_desc))); values.add(BUTTON_IX_CALLED_CARD, new ActionItem(res.getString(R.string.called_card), res.getString(R.string.called_card_desc))); values.add(BUTTON_IX_CALLEE, new ActionItem(res.getString(R.string.called_player), res.getString(R.string.called_player_desc))); values.add(BUTTON_IX_CALLER_SCORE, new ActionItem(res.getString(R.string.caller_score), res.getString(R.string.caller_score_desc))); listView = (ListView) findViewById(R.id.new_game_list); listView.addFooterView(new View(this), null, true); listView.setAdapter(new ActionAdapter(this, values)); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if(position > gameProgress.getValue()) { Toast.makeText(NewGameActivity.this, getResources().getString(R.string.complete_previous_steps), Toast.LENGTH_SHORT).show(); return; } switch(position) { case BUTTON_IX_PLAYERS: { getPlayers(view); break; } case BUTTON_IX_FIRST_NEMESIS: { getFirstAndNemesis(view); break; } case BUTTON_IX_CALLER_BID: { getCallerAndBid(view); break; } case BUTTON_IX_CALLED_CARD: { getCalledCard(view); break; } case BUTTON_IX_CALLEE: { getCallee(view); break; } case BUTTON_IX_CALLER_SCORE: { getCallerScore(view); break; } default: { // Forgot to handle new game data cases here assert false; break; } } } }); } @Override protected void onResume() { super.onResume(); updateProgress(); ((Button) findViewById(R.id.new_game_confirm)).setEnabled(gameProgress.getValue() >= EGameProgress.CALLED_CARD.getValue()); } public void confirm(View view) { } private void updateProgress() { if(gameData.getPlayers() == null || gameData.getPlayers().size() != 5) { gameProgress = EGameProgress.NONE; return; } boolean foundNullPlayer = false; for(int i = 0; i < gameData.getPlayers().size(); i++) { if(gameData.getPlayers().get(i) == null) { foundNullPlayer = true; break; } } if(foundNullPlayer) { // How did this happen? We don't want this at all... assert false; gameProgress = EGameProgress.NONE; return; } boolean isNemesisPresent = gameData.isNemesisPresent(); if(gameData.getFirst() == null || (isNemesisPresent && gameData.getNemesisCaller() == null)) { gameProgress = EGameProgress.PLAYERS; return; } boolean isFirstPlaying = gameData.isPlayerPresent(gameData.getFirst()); boolean isNemesisCallerPlaying = false; if(gameData.getNemesisCaller() != null) { isNemesisCallerPlaying = gameData.isPlayerPresent(gameData.getNemesisCaller()); } if(!isFirstPlaying || (!isNemesisCallerPlaying && isNemesisPresent)) { gameProgress = EGameProgress.PLAYERS; return; } if(gameData.getCaller() == null || !(gameData.getCallerBid() >= 60 && gameData.getCallerBid() <= 120)) { gameProgress = EGameProgress.FIRST_NEMESIS; return; } boolean isCallerPlaying = gameData.isPlayerPresent(gameData.getCaller()); if(!isCallerPlaying) { gameProgress = EGameProgress.FIRST_NEMESIS; return; } if(gameData.getCalledCard() == null || gameData.getCalledCard().getSuit() == ECardSuit.NONE || gameData.getCalledCard().getNumber() == ECardNumber.NONE) { gameProgress = EGameProgress.CALLER_BID; return; } if(gameData.getCallee() == null || !gameData.isPlayerPresent(gameData.getCallee())) { gameProgress = EGameProgress.CALLED_CARD; return; } if(!(gameData.getCallerScore() >= 0 && gameData.getCallerScore() <= 120)) { gameProgress = EGameProgress.CALLEE; } gameProgress = EGameProgress.CALLER_SCORE; gameProgress = EGameProgress.COMPLETE; } public void getPlayers(View view) { Intent intent = new Intent(this, PlayersSelectActivity.class); startActivity(intent); } public void getFirstAndNemesis(View view) { Intent intent = new Intent(this, FirstNemesisSelectActivity.class); startActivity(intent); } public void getCallerAndBid(View view) { Intent intent = new Intent(this, CallerBidSelectActivity.class); startActivity(intent); } public void getCalledCard(View view) { Intent intent = new Intent(this, CallCardSuitSelectActivity.class); startActivity(intent); } public void getCallee(View view) { Intent intent = new Intent(this, CalleeSelectActivity.class); startActivity(intent); } public void getCallerScore(View view) { Intent intent = new Intent(this, ScoreSelectActivity.class); startActivity(intent); } public static GameData getGameData() { return gameData; } }