Android Open Source - ScoponeDaPolso Table






From Project

Back to project page ScoponeDaPolso.

License

The source code is released under:

GNU General Public License

If you think the Android project ScoponeDaPolso 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 org.gdg.bari.entities;
//from www  .ja v  a  2  s .co m
import android.util.Log;

import com.google.common.collect.Sets;


import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

public class Table {

    private static final String TAG = Table.class.getSimpleName();

    private String roomId;
    private List<String> playerList; //player 0 & 2 TEAM A, player 1 & 3 TEAM B
    private Score scoreTeamA;
    private Score scoreTeamB;
    private Deck deck;
    private String lastTakenPlayerId;
    private Set<Card> cardsOnTable;

    public Table(String roomId, List<String> playerList){

        this.roomId = roomId;
        this.lastTakenPlayerId = null;
        this.playerList = playerList;
        this.cardsOnTable = new HashSet<Card>();
        this.deck = new Deck(playerList);
        this.scoreTeamA = new Score();
        this.scoreTeamB = new Score();
    }

    public Deck takeDeck(){
        return this.deck;
    }

    public List<Card> getPlayerCardList(String playerId){
        return deck.getPlayerCardList(playerId);
    }

    //chiamata dai giocatori "passivi"
    public void updateDeck(Card shootedCard, Set<Card> takenCardSet){

        if(takenCardSet.isEmpty())
            cardsOnTable.add(shootedCard);
        else {
            cardsOnTable.removeAll(takenCardSet);
            for(Card takenCard :  takenCardSet)
                deck.update(takenCard);

            //TODO change to notification
            if(cardsOnTable.isEmpty()) {

                Log.i(TAG, "scopa fatta");
                Score score = getScoreTeam(shootedCard.getOwner());
                score.setScope(score.getScope()+1);
            }

            checkBeautifulSeven(shootedCard, takenCardSet);
            lastTakenPlayerId = shootedCard.getOwner();
        }
    }

    //chiamata del giocatore "attivo"
    public Set<Card> calculateHand(Card shootedCard){

        Set<Card> matchedCombination = new HashSet<Card>();
        Set<Set<Card>> combinationSet = Sets.powerSet(cardsOnTable);

        Iterator<Set<Card>> iterator = combinationSet.iterator();
        while(iterator.hasNext() && matchedCombination.isEmpty()){

            int sum = 0;
            Set<Card> combination = iterator.next();
            for(Card card: combination)
                sum += card.getValue();

            if(sum == shootedCard.getValue()){

                shootedCard.setStatus(Constants.STATUS_TAKEN);

                for(Card card: combination){
                    card.setStatus(Constants.STATUS_TAKEN);
                    card.setOwner(shootedCard.getOwner());
                    cardsOnTable.remove(card);
                }

                if(cardsOnTable.isEmpty()){
                    //TODO hai fatto scopa
                    Log.i(TAG, "hai fatto scopa");
                    Score score = getScoreTeam(shootedCard.getOwner());
                    score.setScope(score.getScope()+1);
                }

                checkBeautifulSeven(shootedCard, matchedCombination);

                matchedCombination = combination;
                lastTakenPlayerId = shootedCard.getOwner();
            }
        }

        if(matchedCombination.isEmpty()) {
            //stiamo ignorando l'owner
            shootedCard.setStatus(Constants.STATUS_ON_TABLE);
            cardsOnTable.add(shootedCard);
        }
        return matchedCombination;
    }

    public List<Score> calculateFinalScore(){

        List<Score> finalScore = new ArrayList<Score>();

        //lunghe
        int numberOfCardsTeamA = deck.getNumberOfCardsOwnedByPlayer(playerList.get(0)) +
                deck.getNumberOfCardsOwnedByPlayer(playerList.get(2));

        int numberOfCardsTeamB = deck.getNumberOfCardsOwnedByPlayer(playerList.get(1)) +
                deck.getNumberOfCardsOwnedByPlayer(playerList.get(3));

        if(numberOfCardsTeamA > numberOfCardsTeamB)
            scoreTeamA.setLunga(1);
        else if(numberOfCardsTeamB > numberOfCardsTeamA)
            scoreTeamB.setLunga(1);

        //70
        //TODO

        //denari
        int numberOfDenariCardsTeamA = deck.getNumberOfDenariCardsOwnedByPlayer(playerList.get(0)) +
                deck.getNumberOfDenariCardsOwnedByPlayer(playerList.get(2));

        int numberOfDenariCardsTeamB = deck.getNumberOfDenariCardsOwnedByPlayer(playerList.get(1)) +
                deck.getNumberOfDenariCardsOwnedByPlayer(playerList.get(3));

        if(numberOfDenariCardsTeamA > numberOfDenariCardsTeamB)
            scoreTeamA.setDenari(1);
        else if(numberOfDenariCardsTeamB > numberOfDenariCardsTeamA)
            scoreTeamB.setDenari(1);

        finalScore.add(scoreTeamA);
        finalScore.add(scoreTeamB);
        return finalScore;
    }

    private Score getScoreTeam(String player){

        if((playerList.indexOf(player)%2)==1)
            return scoreTeamB;
        else
            return scoreTeamA;
    }

    private void checkBeautifulSeven(Card shootedCard, Set<Card> matchedCombination){

        Card beautifulSeven = new Card(Constants.SEED_DENARI, 7);
        if(matchedCombination.contains(beautifulSeven) ||
                beautifulSeven.equals(shootedCard)){
            Score score = getScoreTeam(shootedCard.getOwner());
            score.setSettebello(1);
        }
    }
}




Java Source Code List

com.google.example.games.basegameutils.BaseGameActivity.java
com.google.example.games.basegameutils.BaseGameUtils.java
com.google.example.games.basegameutils.GameHelperUtils.java
com.google.example.games.basegameutils.GameHelper.java
com.mariux.teleport.lib.ApplicationTest.java
com.mariux.teleport.lib.TeleportClient.java
com.mariux.teleport.lib.TeleportService.java
org.gdg.bari.entities.ApplicationTest.java
org.gdg.bari.entities.Card.java
org.gdg.bari.entities.Constants.java
org.gdg.bari.entities.Deck.java
org.gdg.bari.entities.Score.java
org.gdg.bari.entities.TableTurn.java
org.gdg.bari.entities.Table.java
org.gdg.bari.entities.TeleportClientManager.java
org.gdg.bari.scopone.ApplicationTest.java
org.gdg.bari.scopone.activity.MobileGameActivity.java
org.gdg.bari.scopone.activity.MobileMainActivity.java
org.gdg.bari.scopone.activity.WearConfirmationActivity.java
org.gdg.bari.scopone.activity.WearMainActivity.java
org.gdg.bari.scopone.fragment.CardListFragment.java
org.gdg.bari.scopone.fragment.GameFragment.java
org.gdg.bari.scopone.fragment.LoginFragment.java
org.gdg.bari.scopone.fragment.MenuFragment.java
org.gdg.bari.scopone.service.MobileTeleportService.java
org.gdg.bari.scopone.services.WearTeleportService.java
org.gdg.bari.scopone.util.GoogleApiClientManager.java
org.gdg.bari.scopone.util.LogUtil.java