ajout modèle

pull/5/head
Alexis1663 2 years ago
parent e648c719c2
commit 1f89f63222

@ -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'

@ -29,6 +29,12 @@
<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>
</manifest>

@ -5,6 +5,7 @@ import android.os.Bundle
import android.widget.ImageView
import androidx.core.content.ContextCompat
import but.androidstudio.tetris.R
import modele.Game
class Game : AppCompatActivity() {
@ -13,5 +14,11 @@ class Game : AppCompatActivity() {
setContentView(R.layout.activity_game)
}
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()
}
}

@ -18,7 +18,7 @@ class Option : AppCompatActivity() {
super.onResume()
val spinnerDifficulty:Spinner = findViewById(R.id.spinnerDifficulty)
val difficulty = arrayOf("Facile","Intermédiaire","Difficile")
val difficulty = arrayOf("Easy","Medium","Hard")
val adaptateurSpinnerDifficulty = ArrayAdapter(this,android.R.layout.simple_spinner_dropdown_item,difficulty)
spinnerDifficulty.adapter = adaptateurSpinnerDifficulty

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

@ -7,6 +7,12 @@ class DashBoard(private val width: Int,private val height: Int) {
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

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

@ -0,0 +1,10 @@
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,5 @@
package modele
enum class EnumTypeShape {
IShape,SquareShape,TShape,LShape,JShape,ZShape,SShape
}

@ -1,6 +1,25 @@
package modele
class Game(private val width: Int,private val height: Int) {
private val dashBoard: DashBoard = DashBoard(width,height)
private val currentShape: Shape? = null
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)
}
}

@ -1,23 +1,41 @@
package modele
class Shape(private var x: Int,private var y: Int) {
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.x += 1
this.position.setX(this.position.getX()+1)
//update
}
fun moveLeft(){
this.x -=1
this.position.setX(this.position.getX()-1)
//update
}
fun moveDown(){
this.y -= 1
this.position.setY(this.position.getY()-1)
//update
}
/*fun rotateLeft(){
}*/
/*fun rotateRight(){
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
}
}

@ -1,14 +1,48 @@
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()
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]
}
}

@ -1,13 +1,12 @@
<?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="activity.Menu">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"

@ -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="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>

@ -0,0 +1,4 @@
package modele
class Draw {
}
Loading…
Cancel
Save