Package com.poker.shared

Examples of com.poker.shared.State


    return serialized;
  }
 
  public static State unserializeState(String serialized) {
    try {
      State state=new State();
      String[] tokens = serialized.split("_");
      int turn = Integer.parseInt(tokens[0]);
      state.setPlayerTurn(turn);
      int process = Integer.parseInt(tokens[1]);
      state.setProcess(process);
      state.getPlayers().get(0).setBalance(Integer.parseInt(tokens[2]));
      state.getPlayers().get(1).setBalance(Integer.parseInt(tokens[3]));
      if (process >= 1) {
        ArrayList<Card> dealerCards = new ArrayList<Card>();
        ArrayList<Card> player1Cards = new ArrayList<Card>();
        ArrayList<Card> player2Cards = new ArrayList<Card>();
        for (int i = 4; i < 9;) {
          Suit suit = Enum.valueOf(Suit.class, tokens[i]);

          Rank rank = Enum.valueOf(Rank.class, tokens[i + 1]);
          Card card = new Card(suit, rank);
          dealerCards.add(card);
          i += 2;
        }
        state.setDealerCards(dealerCards);
        for (int i = 10; i < 15;) {
          Suit suit = Enum.valueOf(Suit.class, tokens[i]);
          Rank rank = Enum.valueOf(Rank.class, tokens[i + 1]);
          Card card = new Card(suit, rank);
          player1Cards.add(card);
          i += 2;
        }
        state.setPlayerCards(0, player1Cards);
        for (int i = 16; i < 21;) {
          Suit suit = Enum.valueOf(Suit.class, tokens[i]);
          Rank rank = Enum.valueOf(Rank.class, tokens[i + 1]);
          Card card = new Card(suit, rank);
          player2Cards.add(card);
          i += 2;
        }
        state.setPlayerCards(1, player2Cards);
        state.clearDesk();
        state.setDesk();
      }

      if (process == 2) {
        state.getPlayers().get(0).setChoose(Choose.valueOf(tokens[22]));
      }

      if (process == 3) {
        state.getPlayers().get(0).setChoose(Choose.valueOf(tokens[22]));
        state.getPlayers().get(1).setChoose(Choose.valueOf(tokens[23]));
      }

      if (process == 4) {
        state.getPlayers().get(0).setChoose(Choose.valueOf(tokens[22]));
        state.getPlayers().get(1).setChoose(Choose.valueOf(tokens[23]));
        state.getPlayers().get(0).setDecision(Decision.valueOf(tokens[24]));
        state.getPlayers().get(0).setResult(GameOver.Result.valueOf(tokens[25]));
      }

      if (process == 5) {
        state.getPlayers().get(0).setChoose(Choose.valueOf(tokens[22]));
        state.getPlayers().get(1).setChoose(Choose.valueOf(tokens[23]));
        state.getPlayers().get(0).setDecision(Decision.valueOf(tokens[24]));
        state.getPlayers().get(0).setResult(GameOver.Result.valueOf(tokens[25]));
        state.getPlayers().get(1).setDecision(Decision.valueOf(tokens[26]));
        state.getPlayers().get(1).setResult(GameOver.Result.valueOf(tokens[27]));
      }

      return state;
    } catch (StringIndexOutOfBoundsException e) {
      return new State();
    } catch (ArrayIndexOutOfBoundsException e) {
      return new State();
    }
  }
View Full Code Here


    * initialize state
    * @param graphics
    */
  public void initState(View graphics) {
    this.graphics = graphics;
    this.state = new State();
    this.state.initialize();
    this.state.setProcess(0);
    ArrayList<Player> players = state.getPlayers();
    ArrayList<String> playerIds = new ArrayList<String>();
    for (int i = 0; i < players.size(); i++) {
View Full Code Here

        state.getPlayers().get(1).setResult(GameOver.Result.valueOf(tokens[27]));
      }

      return state;
    } catch (StringIndexOutOfBoundsException e) {
      return new State();
    } catch (ArrayIndexOutOfBoundsException e) {
      return new State();
    }
  }
View Full Code Here

                     String opponent = matchSplit[1].equals(userId) ? matchSplit[2]: matchSplit[1];
                     if(opponent==matchSplit[1])
                       meID=0;
                     else
                       meID=1;
                     State state=unserializeState(matchSplit[matchSplit.length-1]);
                     setState(state);
             }
             return processedMatchList;
     }
View Full Code Here

       String[] matchSplit = match.split("##");
       String opponent = matchSplit[1].equals(userId) ? matchSplit[2]: matchSplit[1];
       setOtherId(opponent);
         currentMatchId=new Long(matchSplit[0]);
         State state=unserializeState(matchSplit[matchSplit.length-1]);
        
         if(otherId.equals(matchSplit[1]))
           meID=0;
         else
           meID=1;
         setState(state);
         graphics.showTurn(Graphics.messages.setYouPlayer()+(meID+1));
         graphics.showGameTurn(state.getPlayerTurn(),AI);
         graphics.showGameInfo(state.getProcess());
         graphics.showBalance1(state.getPlayers().get(0).getBalance());
         graphics.showBalance2(state.getPlayers().get(1).getBalance());

     }
View Full Code Here

TOP

Related Classes of com.poker.shared.State

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.