Android Open Source - FourRowSolitaire Card Rank






From Project

Back to project page FourRowSolitaire.

License

The source code is released under:

GNU General Public License

If you think the Android project FourRowSolitaire 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

/*
 This file is a part of Four Row Solitaire
/*  w  w  w .  j  a  v a  2 s .  c o m*/
 Copyright (C) 2010-2014 by Matt Stephen, Todor Balabanov, Konstantin Tsanov, Ventsislav Medarov, Vanya Gyaurova, Plamena Popova, Hristiana Kalcheva, Yana Genova

 Four Row Solitaire is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 Four Row Solitaire is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with FourRowSolitaire.  If not, see <http://www.gnu.org/licenses/>.
 */

package eu.veldsoft.four.row.solitaire;

/**
 * Card rank enum.
 * 
 * @author Todor Balabanov
 */
enum CardRank {

  /**
   * Ace enum constant.
   */
  ACE(1),

  /**
   * Two enum constant.
   */
  TWO(2),

  /**
   * Three enum constant.
   */
  THREE(3),

  /**
   * Four enum constant.
   */
  FOUR(4),

  /**
   * Five enum constant.
   */
  FIVE(5),

  /**
   * Six enum constant.
   */
  SIX(6),

  /**
   * Seven enum constant.
   */
  SEVEN(7),

  /**
   * Eight enum constant.
   */
  EIGHT(8),

  /**
   * Nine enum constant.
   */
  NINE(9),

  /**
   * Ten enum constant.
   */
  TEN(10),

  /**
   * Jack enum constant.
   */
  JACK(11),

  /**
   * Queen enum constant.
   */
  QUEEN(12),

  /**
   * King enum constant.
   */
  KING(13);

  /**
   * Rank index.
   */
  private int index;

  /**
   * Returns the card's rank based on the argument index.
   * 
   * @param index
   *            Index to be matched with enum constant.
   * 
   * @return Matched enum constant.
   * 
   * @author Todor Balabanov
   */
  public static CardRank getValue(int index) {
    switch (index) {
    case 1:
      return ACE;
    case 2:
      return TWO;
    case 3:
      return THREE;
    case 4:
      return FOUR;
    case 5:
      return FIVE;
    case 6:
      return SIX;
    case 7:
      return SEVEN;
    case 8:
      return EIGHT;
    case 9:
      return NINE;
    case 10:
      return TEN;
    case 11:
      return JACK;
    case 12:
      return QUEEN;
    case 13:
      return KING;
    }

    return null;
  }

  /**
   * Setting the card's rank based on the argument index. The argument
   * represents one of the 13 ranks.
   * 
   * @param index
   *            Index to be used for the rank.
   * 
   * @author Todor Balabanov
   */
  private CardRank(int index) {
    this.index = index;
  }

  /**
   * Returns the card's rank.
   * 
   * @return index Rank index.
   * 
   * @author Todor Balabanov
   */
  public int getIndex() {
    return index;
  }

  /**
   * Checks if the current card we're holding is lesser by one than the
   * current top card on one of the columns.
   * 
   * @param card
   *            Current card we're holding.
   * 
   * @return True if the current card is lesser by one than the top card on
   *         the column, otherwise false.
   * 
   * @author Todor Balabanov
   */
  public boolean isLessByOneThan(final CardRank card) {
    if (this == TWO && card == ACE) {
      return true;
    }
    if (this == THREE && card == TWO) {
      return true;
    }
    if (this == FOUR && card == THREE) {
      return true;
    }
    if (this == FIVE && card == FOUR) {
      return true;
    }
    if (this == SIX && card == FIVE) {
      return true;
    }
    if (this == SEVEN && card == SIX) {
      return true;
    }
    if (this == EIGHT && card == SEVEN) {
      return true;
    }
    if (this == NINE && card == EIGHT) {
      return true;
    }
    if (this == TEN && card == NINE) {
      return true;
    }
    if (this == JACK && card == TEN) {
      return true;
    }
    if (this == QUEEN && card == JACK) {
      return true;
    }
    if (this == KING && card == QUEEN) {
      return true;
    }

    return false;
  }

