Android Open Source - FindYourWords Positions






From Project

Back to project page FindYourWords.

License

The source code is released under:

Apache License

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

/**
 * Position is a class that take track of all possible position of the words from the coordinates (X,Y)
 * /* ww w. j  a  va  2s .  c om*/
 * Commands explain which direction can be used to put a word into the grid.
 * 
 * Commands:
 * 0: vertical up
 * 1: diagonal up rigth
 * 2: horizontal rigth
 * 3: diagonal down rigth
 * 4: vertical down
 * 5: diagonal down left 
 * 6: horizontal left
 * 7: diagonal up left
 * 
 * @author Sara Craba
 * @version 1.0
 */

package grid;

public class Positions{
  private boolean[] positions;
  private int grid_x_dimension;
  private int grid_y_dimension;

  /**
   * Constuctor
   * @param grid_x_dimension    whidt of the grid
   * @param grid_y_dimension    hight of the grid
   */
  public Positions(int grid_x_dimension, int grid_y_dimension)
  {
    //for definition all element are false
    positions= new boolean[8];
    this.grid_x_dimension=grid_x_dimension;
    this.grid_y_dimension=grid_y_dimension;
  }
  
  /**
   * The getArray method return a position array that explain in which position can stay the
   * word in the grid from (X,Y) start point.
   * @param gridGame    grid of the game
   * @param word      word to check
   * @param coordX    x coordinate of the start cell
   * @param coordY    y coordinate of the start cell
   * @return        boolean position array
   */
  public boolean[] getArray(Cell gridGame[][], String word, int coordX, int coordY)
  {
    control(gridGame, word,coordX,coordY);
    return positions;
  }
  
  /**
   * The control method initialize the positions array that take track per each direction if a word can
   * stay in the direction. The word start from the cell in coordinates (X,Y).
   * Per each direction put true if can stay, false otherwise
   * @param gridGame    grid of the game
   * @param word      word to check
   * @param coordX    x coordinate of the start cell
   * @param coordY    y coordinate of the start cell
   */
  private void control(Cell gridGame[][], String word, int coordX, int coordY)
  {
    final int costA= word.length() - 1;
    final int costB= grid_x_dimension - 1 - costA;
    final int costC= grid_y_dimension - 1 - costA;
    int varA, varB, varC, varD;

    for (int command=0; command<8; command++)
    {
      //initialization of varA and varB
      varA= ((command==0)||(command==4))?0:((command>4)?(coordX-costA):(costB-coordX));
      varB= ((command==2)||(command==6))?0:((command>2)&&(command<6)?(costC-coordY):(coordY-costA));

      //varA and varB say if the word starting from (X,Y) position can stay into the grid
      if( (varA<0) || (varB<0) )
      {
        positions[command]=false;
        continue;
      }

      //word can stay in the position
      positions[command]=true;

      //check if the char of the word can stay in the cells
      for (int j=0; j< word.length(); j++)
      {
        //initialization of varC and varD
        varC=coordX + (((command==0)||(command==4))?0:((command>4)?-j:j));
        varD=coordY + (((command==2)||(command==6))?0:((command>2)&&(command<6)?j:-j));

        //if the char into the cell is different from the char of the word, the position is busy
        if((gridGame[varD][varC].getLetter()!=GridManager.CELL_TEXT_NULL) && 
           (gridGame[varD][varC].getLetter()!=word.charAt(j)))
        {
          positions[command]=false;
          break;
        }
      }
    }
  }
}




Java Source Code List

com.ipaulpro.afilechooser.FileChooserActivity.java
com.ipaulpro.afilechooser.FileListAdapter.java
com.ipaulpro.afilechooser.FileListFragment.java
com.ipaulpro.afilechooser.FileLoader.java
com.ipaulpro.afilechooser.utils.FileUtils.java
com.ipaulpro.afilechooser.utils.MimeTypeParser.java
com.ipaulpro.afilechooser.utils.MimeTypes.java
dialog.DialogCredits.java
dialog.DialogInfoMain.java
dialog.DialogInfo.java
dialog.DialogSaveFile.java
grid.CaptureWord.java
grid.Cell.java
grid.GridManager.java
grid.LetterView.java
grid.LineDrawView.java
grid.Positions.java
grid.RelativeLayoutView.java
mainClasses.MainActivity.java
mainClasses.SetWords.java
win.DialogWinThread.java
win.DialogWin.java
win.WinView.java
word.CompareStringList.java
word.OneWord.java