|
|
|
@ -3,7 +3,7 @@ package modele
|
|
|
|
|
import views.ViewsGame
|
|
|
|
|
|
|
|
|
|
class DashBoard(private val width: Int,private val height: Int,private val view: ViewsGame) {
|
|
|
|
|
private val gridOfGame = Array(this.height) { IntArray(this.width) }
|
|
|
|
|
val gridOfGame = Array(this.height) { IntArray(this.width) }
|
|
|
|
|
|
|
|
|
|
// Our getter
|
|
|
|
|
fun getWidth(): Int = this.width
|
|
|
|
@ -61,91 +61,110 @@ class DashBoard(private val width: Int,private val height: Int,private val view:
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun addShape(shape: Shape): Boolean {
|
|
|
|
|
when (shape.typeShape.type) {
|
|
|
|
|
EnumTypeShape.IShape -> { // Shape I (la ligne)
|
|
|
|
|
// Mettre ICI des verification ou un try pour les limite du tableau
|
|
|
|
|
|
|
|
|
|
for (line in 0..3) { // On vérifie que l'espace est disponible
|
|
|
|
|
for (column in 0..3) {
|
|
|
|
|
if ((isOccupied(
|
|
|
|
|
shape.position.getX() + column,
|
|
|
|
|
shape.position.getY() + line
|
|
|
|
|
)) and (shape.typeShape.showShape[line][column] == 1)
|
|
|
|
|
) {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (line in 0..3) { // On vérifie que l'espace est disponible
|
|
|
|
|
for (column in 0..3) {
|
|
|
|
|
if ((isOccupied(
|
|
|
|
|
shape.position.x + column,
|
|
|
|
|
shape.position.y + line
|
|
|
|
|
)) and (shape.typeShape.showShape[line][column] == 1)
|
|
|
|
|
) {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
writeShape(shape)
|
|
|
|
|
}
|
|
|
|
|
else -> {
|
|
|
|
|
println("Type de piece incomprehensible !!")
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
writeShape(shape)
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test si c'est possible de l'intégré dans gridOfGame
|
|
|
|
|
private fun moveRightPossible(shape: Shape):Boolean{
|
|
|
|
|
|
|
|
|
|
// ATTENTION ELLE BUG PAS DE COLLISION
|
|
|
|
|
fun moveRight(shape:Shape):Position{
|
|
|
|
|
//Check les limite du tableau à droite !!!! A vérifier que ca marche !!!
|
|
|
|
|
var limiteInitial = width-shape.position.getX()
|
|
|
|
|
var limite:Int = 0
|
|
|
|
|
val pos:MutableList<Position> = shape.sharePositionRight()
|
|
|
|
|
|
|
|
|
|
if (limiteInitial >= 4 ){
|
|
|
|
|
limite = 4
|
|
|
|
|
}else {
|
|
|
|
|
limite = limiteInitial
|
|
|
|
|
for ( position in pos){
|
|
|
|
|
if ( position.x+shape.position.x >= width){
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
if( gridOfGame[position.y+shape.position.y][position.x+shape.position.x] != 0) {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for ( line in 0..limite){ // Check si le décalage est possible
|
|
|
|
|
for ( column in 0..limite){
|
|
|
|
|
if ( column != limite) {
|
|
|
|
|
if ((shape.typeShape.showShape[line][column] == 1)
|
|
|
|
|
and (shape.typeShape.showShape[line][column + 1] == 0)
|
|
|
|
|
and (gridOfGame[shape.position.getX() + line][shape.position.getY() + column + 1] == 1)
|
|
|
|
|
) {
|
|
|
|
|
return shape.position
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
if ( limite == limiteInitial and shape.typeShape.showShape[line][column] == 1){
|
|
|
|
|
return shape.position
|
|
|
|
|
}
|
|
|
|
|
if ((shape.typeShape.showShape[line][column] == 1)
|
|
|
|
|
and (gridOfGame[shape.position.getX() + line][shape.position.getY() + column + 1] == 1)
|
|
|
|
|
) {
|
|
|
|
|
return shape.position
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fun moveRight(shape: Shape):Boolean{
|
|
|
|
|
println("Shape action -> Move Right ! ")
|
|
|
|
|
shape.position.addX()
|
|
|
|
|
if (!moveRightPossible(shape)){
|
|
|
|
|
shape.position.decrementeX()
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
shape.position.decrementeX()
|
|
|
|
|
deleteShape(shape)
|
|
|
|
|
shape.position.addX()
|
|
|
|
|
writeShape(shape)
|
|
|
|
|
return shape.position
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun moveLeft(shape:Shape):Position{
|
|
|
|
|
// Test si c'est possible de l'intégré dans gridOfGame
|
|
|
|
|
private fun moveLeftPossible(shape: Shape):Boolean{
|
|
|
|
|
val pos:MutableList<Position> = shape.sharePositionLeft()
|
|
|
|
|
|
|
|
|
|
// Check if X == 0
|
|
|
|
|
if ( shape.position.getX() == 0 ){
|
|
|
|
|
return shape.position
|
|
|
|
|
}
|
|
|
|
|
for ( position in pos){
|
|
|
|
|
println("X -> : "+position.x)
|
|
|
|
|
println("X -> : "+position.y)
|
|
|
|
|
|
|
|
|
|
for( line in 0..3){
|
|
|
|
|
for( column in 0..3 ){
|
|
|
|
|
if ( column == 0 ){
|
|
|
|
|
if ( (shape.typeShape.showShape[line][column] == 1)
|
|
|
|
|
and (gridOfGame[shape.position.getX()+line][shape.position.getY()+column-1] == 1) ){
|
|
|
|
|
return shape.position
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ( shape.position.x < 0 ){
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
if( gridOfGame[position.y+shape.position.y][position.x+shape.position.x] != 0) {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun moveLeft(shape:Shape):Boolean{
|
|
|
|
|
println("Shape action -> Move Left ! ")
|
|
|
|
|
shape.position.decrementeX()
|
|
|
|
|
if (!moveLeftPossible(shape)){
|
|
|
|
|
shape.position.addX()
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
shape.position.addX()
|
|
|
|
|
deleteShape(shape)
|
|
|
|
|
shape.position.decrementeX()
|
|
|
|
|
writeShape(shape)
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
private fun moveDownPossible(shape: Shape):Boolean{
|
|
|
|
|
|
|
|
|
|
val pos:MutableList<Position> = shape.sharePositionRight()
|
|
|
|
|
|
|
|
|
|
return shape.position
|
|
|
|
|
for ( position in pos){
|
|
|
|
|
if ( position.y+shape.position.y >= height){
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
if( gridOfGame[position.y+shape.position.y][position.x+shape.position.x] != 0) {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun moveDown(shape: Shape):Boolean{
|
|
|
|
|
println("Shape action -> Move down ! ")
|
|
|
|
|
shape.position.addY()
|
|
|
|
|
if (!moveDownPossible(shape)){
|
|
|
|
|
shape.position.decrementeY()
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
shape.position.decrementeY()
|
|
|
|
|
deleteShape(shape)
|
|
|
|
|
shape.position.addY()
|
|
|
|
|
writeShape(shape)
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Delete a shape in gridOfGame
|
|
|
|
@ -153,7 +172,7 @@ class DashBoard(private val width: Int,private val height: Int,private val view:
|
|
|
|
|
for (line in 0..3) {
|
|
|
|
|
for (column in 0..3) {
|
|
|
|
|
if (shape.typeShape.showShape[line][column] == 1) {
|
|
|
|
|
gridOfGame[shape.position.getX() + line][shape.position.getY() + column] = 0
|
|
|
|
|
gridOfGame[shape.position.y + line][shape.position.x + column] = 0
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -161,10 +180,13 @@ class DashBoard(private val width: Int,private val height: Int,private val view:
|
|
|
|
|
|
|
|
|
|
// Write the shape in gridOfGame
|
|
|
|
|
private fun writeShape(shape: Shape){
|
|
|
|
|
println("Final X : "+shape.position.x)
|
|
|
|
|
println("Final Y : "+shape.position.y)
|
|
|
|
|
|
|
|
|
|
for (line in 0..3) {
|
|
|
|
|
for (column in 0..3) {
|
|
|
|
|
if (shape.typeShape.showShape[line][column] == 1) {
|
|
|
|
|
gridOfGame[shape.position.getY() + line][shape.position.getX() + column] =
|
|
|
|
|
gridOfGame[shape.position.y+ line][shape.position.x + column] =
|
|
|
|
|
shape.typeShape.couleur
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|