parent
24011493ad
commit
d791327b73
@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="deploymentTargetDropDown">
|
||||||
|
<runningDeviceTargetSelectedWithDropDown>
|
||||||
|
<Target>
|
||||||
|
<type value="RUNNING_DEVICE_TARGET" />
|
||||||
|
<deviceKey>
|
||||||
|
<Key>
|
||||||
|
<type value="SERIAL_NUMBER" />
|
||||||
|
<value value="2208661a3b057ece" />
|
||||||
|
</Key>
|
||||||
|
</deviceKey>
|
||||||
|
</Target>
|
||||||
|
</runningDeviceTargetSelectedWithDropDown>
|
||||||
|
<timeTargetWasSelectedWithDropDown value="2023-03-10T23:31:57.060360300Z" />
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -1,59 +1,127 @@
|
|||||||
package com.example.shakecraft
|
package com.example.shakecraft
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Context.SENSOR_SERVICE
|
||||||
|
import android.content.pm.ActivityInfo
|
||||||
|
import android.hardware.Sensor
|
||||||
|
import android.hardware.SensorEvent
|
||||||
|
import android.hardware.SensorEventListener
|
||||||
|
import android.hardware.SensorManager
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.os.Vibrator
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import android.view.animation.AlphaAnimation
|
||||||
|
import android.widget.ImageView
|
||||||
|
import android.widget.ProgressBar
|
||||||
|
import android.widget.TextView
|
||||||
|
import androidx.core.content.ContextCompat.getSystemService
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import com.example.shakecraft.data.Stub
|
||||||
|
import com.example.shakecraft.model.GeneratorLoot
|
||||||
|
import com.example.shakecraft.model.Player
|
||||||
|
import com.example.shakecraft.view.adapter.AdapterInventory
|
||||||
|
import kotlin.math.pow
|
||||||
|
import kotlin.math.sqrt
|
||||||
|
|
||||||
// TODO: Rename parameter arguments, choose names that match
|
|
||||||
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
|
class CollectFragment(var player: Player) : Fragment() {
|
||||||
private const val ARG_PARAM1 = "param1"
|
var stubdata = Stub().load();
|
||||||
private const val ARG_PARAM2 = "param2"
|
private lateinit var sensorManager: SensorManager
|
||||||
|
private lateinit var accelerometer: Sensor
|
||||||
/**
|
private lateinit var accelerometerEventListener: SensorEventListener
|
||||||
* A simple [Fragment] subclass.
|
private lateinit var progressBar: ProgressBar
|
||||||
* Use the [CollectFragment.newInstance] factory method to
|
|
||||||
* create an instance of this fragment.
|
|
||||||
*/
|
|
||||||
class CollectFragment : Fragment() {
|
|
||||||
// TODO: Rename and change types of parameters
|
|
||||||
private var param1: String? = null
|
|
||||||
private var param2: String? = null
|
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
arguments?.let {
|
|
||||||
param1 = it.getString(ARG_PARAM1)
|
|
||||||
param2 = it.getString(ARG_PARAM2)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateView(
|
override fun onCreateView(
|
||||||
inflater: LayoutInflater, container: ViewGroup?,
|
inflater: LayoutInflater, container: ViewGroup?,
|
||||||
savedInstanceState: Bundle?
|
savedInstanceState: Bundle?
|
||||||
): View? {
|
): View? {
|
||||||
// Inflate the layout for this fragment
|
// Récupérez une référence à la ProgressBar dans la vue
|
||||||
return inflater.inflate(R.layout.fragment_collect, container, false)
|
val view = inflater.inflate(R.layout.fragment_collect, container, false)
|
||||||
}
|
|
||||||
|
progressBar = view.findViewById(R.id.progressBar)
|
||||||
companion object {
|
sensorManager = requireActivity().getSystemService(Context.SENSOR_SERVICE) as SensorManager
|
||||||
/**
|
accelerometer = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER)
|
||||||
* Use this factory method to create a new instance of
|
|
||||||
* this fragment using the provided parameters.
|
// Créez un écouteur de capteur d'accéléromètre pour écouter les secousses
|
||||||
*
|
accelerometerEventListener = object : SensorEventListener {
|
||||||
* @param param1 Parameter 1.
|
override fun onAccuracyChanged(sensor: Sensor?, accuracy: Int) {
|
||||||
* @param param2 Parameter 2.
|
// Ne faites rien ici
|
||||||
* @return A new instance of fragment CollectFragment.
|
}
|
||||||
*/
|
|
||||||
// TODO: Rename and change types and number of parameters
|
@SuppressLint("ServiceCast")
|
||||||
@JvmStatic
|
override fun onSensorChanged(event: SensorEvent?) {
|
||||||
fun newInstance(param1: String, param2: String) =
|
val acceleration = sqrt(
|
||||||
CollectFragment().apply {
|
event!!.values[0].pow(2) + event.values[1].pow(2) + event.values[2].pow(2)
|
||||||
arguments = Bundle().apply {
|
)
|
||||||
putString(ARG_PARAM1, param1)
|
if(progressBar.progress == 100){
|
||||||
putString(ARG_PARAM2, param2)
|
val vibrator = context?.getSystemService(Context.VIBRATOR_SERVICE) as Vibrator
|
||||||
|
vibrator.vibrate(100)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
val item = GeneratorLoot.generateLootCollection();
|
||||||
|
println(item);
|
||||||
|
|
||||||
|
val maVue = view.findViewById<View>(R.id.toast)
|
||||||
|
val image = maVue.findViewById<ImageView>(R.id.imageViewLoot)
|
||||||
|
val name = maVue.findViewById<TextView>(R.id.nameLoot)
|
||||||
|
val xp = maVue.findViewById<TextView>(R.id.xpRewarded)
|
||||||
|
maVue.visibility = View.VISIBLE
|
||||||
|
val fadeIn = AlphaAnimation(0f, 1f)
|
||||||
|
fadeIn.duration = 200
|
||||||
|
maVue.startAnimation(fadeIn)
|
||||||
|
maVue.postDelayed({
|
||||||
|
maVue.visibility = View.GONE
|
||||||
|
image.setImageResource(item.image)
|
||||||
|
name.text = item.name
|
||||||
|
|
||||||
|
}, 3000)
|
||||||
|
|
||||||
|
|
||||||
|
player.addItem(item);
|
||||||
|
progressBar.progress = 0;
|
||||||
|
}
|
||||||
|
if (acceleration > 40) {
|
||||||
|
// Le téléphone a été secoué, mettre à jour la barre de chargement ici
|
||||||
|
progressBar.progress += (acceleration/20).toInt() // Incrémente la progression de la barre de 10 unités
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Enregistrez l'écouteur de capteur d'accéléromètre
|
||||||
|
sensorManager.registerListener(
|
||||||
|
accelerometerEventListener,
|
||||||
|
accelerometer,
|
||||||
|
SensorManager.SENSOR_DELAY_GAME
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
// Retournez la vue de fragment
|
||||||
|
return view
|
||||||
}
|
}
|
||||||
|
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||||
|
super.onActivityCreated(savedInstanceState)
|
||||||
|
|
||||||
|
val activity = requireActivity()
|
||||||
|
activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
|
||||||
|
}
|
||||||
|
override fun onDestroy() {
|
||||||
|
super.onDestroy()
|
||||||
|
|
||||||
|
// Désenregistrez l'écouteur de capteur d'accéléromètre lorsque le fragment est détruit
|
||||||
|
sensorManager.unregisterListener(accelerometerEventListener)
|
||||||
|
val activity = requireActivity()
|
||||||
|
activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,17 +1,22 @@
|
|||||||
package com.example.shakecraft.data
|
package com.example.shakecraft.data
|
||||||
|
|
||||||
|
import com.example.shakecraft.R
|
||||||
import com.example.shakecraft.model.Item
|
import com.example.shakecraft.model.Item
|
||||||
|
import com.example.shakecraft.model.Player
|
||||||
|
|
||||||
|
|
||||||
class Stub {
|
class Stub {
|
||||||
|
|
||||||
fun load() : List<Item>{
|
fun load() : List<Item>{
|
||||||
val items : MutableList<Item> = mutableListOf<Item>()
|
val items : MutableList<Item> = mutableListOf<Item>()
|
||||||
items.add(Item(name = "Beech Log", rarity = 0, stack = 1));
|
items.add(Item(name = "Beech Log", rarity = 0, stack = 1, R.drawable.ic_anvil));
|
||||||
items.add(Item(name = "Bronze Ore", rarity = 0, stack = 1));
|
items.add(Item(name = "Bronze Ore", rarity = 0, stack = 1, R.drawable.ic_anvil));
|
||||||
items.add(Item(name = "Iron Ore", rarity = 0, stack = 1));
|
items.add(Item(name = "Iron Ore", rarity = 0, stack = 1, R.drawable.ic_anvil));
|
||||||
items.add(Item(name = "Diamond", rarity = 0, stack = 1));
|
items.add(Item(name = "Diamond", rarity = 0, stack = 1, R.drawable.ic_anvil));
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
var currentPlayer : Player = Player("Winker",0);
|
||||||
|
|
||||||
}
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
package com.example.shakecraft.model
|
||||||
|
|
||||||
|
import com.example.shakecraft.R
|
||||||
|
import kotlin.random.Random
|
||||||
|
|
||||||
|
class GeneratorLoot {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun generateLootCollection(): Item {
|
||||||
|
val possibleLoot: List<Pair<Item, Double>> = listOf(
|
||||||
|
Pair(Item(name = "Beech Log", rarity = 0, stack = 1, R.drawable.log2), 0.6),
|
||||||
|
Pair(Item(name = "Bronze Ore", rarity = 0, stack = 1, R.drawable.bronze_ore), 0.25),
|
||||||
|
Pair(Item(name = "Iron Ore", rarity = 0, stack = 1, R.drawable.iron_ore), 0.10),
|
||||||
|
Pair(Item(name = "Diamond", rarity = 0, stack = 1, R.drawable.diamond), 0.05),
|
||||||
|
)
|
||||||
|
val rand = Random.nextDouble()
|
||||||
|
|
||||||
|
var cumulativeProb = 0.0
|
||||||
|
for (element in possibleLoot) {
|
||||||
|
cumulativeProb += element.second
|
||||||
|
if (rand < cumulativeProb) {
|
||||||
|
return element.first
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Si aucun élément n'a été choisi, retourner le dernier élément de la liste
|
||||||
|
return possibleLoot.last().first
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,9 +1,12 @@
|
|||||||
package com.example.shakecraft.model
|
package com.example.shakecraft.model
|
||||||
|
|
||||||
|
import android.media.Image
|
||||||
|
|
||||||
data class Item(
|
data class Item(
|
||||||
var name: String,
|
var name: String,
|
||||||
var rarity: Int,
|
var rarity: Int,
|
||||||
var stack: Int,
|
var stack: Int,
|
||||||
|
var image: Int,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -0,0 +1,32 @@
|
|||||||
|
package com.example.shakecraft.model
|
||||||
|
|
||||||
|
class Player(val pseudo: String, var xp: Int = 0) {
|
||||||
|
var level: Int = 1
|
||||||
|
private set
|
||||||
|
|
||||||
|
val items: MutableList<Item> = mutableListOf()
|
||||||
|
|
||||||
|
fun addItem(item: Item) {
|
||||||
|
var findItem = items.find { it.name == item.name }
|
||||||
|
if(findItem!= null){
|
||||||
|
findItem.stack += 1;
|
||||||
|
}
|
||||||
|
else{items.add(item)}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun removeItem(item: Item) {
|
||||||
|
items.remove(item)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun increaseXp(amount: Int) {
|
||||||
|
xp += amount
|
||||||
|
if (xp >= 100 * level) {
|
||||||
|
levelUp()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun levelUp() {
|
||||||
|
level++
|
||||||
|
println("$pseudo a atteint le niveau $level !")
|
||||||
|
}
|
||||||
|
}
|
After Width: | Height: | Size: 2.0 KiB |
After Width: | Height: | Size: 2.4 KiB |
After Width: | Height: | Size: 2.0 KiB |
@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<solid android:color="@color/black_800"/>
|
||||||
|
<corners
|
||||||
|
android:topLeftRadius="5dp"
|
||||||
|
android:topRightRadius="5dp"
|
||||||
|
android:bottomLeftRadius="5dp"
|
||||||
|
android:bottomRightRadius="5dp"/>
|
||||||
|
<stroke android:width="1dp"
|
||||||
|
android:color="@color/white" />
|
||||||
|
</shape>
|
After Width: | Height: | Size: 2.0 KiB |
@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<solid android:color="@color/black_800"/>
|
||||||
|
<corners
|
||||||
|
android:topLeftRadius="10dp"
|
||||||
|
android:topRightRadius="10dp"
|
||||||
|
android:bottomLeftRadius="10dp"
|
||||||
|
android:bottomRightRadius="10dp"/>
|
||||||
|
</shape>
|
Loading…
Reference in new issue