Fusion des branch Alexis et Enzo dans Master

pull/10/head
Alexis1663 2 years ago
commit b8fdda7767

File diff suppressed because it is too large Load Diff

@ -11,6 +11,7 @@
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/app" />
<option value="$PROJECT_DIR$/mylibrary" />
</set>
</option>
</GradleProjectSettings>

@ -38,6 +38,7 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.8.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.fragment:fragment:1.5.5'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'

@ -21,6 +21,28 @@
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<activity android:name="activity.Menu" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name="activity.Game" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name="activity.Option" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name="activity.MainActivity" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>

@ -0,0 +1,21 @@
package but.androidstudio.tetris
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
class MainFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
}
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_main, container, false)
}
}

@ -0,0 +1,59 @@
package but.androidstudio.tetris
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private const val ARG_PARAM1 = "param1"
private const val ARG_PARAM2 = "param2"
/**
* A simple [Fragment] subclass.
* Use the [OptionFragment.newInstance] factory method to
* create an instance of this fragment.
*/
class OptionFragment : Fragment() {
// TODO: Rename and change types of parameters
private var param1: String? = null
private var param2: String? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
arguments?.let {
param1 = it.getString(ARG_PARAM1)
param2 = it.getString(ARG_PARAM2)
}
}
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_option, container, false)
}
companion object {
/**
* Use this factory method to create a new instance of
* this fragment using the provided parameters.
*
* @param param1 Parameter 1.
* @param param2 Parameter 2.
* @return A new instance of fragment OptionFragment.
*/
// TODO: Rename and change types and number of parameters
@JvmStatic
fun newInstance(param1: String, param2: String) =
OptionFragment().apply {
arguments = Bundle().apply {
putString(ARG_PARAM1, param1)
putString(ARG_PARAM2, param2)
}
}
}
}

@ -0,0 +1,60 @@
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 set something to occupied
fun toOccupied(col: Int,row: Int){
gridOfGame[row][col] = 1
}
// 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)
}
}
}

@ -0,0 +1,7 @@
package modele
enum class Difficulty {
EASY,
MEDIUM,
HARD
}

@ -0,0 +1,5 @@
package modele
enum class EnumTypeShape {
IShape,SquareShape,TShape,LShape,JShape,ZShape,SShape
}

@ -0,0 +1,25 @@
package modele
class Game(private val width: Int,private val height: Int) {
private val dashBoard: DashBoard = DashBoard(width,height)
private var currentShape: Shape? = null
private var difficulty: Difficulty = Difficulty.EASY
// To get the current difficulty
fun getDifficulty(): Difficulty = this.difficulty
// To get the current shape on the game
fun getCurrentShape(): Shape? = this.currentShape
// To set the current shape
fun setCurrentShape(newCurrentShape: Shape){
this.currentShape = newCurrentShape
}
// The start game function
fun startGame(){
//this.setCurrentShape(TypeShape.SquareShape)
}
}

@ -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,41 @@
package modele
import java.lang.reflect.Type
class Shape(private val typeShape: TypeShape,private var position: Position) {
private var shapePosition : Array<Position> = emptyArray()
/* init {
val
}*/
fun moveRight(){
this.position.setX(this.position.getX()+1)
//update
}
fun moveLeft(){
this.position.setX(this.position.getX()-1)
//update
}
fun moveDown(){
this.position.setY(this.position.getY()-1)
//update
}
fun rotateLeft(){
val tmp = this.position.getX()
this.position.setX(this.position.getY() * -1)
this.position.setY(tmp)
//update
}
fun rotateRight(){
val tmp = this.position.getX()
this.position.setX(this.position.getY())
this.position.setY(tmp * -1)
//update
}
}

@ -0,0 +1,48 @@
package modele
import java.lang.reflect.Type
import kotlin.random.Random
class TypeShape(private val type: EnumTypeShape,private val showShape: Array<Array<Array<Int>>>){
private var currentIndex = 0
fun getPoints(): Array<Position>{
val positions = ArrayList<Position>()
val typeShape = getCurrentType()
for (i in typeShape.indices){
for (j in typeShape[i].indices){
if (typeShape[i][j] != 0) {
positions.add(Position(j, i))
}
}
}
return positions.toTypedArray()
}
//to augmente of 1 the current index
fun getNextType(): TypeShape {
currentIndex++
return this
}
//To get the next shape
fun getNextShape(){
val random: Int = Random.nextInt(1,7)
when(random){
1 -> TypeShape(EnumTypeShape.IShape, arrayOf(arrayOf(arrayOf())))
2 -> TypeShape(EnumTypeShape.SquareShape, arrayOf(arrayOf(arrayOf())))
3 -> TypeShape(EnumTypeShape.JShape, arrayOf(arrayOf(arrayOf())))
4 -> TypeShape(EnumTypeShape.LShape, arrayOf(arrayOf(arrayOf())))
5 -> TypeShape(EnumTypeShape.SShape, arrayOf(arrayOf(arrayOf())))
6 -> TypeShape(EnumTypeShape.TShape, arrayOf(arrayOf(arrayOf())))
7 -> TypeShape(EnumTypeShape.ZShape, arrayOf(arrayOf(arrayOf())))
else -> throw Exception("Problème de random getNextShape()")
}
}
// To get the table of position of the current shape type
private fun getCurrentType(): Array<Array<Int>> {
return showShape[currentIndex]
}
}

