parent
e648c719c2
commit
1f89f63222
@ -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()
|
||||
}
|
||||
}
|
@ -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,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]
|
||||
}
|
||||
}
|
@ -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…
Reference in new issue