|
|
|
@ -1,12 +1,14 @@
|
|
|
|
|
package modele
|
|
|
|
|
|
|
|
|
|
import android.annotation.SuppressLint
|
|
|
|
|
import android.util.Log
|
|
|
|
|
import android.widget.TextView
|
|
|
|
|
import kotlinx.coroutines.GlobalScope
|
|
|
|
|
import kotlinx.coroutines.cancel
|
|
|
|
|
import kotlinx.coroutines.launch
|
|
|
|
|
import views.ViewsGame
|
|
|
|
|
|
|
|
|
|
class Game(private val width: Int,private val height: Int,private val viewGame:ViewsGame) {
|
|
|
|
|
class Game(private val width: Int,private val height: Int,private val viewGame:ViewsGame,private val points:TextView) {
|
|
|
|
|
val dashBoard: DashBoard = DashBoard(width,height,viewGame)
|
|
|
|
|
lateinit var currentShape: Shape
|
|
|
|
|
var difficulty: Difficulty = Difficulty.EASY
|
|
|
|
@ -17,13 +19,14 @@ class Game(private val width: Int,private val height: Int,private val viewGame:V
|
|
|
|
|
// The start game function
|
|
|
|
|
|
|
|
|
|
fun startGame(){
|
|
|
|
|
//this.setCurrentShape(TypeShape.SquareShape)
|
|
|
|
|
currentShape = Shape(TypeShape(EnumTypeShape.SShape),Position(1,1))
|
|
|
|
|
dashBoard.addShape(currentShape)
|
|
|
|
|
val listeTypeShape: List<EnumTypeShape> = listOf(EnumTypeShape.ZShape,EnumTypeShape.JShape,EnumTypeShape.IShape,EnumTypeShape.LShape,EnumTypeShape.TShape,EnumTypeShape.SquareShape,EnumTypeShape.SShape)
|
|
|
|
|
var indexListeTypeShape:Int = 0
|
|
|
|
|
|
|
|
|
|
//currentShape = Shape(TypeShape(EnumTypeShape.SShape),Position(1,1))
|
|
|
|
|
//dashBoard.addShape(currentShape)
|
|
|
|
|
|
|
|
|
|
currentShape = Shape(TypeShape(EnumTypeShape.IShape),Position(2,5))
|
|
|
|
|
dashBoard.addShape(currentShape)
|
|
|
|
|
//currentShape = Shape(TypeShape(EnumTypeShape.IShape),Position(2,5))
|
|
|
|
|
//dashBoard.addShape(currentShape)
|
|
|
|
|
|
|
|
|
|
//currentShape = Shape(TypeShape(EnumTypeShape.SquareShape),Position(2,6))
|
|
|
|
|
//dashBoard.addShape(currentShape)
|
|
|
|
@ -39,15 +42,42 @@ class Game(private val width: Int,private val height: Int,private val viewGame:V
|
|
|
|
|
|
|
|
|
|
//currentShape = Shape(TypeShape(EnumTypeShape.JShape),Position(1,1))
|
|
|
|
|
//dashBoard.addShape(currentShape)
|
|
|
|
|
|
|
|
|
|
//dashBoard.gridOfGame[2][0] = 5
|
|
|
|
|
/*
|
|
|
|
|
dashBoard.gridOfGame[0][0] = 5
|
|
|
|
|
dashBoard.gridOfGame[0][1] = 5
|
|
|
|
|
dashBoard.gridOfGame[0][2] = 5
|
|
|
|
|
dashBoard.gridOfGame[0][3] = 5
|
|
|
|
|
dashBoard.gridOfGame[0][4] = 5
|
|
|
|
|
dashBoard.gridOfGame[0][5] = 5
|
|
|
|
|
dashBoard.gridOfGame[0][6] = 5
|
|
|
|
|
*/
|
|
|
|
|
currentShape = Shape(TypeShape(listeTypeShape[indexListeTypeShape]),Position(width/2,0))
|
|
|
|
|
indexListeTypeShape++
|
|
|
|
|
dashBoard.addShape(currentShape)
|
|
|
|
|
|
|
|
|
|
println("RUN !!")
|
|
|
|
|
dashBoard.updateViewGame()
|
|
|
|
|
|
|
|
|
|
GlobalScope.launch {
|
|
|
|
|
while (true){
|
|
|
|
|
dashBoard.fallingShape(currentShape)
|
|
|
|
|
while(true){
|
|
|
|
|
if(! dashBoard.fallingShape(currentShape)){
|
|
|
|
|
if ( indexListeTypeShape == 7 ){
|
|
|
|
|
indexListeTypeShape = 0
|
|
|
|
|
}
|
|
|
|
|
val nbLine = dashBoard.clearLines()
|
|
|
|
|
if ( (nbLine > 0) and (nbLine<4)){
|
|
|
|
|
val tmpPoints:String = points.text as String
|
|
|
|
|
points.text = (tmpPoints.toInt()+(nbLine*100)).toString()
|
|
|
|
|
}
|
|
|
|
|
if ( nbLine == 4 ){
|
|
|
|
|
val tmpPoints:String = points.text as String
|
|
|
|
|
points.text = (tmpPoints.toInt()+1200).toString()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
currentShape = Shape(TypeShape(listeTypeShape[indexListeTypeShape]),Position(width/2,0))
|
|
|
|
|
dashBoard.addShape(currentShape)
|
|
|
|
|
indexListeTypeShape++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|