diff --git a/Tetris/app/src/main/java/modele/DashBoard.kt b/Tetris/app/src/main/java/modele/DashBoard.kt new file mode 100644 index 0000000..247cb08 --- /dev/null +++ b/Tetris/app/src/main/java/modele/DashBoard.kt @@ -0,0 +1,54 @@ +package modele + +class DashBoard(private val width: Int,private val height: Int) { + private val gridOfGame = Array(this.height){IntArray(this.width)} + + // Our getter + fun getWidth(): Int = this.width + fun getHeight(): Int = this.height + + // To check if an position is occupied + fun isOccupied(col: Int,row: Int): Boolean = gridOfGame[row][col] != 0 + + fun isLineFull(row: Int): Boolean{ + for (col in 0 until this.width){ + if(gridOfGame[row][col] == 0){ + return false + } + } + return true + } + + fun clearLine(row: Int){ + for (col in 0 until this.width){ + gridOfGame[row][col] = 0 + } + } + + fun shiftDown(rowToBegin: Int){ + for (row in (height - 1)..rowToBegin){ + for (col in 0 until this.width){ + gridOfGame[row][col] = gridOfGame[row - rowToBegin][col] + } + } + for (row in 0 until rowToBegin){ + for (col in 0 until this.width){ + gridOfGame[row][col] = 0 + } + } + } + + //To check each grid line and remove if a line is full. Uses clearLine(), isLineFull() and shiftDown() + fun clearLines(){ + var nbRowCleared: Int = 0 + for (row in 0 until this.height){ + if(isLineFull(row)){ + clearLine(row) + ++nbRowCleared + } + } + if(nbRowCleared != 0){ + shiftDown(nbRowCleared) + } + } +} \ No newline at end of file diff --git a/Tetris/app/src/main/java/modele/Draw.kt b/Tetris/app/src/main/java/modele/Draw.kt deleted file mode 100644 index d4cfe30..0000000 --- a/Tetris/app/src/main/java/modele/Draw.kt +++ /dev/null @@ -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 { -} \ No newline at end of file diff --git a/Tetris/app/src/main/java/modele/Game.kt b/Tetris/app/src/main/java/modele/Game.kt new file mode 100644 index 0000000..9aabde3 --- /dev/null +++ b/Tetris/app/src/main/java/modele/Game.kt @@ -0,0 +1,6 @@ +package modele +class Game(private val width: Int,private val height: Int) { + private val dashBoard: DashBoard = DashBoard(width,height) + private val currentShape: Shape? = null + +} \ No newline at end of file diff --git a/Tetris/app/src/main/java/modele/Position.kt b/Tetris/app/src/main/java/modele/Position.kt new file mode 100644 index 0000000..4d8cfad --- /dev/null +++ b/Tetris/app/src/main/java/modele/Position.kt @@ -0,0 +1,14 @@ +package modele + +class Position(private var x: Int,private var y: Int) { + fun getX() = this.x + fun getY() = this.y + + fun setX(newX: Int){ + this.x = newX + } + + fun setY(newY: Int){ + this.y = newY + } +} \ No newline at end of file diff --git a/Tetris/app/src/main/java/modele/Shape.kt b/Tetris/app/src/main/java/modele/Shape.kt new file mode 100644 index 0000000..cff686a --- /dev/null +++ b/Tetris/app/src/main/java/modele/Shape.kt @@ -0,0 +1,23 @@ +package modele + +class Shape(private var x: Int,private var y: Int) { + fun moveRight(){ + this.x += 1 + } + + fun moveLeft(){ + this.x -=1 + } + + fun moveDown(){ + this.y -= 1 + } + + /*fun rotateLeft(){ + + }*/ + + /*fun rotateRight(){ + + }*/ +} \ No newline at end of file diff --git a/Tetris/app/src/main/java/modele/TypeShape.kt b/Tetris/app/src/main/java/modele/TypeShape.kt new file mode 100644 index 0000000..8802b20 --- /dev/null +++ b/Tetris/app/src/main/java/modele/TypeShape.kt @@ -0,0 +1,14 @@ +package modele + +enum class TypeShape(private var shape: Array) { + ZStair(arrayOf(Position(-1, 1), Position(0, 1), Position(0, 0), Position(1, 1))), + SStair(arrayOf(Position(-1,0),Position(0,0),Position(0,1),Position(1,1))), + LRight(arrayOf(Position(-1,0),Position(0,0),Position(0,1),Position(0,2))), + LLeft(arrayOf(Position(0,2),Position(0,1),Position(0,0),Position(1,0))), + TShape(arrayOf(Position(-1,0),Position(0,0),Position(0,-1),Position(1,0))), + IShape(arrayOf(Position(0,0),Position(0,1),Position(0,2),Position(0,3))), + SquareShape(arrayOf(Position(0,0),Position(0,-1),Position(1,-1),Position(1,0))); + + // The getter of the array of position of the enum shape + fun getShape(): Array = this.shape.copyOf() +} \ No newline at end of file diff --git a/Tetris/app/src/main/res/layout/activity_option.xml b/Tetris/app/src/main/res/layout/activity_option.xml index 2fd06b3..e40e7ac 100644 --- a/Tetris/app/src/main/res/layout/activity_option.xml +++ b/Tetris/app/src/main/res/layout/activity_option.xml @@ -6,6 +6,8 @@ android:layout_height="match_parent" tools:context="activity.Menu"> + + Tetris + + Hello blank fragment \ No newline at end of file diff --git a/Tetris/mylibrary/.gitignore b/Tetris/mylibrary/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/Tetris/mylibrary/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/Tetris/mylibrary/build.gradle b/Tetris/mylibrary/build.gradle new file mode 100644 index 0000000..e2b9388 --- /dev/null +++ b/Tetris/mylibrary/build.gradle @@ -0,0 +1,41 @@ +plugins { + id 'com.android.library' + id 'org.jetbrains.kotlin.android' +} + +android { + namespace 'com.example.mylibrary' + compileSdk 33 + + defaultConfig { + minSdk 16 + targetSdk 33 + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + consumerProguardFiles "consumer-rules.pro" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + kotlinOptions { + jvmTarget = '1.8' + } +} + +dependencies { + + implementation 'androidx.core:core-ktx:1.7.0' + implementation 'androidx.appcompat:appcompat:1.6.1' + implementation 'com.google.android.material:material:1.8.0' + testImplementation 'junit:junit:4.13.2' + androidTestImplementation 'androidx.test.ext:junit:1.1.5' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' +} \ No newline at end of file diff --git a/Tetris/mylibrary/consumer-rules.pro b/Tetris/mylibrary/consumer-rules.pro new file mode 100644 index 0000000..e69de29 diff --git a/Tetris/mylibrary/proguard-rules.pro b/Tetris/mylibrary/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/Tetris/mylibrary/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/Tetris/mylibrary/src/androidTest/java/com/example/mylibrary/ExampleInstrumentedTest.kt b/Tetris/mylibrary/src/androidTest/java/com/example/mylibrary/ExampleInstrumentedTest.kt new file mode 100644 index 0000000..9bc1b73 --- /dev/null +++ b/Tetris/mylibrary/src/androidTest/java/com/example/mylibrary/ExampleInstrumentedTest.kt @@ -0,0 +1,24 @@ +package com.example.mylibrary + +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.ext.junit.runners.AndroidJUnit4 + +import org.junit.Test +import org.junit.runner.RunWith + +import org.junit.Assert.* + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getInstrumentation().targetContext + assertEquals("com.example.mylibrary.test", appContext.packageName) + } +} \ No newline at end of file diff --git a/Tetris/mylibrary/src/main/AndroidManifest.xml b/Tetris/mylibrary/src/main/AndroidManifest.xml new file mode 100644 index 0000000..a5918e6 --- /dev/null +++ b/Tetris/mylibrary/src/main/AndroidManifest.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Tetris/mylibrary/src/test/java/com/example/mylibrary/ExampleUnitTest.kt b/Tetris/mylibrary/src/test/java/com/example/mylibrary/ExampleUnitTest.kt new file mode 100644 index 0000000..e9c2e27 --- /dev/null +++ b/Tetris/mylibrary/src/test/java/com/example/mylibrary/ExampleUnitTest.kt @@ -0,0 +1,17 @@ +package com.example.mylibrary + +import org.junit.Test + +import org.junit.Assert.* + +/** + * Example local unit test, which will execute on the development machine (host). + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +class ExampleUnitTest { + @Test + fun addition_isCorrect() { + assertEquals(4, 2 + 2) + } +} \ No newline at end of file diff --git a/Tetris/settings.gradle b/Tetris/settings.gradle index 0b3e1b8..19ebe97 100644 --- a/Tetris/settings.gradle +++ b/Tetris/settings.gradle @@ -14,3 +14,4 @@ dependencyResolutionManagement { } rootProject.name = "Tetris" include ':app' +include ':mylibrary'