  /**
   * Checks if the current card we're holding is greater by one than the top
   * card on one of the foundation piles.
   * 
   * @param card
   *            Current card we're holding.
   * 
   * @return True if the current card we're holding is greater by one than the
   *         current top card on one of the foundation piles, otherwise false.
   * 
   * @author Todor Balabanov
   */
  public boolean isGreaterByOneThan(final CardRank card) {
    if (card == TWO && this == ACE) {
      return true;
    }
    if (card == THREE && this == TWO) {
      return true;
    }
    if (card == FOUR && this == THREE) {
      return true;
    }
    if (card == FIVE && this == FOUR) {
      return true;
    }
    if (card == SIX && this == FIVE) {
      return true;
    }
    if (card == SEVEN && this == SIX) {
      return true;
    }
    if (card == EIGHT && this == SEVEN) {
      return true;
    }
    if (card == NINE && this == EIGHT) {
      return true;
    }
    if (card == TEN && this == NINE) {
      return true;
    }
    if (card == JACK && this == TEN) {
      return true;
    }
    if (card == QUEEN && this == JACK) {
      return true;
    }
    if (card == KING && this == QUEEN) {
      return true;
    }

    return false;
  }
}




Java Source Code List

eu.veldsoft.four.row.solitaire.AboutGameActivity.java
eu.veldsoft.four.row.solitaire.AcePileLayeredPane.java
eu.veldsoft.four.row.solitaire.AcePile.java
eu.veldsoft.four.row.solitaire.AnimationSettings.java
eu.veldsoft.four.row.solitaire.BestTimesActivity.java
eu.veldsoft.four.row.solitaire.CardColor.java
eu.veldsoft.four.row.solitaire.CardComponent.java
eu.veldsoft.four.row.solitaire.CardRank.java
eu.veldsoft.four.row.solitaire.CardStackLayeredPane.java
eu.veldsoft.four.row.solitaire.CardStack.java
eu.veldsoft.four.row.solitaire.CardSuit.java
eu.veldsoft.four.row.solitaire.Card.java
eu.veldsoft.four.row.solitaire.ChangeAppearance.java
eu.veldsoft.four.row.solitaire.ChangeOptions.java
eu.veldsoft.four.row.solitaire.ColumnLayeredPane.java
eu.veldsoft.four.row.solitaire.Column.java
eu.veldsoft.four.row.solitaire.Common.java
eu.veldsoft.four.row.solitaire.DealDeckLayeredPane.java
eu.veldsoft.four.row.solitaire.DealDeck.java
eu.veldsoft.four.row.solitaire.Deck.java
eu.veldsoft.four.row.solitaire.DiscardPileLayeredPane.java
eu.veldsoft.four.row.solitaire.DiscardPile.java
eu.veldsoft.four.row.solitaire.FireworksDisplay.java
eu.veldsoft.four.row.solitaire.FourRowSolitaire.java
eu.veldsoft.four.row.solitaire.GameActivity.java
eu.veldsoft.four.row.solitaire.GameDifficulty.java
eu.veldsoft.four.row.solitaire.GameState.java
eu.veldsoft.four.row.solitaire.HelpActivity.java
eu.veldsoft.four.row.solitaire.MenuActivity.java
eu.veldsoft.four.row.solitaire.SettingsActivity.java
eu.veldsoft.four.row.solitaire.SingleCellLayeredPane.java
eu.veldsoft.four.row.solitaire.SingleCell.java
eu.veldsoft.four.row.solitaire.SolitaireBoardFrame.java
eu.veldsoft.four.row.solitaire.SolitaireBoard.java
eu.veldsoft.four.row.solitaire.SolitaireLayout.java
eu.veldsoft.four.row.solitaire.SolitairePanel.java
eu.veldsoft.four.row.solitaire.SoundsSettings.java
eu.veldsoft.four.row.solitaire.StatisticsActivity.java
eu.veldsoft.four.row.solitaire.StatisticsTab0Activity.java
eu.veldsoft.four.row.solitaire.StatisticsTab1Activity.java
eu.veldsoft.four.row.solitaire.StatisticsTab2Activity.java
eu.veldsoft.four.row.solitaire.StatisticsTab3Activity.java
eu.veldsoft.four.row.solitaire.StatisticsTab4Activity.java
eu.veldsoft.four.row.solitaire.StatisticsTab5Activity.java
eu.veldsoft.four.row.solitaire.ThroughLimit.java
eu.veldsoft.four.row.solitaire.TopTimes.java
eu.veldsoft.four.row.solitaire.WinActivity.java
eu.veldsoft.four.row.solitaire.WinScreen.java