@ -1,10 +0,0 @@
|
||||
package modele
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.graphics.Paint
|
||||
import android.graphics.Path
|
||||
import android.view.View
|
||||
|
||||
class Draw {
|
||||
}
|
@ -1,17 +1,26 @@
|
||||
package activity
|
||||
package tetrisGame.activity
|
||||
|
||||
import android.graphics.Canvas
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.widget.ImageView
|
||||
import androidx.core.content.ContextCompat
|
||||
import but.androidstudio.tetris.R
|
||||
import tetrisGame.views.ViewsGame
|
||||
|
||||
class Game : AppCompatActivity() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
setContentView(R.layout.activity_game)
|
||||
}
|
||||
|
||||
val view = findViewById<ViewsGame>(R.id.tabGame)
|
||||
|
||||
//Pour nettoyer la vue
|
||||
view.invalidate()
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package activity
|
||||
package tetrisGame.activity
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import android.os.Bundle
|
@ -0,0 +1,104 @@
|
||||
package tetrisGame.views
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Color
|
||||
import android.graphics.Paint
|
||||
import android.graphics.Rect
|
||||
import android.util.AttributeSet
|
||||
import android.view.View
|
||||
|
||||
class ViewsGame(context:Context, attrs: AttributeSet?) : View(context, attrs) {
|
||||
|
||||
val myPaint:Paint = Paint()
|
||||
|
||||
override fun onDraw(canvas: Canvas) {
|
||||
super.onDraw(canvas)
|
||||
|
||||
val tailleGrille:Float = 5F
|
||||
val tailleTableauHauteur:Float = measuredHeight.toFloat()
|
||||
val tailleTableauLargeur:Float = measuredWidth.toFloat()
|
||||
val nbCaseLargeur:Int = 7
|
||||
val nbCaseHauteur:Int = 15
|
||||
|
||||
// Pour remplir le tableau de zero ( a enlever)
|
||||
var tableau = arrayOf<Array<Int>>()
|
||||
for (i in 0 until nbCaseHauteur) {
|
||||
var array = arrayOf<Int>()
|
||||
for (j in 0 until nbCaseLargeur) {
|
||||
array += 0
|
||||
}
|
||||
tableau += array
|
||||
}
|
||||
|
||||
// Test
|
||||
// Droite
|
||||
tableau[0][0] = 1
|
||||
tableau[1][0] = 1
|
||||
tableau[2][0] = 1
|
||||
tableau[3][0] = 1
|
||||
// Carré
|
||||
tableau[0][2] = 4
|
||||
tableau[0][3] = 4
|
||||
tableau[1][2] = 4
|
||||
tableau[1][3] = 4
|
||||
// T
|
||||
tableau[0][5] = 3
|
||||
tableau[1][5] = 3
|
||||
tableau[1][4] = 3
|
||||
tableau[1][6] = 3
|
||||
// L Gauche
|
||||
tableau[2][2] = 5
|
||||
tableau[3][2] = 5
|
||||
tableau[2][3] = 5
|
||||
tableau[2][4] = 5
|
||||
// L Droite
|
||||
tableau[4][4] = 6
|
||||
tableau[4][5] = 6
|
||||
tableau[4][6] = 6
|
||||
tableau[5][6] = 6
|
||||
// Escalier Droite
|
||||
tableau[4][3] = 2
|
||||
tableau[4][2] = 2
|
||||
tableau[5][2] = 2
|
||||
tableau[5][1] = 2
|
||||
// Escalier Gauche
|
||||
tableau[6][3] = 7
|
||||
tableau[6][4] = 7
|
||||
tableau[7][4] = 7
|
||||
tableau[7][5] = 7
|
||||
|
||||
myPaint.color = Color.GRAY
|
||||
canvas.drawRect(0F,0F,tailleTableauLargeur,tailleTableauHauteur,myPaint)
|
||||
// Color
|
||||
myPaint.color = Color.BLACK
|
||||
|
||||
//Contour
|
||||
myPaint.strokeWidth = 15F
|
||||
canvas.drawLine(0F,0F,0F,tailleTableauHauteur,myPaint)
|
||||
canvas.drawLine(0F,0F,tailleTableauLargeur,0F,myPaint)
|
||||
canvas.drawLine(tailleTableauLargeur,0F,tailleTableauLargeur,tailleTableauHauteur,myPaint)
|
||||
canvas.drawLine(0F,tailleTableauHauteur,tailleTableauLargeur,tailleTableauHauteur,myPaint)
|
||||
|
||||
for( ligne in 0 until nbCaseHauteur){
|
||||
for ( value in 0 until nbCaseLargeur){
|
||||
myPaint.color = Color.GRAY
|
||||
when(tableau[ligne][value]){
|
||||
1 -> myPaint.color = Color.CYAN
|
||||
2 -> myPaint.color = Color.RED
|
||||
3 -> myPaint.color = Color.GREEN
|
||||
4 -> myPaint.color = Color.BLUE
|
||||
5 -> myPaint.color = Color.WHITE
|
||||
6 -> myPaint.color = Color.YELLOW
|
||||
7 -> myPaint.color = Color.MAGENTA
|
||||
}
|
||||
canvas.drawRect((tailleTableauLargeur/nbCaseLargeur)*value+tailleGrille,
|
||||
(tailleTableauHauteur/nbCaseHauteur)*ligne+tailleGrille,
|
||||
(tailleTableauLargeur-((tailleTableauLargeur/nbCaseLargeur)*((nbCaseLargeur-value)-1)))-tailleGrille,
|
||||
(tailleTableauHauteur-((tailleTableauHauteur/nbCaseHauteur)*((nbCaseHauteur-ligne)-1)))-tailleGrille,
|
||||
myPaint)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="oval">
|
||||
|
||||
<solid android:color="@color/white"/>
|
||||
|
||||
|
||||
</shape>-->
|
||||
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item>
|
||||
<shape android:shape="oval">
|
||||
<solid android:color="@color/white"/>
|
||||
</shape>
|
||||
</item>
|
||||
<item
|
||||
android:drawable="@drawable/flechedroite"
|
||||
android:bottom="20dp"
|
||||
android:left="20dp"
|
||||
android:right="20dp"
|
||||
android:top="20dp"/>
|
||||
</layer-list>
|
@ -0,0 +1,5 @@
|
||||
<vector android:autoMirrored="true" android:height="24dp"
|
||||
android:tint="#000000" android:viewportHeight="24"
|
||||
android:viewportWidth="24" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@android:color/white" android:pathData="M12,4l-1.41,1.41L16.17,11H4v2h12.17l-5.58,5.59L12,20l8,-8z"/>
|
||||
</vector>
|
@ -0,0 +1,5 @@
|
||||
<vector android:autoMirrored="true" android:height="24dp"
|
||||
android:tint="#000000" android:viewportHeight="24"
|
||||
android:viewportWidth="24" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@android:color/white" android:pathData="M20,11H7.83l5.59,-5.59L12,4l-8,8 8,8 1.41,-1.41L7.83,13H20v-2z"/>
|
||||
</vector>
|
@ -0,0 +1,5 @@
|
||||
<vector android:autoMirrored="true" android:height="24dp"
|
||||
android:tint="#000000" android:viewportHeight="24"
|
||||
android:viewportWidth="24" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@android:color/white" android:pathData="M15.55,5.55L11,1v3.07C7.06,4.56 4,7.92 4,12s3.05,7.44 7,7.93v-2.02c-2.84,-0.48 -5,-2.94 -5,-5.91s2.16,-5.43 5,-5.91L11,10l4.55,-4.45zM19.93,11c-0.17,-1.39 -0.72,-2.73 -1.62,-3.89l-1.42,1.42c0.54,0.75 0.88,1.6 1.02,2.47h2.02zM13,17.9v2.02c1.39,-0.17 2.74,-0.71 3.9,-1.61l-1.44,-1.44c-0.75,0.54 -1.59,0.89 -2.46,1.03zM16.89,15.48l1.42,1.41c0.9,-1.16 1.45,-2.5 1.62,-3.89h-2.02c-0.14,0.87 -0.48,1.72 -1.02,2.48z"/>
|
||||
</vector>
|
@ -0,0 +1,5 @@
|
||||
<vector android:autoMirrored="true" android:height="24dp"
|
||||
android:tint="#000000" android:viewportHeight="24"
|
||||
android:viewportWidth="24" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@android:color/white" android:pathData="M7.11,8.53L5.7,7.11C4.8,8.27 4.24,9.61 4.07,11h2.02c0.14,-0.87 0.49,-1.72 1.02,-2.47zM6.09,13L4.07,13c0.17,1.39 0.72,2.73 1.62,3.89l1.41,-1.42c-0.52,-0.75 -0.87,-1.59 -1.01,-2.47zM7.1,18.32c1.16,0.9 2.51,1.44 3.9,1.61L11,17.9c-0.87,-0.15 -1.71,-0.49 -2.46,-1.03L7.1,18.32zM13,4.07L13,1L8.45,5.55 13,10L13,6.09c2.84,0.48 5,2.94 5,5.91s-2.16,5.43 -5,5.91v2.02c3.95,-0.49 7,-3.85 7,-7.93s-3.05,-7.44 -7,-7.93z"/>
|
||||
</vector>
|
@ -1,34 +1,75 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
tools:context="activity.Game"
|
||||
>
|
||||
|
||||
<GridLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:columnCount="10"
|
||||
android:rowCount="20"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tilePageGame"
|
||||
android:layout_width="wrap_content"
|
||||
tools:context="tetrisGame.activity.Game"
|
||||
android:background="@color/white">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:layout_marginLeft="15dp"
|
||||
android:layout_marginTop="15dp"
|
||||
android:layout_marginRight="15dp">
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="250dp"
|
||||
android:layout_height="450dp">
|
||||
|
||||
<tetrisGame.views.ViewsGame
|
||||
android:id="@+id/tabGame"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
</FrameLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="TextView"
|
||||
android:layout_row="0"
|
||||
android:layout_column="0"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginTop="2mm"
|
||||
/>
|
||||
android:orientation="horizontal"
|
||||
android:layout_marginTop="50dp">
|
||||
|
||||
<Button
|
||||
android:id="@+id/Button_Left"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="100dp"
|
||||
android:background="@drawable/flechegauche"
|
||||
android:layout_marginStart="15dp"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/Button_Right"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="100dp"
|
||||
android:background="@drawable/flechedroite"
|
||||
android:layout_marginStart="150dp"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="horizontal"
|
||||
android:layout_marginTop="15dp">
|
||||
|
||||
<Button
|
||||
android:id="@+id/Button_Left_Rotation"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="100dp"
|
||||
android:background="@drawable/rotationgauche"
|
||||
android:layout_marginStart="50dp"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/Button_Right_Rotation"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="100dp"
|
||||
android:background="@drawable/rotationdroite"
|
||||
android:layout_marginStart="75dp"/>
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
</GridLayout>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
@ -1,3 +1,4 @@
|
||||
<resources>
|
||||
<string name="app_name">Tetris</string>
|
||||
<string name="TextScore">Score : ??</string>
|
||||
</resources>
|
Loading…
Reference in new issue