Compare commits
No commits in common. '85f3c8ce5e22b05976b110aaf2e1cabab6c36225' and 'b292ad92edd9db83a48e9d2937179ddb6a009a04' have entirely different histories.
85f3c8ce5e
...
b292ad92ed
@ -1,70 +1,54 @@
|
|||||||
package modele
|
package modele
|
||||||
|
|
||||||
import android.widget.TextView
|
import android.util.Log
|
||||||
import kotlinx.coroutines.GlobalScope
|
import kotlinx.coroutines.GlobalScope
|
||||||
|
import kotlinx.coroutines.cancel
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import views.ViewsGame
|
import views.ViewsGame
|
||||||
import kotlin.random.Random
|
|
||||||
|
|
||||||
class Game(private val width: Int,private val height: Int,private val viewGame:ViewsGame,private val points:TextView) {
|
class Game(private val width: Int,private val height: Int,private val viewGame:ViewsGame) {
|
||||||
val dashBoard: DashBoard = DashBoard(width,height,viewGame)
|
val dashBoard: DashBoard = DashBoard(width,height,viewGame)
|
||||||
lateinit var currentShape: Shape
|
lateinit var currentShape: Shape
|
||||||
private var difficulty: Difficulty = Difficulty.EASY
|
var difficulty: Difficulty = Difficulty.EASY
|
||||||
|
|
||||||
|
|
||||||
//To get the next shape
|
|
||||||
private fun getNextShape(): TypeShape {
|
|
||||||
return when(Random.nextInt(1,7)){
|
|
||||||
1 -> TypeShape(EnumTypeShape.IShape)
|
|
||||||
2 -> TypeShape(EnumTypeShape.SquareShape)
|
|
||||||
3 -> TypeShape(EnumTypeShape.JShape)
|
|
||||||
4 -> TypeShape(EnumTypeShape.LShape)
|
|
||||||
5 -> TypeShape(EnumTypeShape.SShape)
|
|
||||||
6 -> TypeShape(EnumTypeShape.TShape)
|
|
||||||
7 -> TypeShape(EnumTypeShape.ZShape)
|
|
||||||
else -> throw Exception("Problème de random getNextShape()")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// The start game function
|
// The start game function
|
||||||
|
|
||||||
fun startGame(){
|
fun startGame(){
|
||||||
|
//this.setCurrentShape(TypeShape.SquareShape)
|
||||||
|
currentShape = Shape(TypeShape(EnumTypeShape.SShape),Position(1,1))
|
||||||
|
dashBoard.addShape(currentShape)
|
||||||
|
|
||||||
|
|
||||||
currentShape = Shape(getNextShape(),Position(width/2,0))
|
currentShape = Shape(TypeShape(EnumTypeShape.IShape),Position(2,5))
|
||||||
dashBoard.addShape(currentShape)
|
dashBoard.addShape(currentShape)
|
||||||
|
|
||||||
|
//currentShape = Shape(TypeShape(EnumTypeShape.SquareShape),Position(2,6))
|
||||||
|
//dashBoard.addShape(currentShape)
|
||||||
|
|
||||||
|
//currentShape = Shape(TypeShape(EnumTypeShape.TShape),Position(2,8))
|
||||||
|
//dashBoard.addShape(currentShape)
|
||||||
|
|
||||||
|
//currentShape = Shape(TypeShape(EnumTypeShape.ZShape),Position(2,10))
|
||||||
|
//dashBoard.addShape(currentShape)
|
||||||
|
|
||||||
|
//currentShape = Shape(TypeShape(EnumTypeShape.SShape),Position(1,1))
|
||||||
|
//dashBoard.addShape(currentShape)
|
||||||
|
|
||||||
|
//currentShape = Shape(TypeShape(EnumTypeShape.JShape),Position(1,1))
|
||||||
|
//dashBoard.addShape(currentShape)
|
||||||
|
|
||||||
|
//dashBoard.gridOfGame[2][0] = 5
|
||||||
|
|
||||||
println("RUN !!")
|
println("RUN !!")
|
||||||
dashBoard.updateViewGame()
|
dashBoard.updateViewGame()
|
||||||
|
|
||||||
// Ne pas utiliser de global scope !!!! SA ENLEVE DES POINTS !!!!!!
|
|
||||||
GlobalScope.launch {
|
GlobalScope.launch {
|
||||||
while(true){
|
while (true){
|
||||||
if(dashBoard.fallingShape(currentShape,difficulty)){
|
dashBoard.fallingShape(currentShape)
|
||||||
|
|
||||||
// Clear line
|
|
||||||
val nbLine = dashBoard.clearLines()
|
|
||||||
|
|
||||||
// Score
|
|
||||||
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()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// New shape
|
|
||||||
currentShape = Shape(getNextShape(),Position(width/2,0))
|
|
||||||
if ( !dashBoard.addShape(currentShape)){
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
println("Game end !!")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Binary file not shown.
Loading…
Reference in new issue