|
|
|
@ -7,9 +7,7 @@ import kotlin.io.path.fileVisitor
|
|
|
|
|
class DashBoard(private val width: Int,private val height: Int,private val view: ViewsGame) {
|
|
|
|
|
val gridOfGame = Array(this.height) { IntArray(this.width) }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// To set something to occupied
|
|
|
|
|
|
|
|
|
|
fun toOccupied(col: Int, row: Int, value: Int) {
|
|
|
|
|
gridOfGame[row][col] = value
|
|
|
|
|
}
|
|
|
|
@ -17,7 +15,7 @@ class DashBoard(private val width: Int,private val height: Int,private val view:
|
|
|
|
|
// To check if an position is occupied
|
|
|
|
|
fun isOccupied(col: Int, row: Int): Boolean = gridOfGame[row][col] != 0
|
|
|
|
|
|
|
|
|
|
fun isLineFull(row: Int): Boolean {
|
|
|
|
|
private fun isLineFull(row: Int): Boolean {
|
|
|
|
|
for (col in 0 until this.width) {
|
|
|
|
|
if (gridOfGame[row][col] == 0) {
|
|
|
|
|
return false
|
|
|
|
@ -26,13 +24,13 @@ class DashBoard(private val width: Int,private val height: Int,private val view:
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun clearLine(row: Int) {
|
|
|
|
|
private fun clearLine(row: Int) {
|
|
|
|
|
for (col in 0 until this.width) {
|
|
|
|
|
gridOfGame[row][col] = 0
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun shiftDown(listeLine:MutableList<Int>) {
|
|
|
|
|
private fun shiftDown(listeLine:MutableList<Int>) {
|
|
|
|
|
|
|
|
|
|
println("Shift Down")
|
|
|
|
|
for( index in listeLine){
|
|
|
|
@ -172,8 +170,11 @@ class DashBoard(private val width: Int,private val height: Int,private val view:
|
|
|
|
|
|
|
|
|
|
for ( line in 0..3){
|
|
|
|
|
for ( column in 0..3){
|
|
|
|
|
if ( (matrix[line][column] == 1) and (shape.typeShape.showShape[line][column] == 0 )){
|
|
|
|
|
if ( gridOfGame[shape.position.y+column][shape.position.x+line] != 0 ) {
|
|
|
|
|
if ( matrix[line][column] == 1){
|
|
|
|
|
if ( (shape.position.y+line >= height) or (shape.position.x+column >= width)){
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
if (gridOfGame[shape.position.y+line][shape.position.x+column] != 0 ){
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -186,6 +187,7 @@ class DashBoard(private val width: Int,private val height: Int,private val view:
|
|
|
|
|
|
|
|
|
|
fun rotateShapeRight(shape: Shape){
|
|
|
|
|
println("Shape action -> Rotation right ! ")
|
|
|
|
|
|
|
|
|
|
deleteShape(shape)
|
|
|
|
|
rotationShapePossible(shape,0)
|
|
|
|
|
writeShape(shape)
|
|
|
|
@ -194,6 +196,7 @@ class DashBoard(private val width: Int,private val height: Int,private val view:
|
|
|
|
|
|
|
|
|
|
fun rotateShapeLeft(shape: Shape){
|
|
|
|
|
println("Shape action -> Rotation left ! ")
|
|
|
|
|
|
|
|
|
|
deleteShape(shape)
|
|
|
|
|
rotationShapePossible(shape,1)
|
|
|
|
|
writeShape(shape)
|
|
|
|
@ -234,9 +237,9 @@ class DashBoard(private val width: Int,private val height: Int,private val view:
|
|
|
|
|
|
|
|
|
|
suspend fun fallingShape(shape: Shape, difficulty: Difficulty):Boolean{
|
|
|
|
|
when(difficulty){
|
|
|
|
|
Difficulty.EASY -> delay(800)
|
|
|
|
|
Difficulty.MEDIUM -> delay(600)
|
|
|
|
|
Difficulty.HARD -> delay(400)
|
|
|
|
|
Difficulty.EASY -> delay(700)
|
|
|
|
|
Difficulty.MEDIUM -> delay(500)
|
|
|
|
|
Difficulty.HARD -> delay(300)
|
|
|
|
|
}
|
|
|
|
|
return moveDown(shape)
|
|
|
|
|
}
|
|
|
|
|