parent
3406ba8c04
commit
e648c719c2
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
@ -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 {
|
||||
}
|
@ -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
|
||||
|
||||
}
|
@ -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
|
||||
}
|
||||
}
|
@ -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(){
|
||||
|
||||
}*/
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package modele
|
||||
|
||||
enum class TypeShape(private var shape: Array<Position>) {
|
||||
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<Position> = this.shape.copyOf()
|
||||
}
|
@ -1,3 +1,5 @@
|
||||
<resources>
|
||||
<string name="app_name">Tetris</string>
|
||||
<!-- TODO: Remove or change this placeholder text -->
|
||||
<string name="hello_blank_fragment">Hello blank fragment</string>
|
||||
</resources>
|
@ -0,0 +1 @@
|
||||
/build
|
@ -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'
|
||||
}
|
@ -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
|
@ -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)
|
||||
}
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
</manifest>
|
@ -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)
|
||||
}
|
||||
}
|
Loading…
Reference in new issue