@ -8,6 +8,7 @@ import android.widget.ImageView
import androidx.core.content.ContextCompat
import but.androidstudio.tetris.R
import tetrisGame.views.ViewsGame
import modele.Game
class Game : AppCompatActivity() {
@ -23,4 +24,11 @@ class Game : AppCompatActivity() {
}
override fun onResume() {
super.onResume()
val myGame: modele.Game = Game(10,20)
myGame.startGame()
}
}

@ -0,0 +1,26 @@
package activity
import android.os.Bundle
import android.os.PersistableBundle
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.FragmentContainerView
import but.androidstudio.tetris.MainFragment
import but.androidstudio.tetris.R
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.main_activity)
if(savedInstanceState == null){
supportFragmentManager.beginTransaction()
.setReorderingAllowed(true)
.add(R.id.homeLayout,MainFragment())
.commit()
}
}
override fun onResume() {
super.onResume()
}
}

@ -14,11 +14,21 @@ class Menu : AppCompatActivity() {
val appName:TextView = findViewById(R.id.appName)
appName.setText(R.string.app_name)
}
override fun onResume() {
super.onResume()
val buttonStart:Button = findViewById(R.id.buttonStart)
buttonStart.setOnClickListener {
val intent = Intent(this, Game::class.java)
startActivity(intent)
val intentStart = Intent(this,Game::class.java)
startActivity(intentStart)
}
val buttonOption:Button = findViewById(R.id.buttonOption)
buttonOption.setOnClickListener {
val intentOption = Intent(this,Option::class.java)
startActivity(intentOption)
}
}
}

@ -1,13 +1,38 @@
package tetrisGame.activity
package activity
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.AdapterView
import android.widget.ArrayAdapter
import android.widget.Spinner
import androidx.appcompat.app.AppCompatActivity
import but.androidstudio.tetris.R
class Option : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_option)
}
override fun onResume() {
super.onResume()
val spinnerDifficulty:Spinner = findViewById(R.id.spinnerDifficulty)
val difficulty = arrayOf("Easy","Medium","Hard")
val adaptateurSpinnerDifficulty = ArrayAdapter(this,android.R.layout.simple_spinner_dropdown_item,difficulty)
spinnerDifficulty.adapter = adaptateurSpinnerDifficulty
spinnerDifficulty.setOnItemSelectedListener(object : AdapterView.OnItemSelectedListener {
override fun onItemSelected(parent: AdapterView<*>, view: View?, position: Int, id: Long) {
val selectedItem = parent.getItemAtPosition(position).toString()
// Faites quelque chose avec l'élément sélectionné
}
override fun onNothingSelected(parent: AdapterView<*>) {
// Ne rien faire si aucun élément n'est sélectionné
}
})
}

@ -1,9 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<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"
tools:context="tetrisGame.activity.Option">
tools:context="activity.Menu">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.5">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Difficulty"/>
<Spinner
android:id="@+id/spinnerDifficulty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="1mm"
/>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

@ -1,10 +1,10 @@
<?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"
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="tetrisGame.activity.Menu">
tools:context=".MainFragment">
<LinearLayout
android:layout_width="wrap_content"
@ -53,4 +53,5 @@
android:text="X" />
</LinearLayout>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</FrameLayout>

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".OptionFragment">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.5">
<Button
android:id="@+id/backButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Retour"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Difficulty"/>
<Spinner
android:id="@+id/spinnerDifficulty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="1mm"
/>
</LinearLayout>
</FrameLayout>

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.fragment.app.FragmentContainerView
android:id="@+id/homeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>

@ -1,4 +1,6 @@
<resources>
<string name="app_name">Tetris</string>
<string name="TextScore">Score : ??</string>
<!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string>
</resources>

@ -0,0 +1,4 @@
package modele
class Draw {
}

@ -1,6 +1,6 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.4.0' apply false
id 'com.android.library' version '7.4.0' apply false
id 'com.android.application' version '7.4.1' apply false
id 'com.android.library' version '7.4.1' apply false
id 'org.jetbrains.kotlin.android' version '1.7.21' apply false
}

@ -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)
}
}

@ -14,3 +14,4 @@ dependencyResolutionManagement {
}
rootProject.name = "Tetris"
include ':app'
include ':mylibrary'

Loading…
Cancel
Save