Skip to content

Commit

Permalink
Add Kdoc for LineSelectionHelper class
Browse files Browse the repository at this point in the history
  • Loading branch information
AraujoJordan committed May 14, 2020
1 parent 87fad22 commit caba3aa
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,47 @@
/**
* Designed and developed by Jordan Lira (@araujojordan)
*
* Copyright (C) 2020 Jordan Lira de Araujo Junior
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
* NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/

package com.araujo.jordan.wordfindify.utils

import android.util.Log
import com.araujo.jordan.wordfindify.models.BoardCharacter
import kotlin.math.absoluteValue
import kotlin.math.atan2

/**
* Make a straight line from first to last letter selected, restricting to the 8 directions
* @author Jordan L. Araujo Jr. (araujojordan)
*/
class LineSelectionHelper {
private var firstChar: BoardCharacter? = null
private var lastChar: BoardCharacter? = null
private var grid: ArrayList<ArrayList<BoardCharacter>>? = null
private var originPoint = arrayOf<Int>()

/**
* Add the first letter and the grid
* @param boardChar first letter of the selection
* @param grid that will perform the selection
*/
fun addFirst(boardChar: BoardCharacter, grid: ArrayList<ArrayList<BoardCharacter>>) {
require(firstChar == null)
this.firstChar = boardChar
Expand All @@ -19,6 +50,11 @@ class LineSelectionHelper {
Log.d("LineSelectionHelper", "ORIGINAL: x:${originPoint[1]} y:${originPoint[0]}")
}

/**
* Draw a line from first letter until the boardChar letter
* @param boardChar last letter of the selection
* @return straight line from first to boardChar letter
*/
fun showLine(boardChar: BoardCharacter): List<BoardCharacter> {
require(firstChar != null)

Expand Down Expand Up @@ -47,7 +83,7 @@ class LineSelectionHelper {
try {
list.add(getChar(list.last().x() + 1, list.last().y() - 1))
} catch (err: Exception) {

/** Ignore if selects to a outside letter **/
}
}
list
Expand All @@ -59,7 +95,7 @@ class LineSelectionHelper {
try {
list.add(getChar(list.last().x() + 1, list.last().y()))
} catch (err: Exception) {

/** Ignore if selects to a outside letter **/
}
}
list
Expand All @@ -71,7 +107,7 @@ class LineSelectionHelper {
try {
list.add(getChar(list.last().x() + 1, list.last().y() + 1))
} catch (err: Exception) {

/** Ignore if selects to a outside letter **/
}
}
list
Expand All @@ -83,7 +119,7 @@ class LineSelectionHelper {
try {
list.add(getChar(list.last().x(), list.last().y() + 1))
} catch (err: Exception) {

/** Ignore if selects to a outside letter **/
}
}
list
Expand All @@ -95,7 +131,7 @@ class LineSelectionHelper {
try {
list.add(getChar(list.last().x() - 1, list.last().y() + 1))
} catch (err: Exception) {

/** Ignore if selects to a outside letter **/
}
}
list
Expand All @@ -107,7 +143,7 @@ class LineSelectionHelper {
try {
list.add(getChar(list.last().x() - 1, list.last().y()))
} catch (err: Exception) {

/** Ignore if selects to a outside letter **/
}
}
list
Expand All @@ -119,7 +155,7 @@ class LineSelectionHelper {
try {
list.add(getChar(list.last().x() - 1, list.last().y() - 1))
} catch (err: Exception) {

/** Ignore if selects to a outside letter **/
}
}
list
Expand All @@ -132,7 +168,7 @@ class LineSelectionHelper {
try {
list.add(getChar(list.last().x(), list.last().y() - 1))
} catch (err: Exception) {

/** Ignore if selects to a outside letter **/
}
}
list
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,19 @@ class BoardAdapter(
override fun isSelected(index: Int) =
grid[index % boardSize][if (index < boardSize) 0 else index / boardSize].isOnSelection


/**
* Release selection of all items
*/
override fun releaseSelection() {
lineSelectHelper = null
presenter.checkForWord()
notifyDataSetChanged()
touchListener.setIsActive(true)
}

/**
* Set selected items to paint the right words on the board
*/
override fun setSelected(index: Int, selected: Boolean) {
val touchLetter = grid[index % boardSize][index / boardSize]
if (lineSelectHelper == null) {
Expand All @@ -118,14 +123,6 @@ class BoardAdapter(
}
}

private fun getGridIndex(boardChar: BoardCharacter): Int {
repeat(100) {
val item = grid[it % boardSize][if (it < boardSize) 0 else it / boardSize]
if (item.id == boardChar.id) return it
}
return 0
}

/**
* Play sound based on many elements are selected in the board
* @param ctx context used to retrieve and play the sound from resources
Expand Down

0 comments on commit caba3aa

Please sign in to comment.