Compare commits

..

No commits in common. 'master' and 'OpenWeatherApi' have entirely different histories.

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 88 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 44 KiB

@ -34,29 +34,12 @@ La page "Dungeon" est une page de jeu dans laquelle le joueur doit secouer son t
![](https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/rainbow.png) ![](https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/rainbow.png)
## :bar_chart: distribution of work
- ✅ Fragment Home : Lucas Delanier <img src ="https://codefirst.iut.uca.fr/git/avatars/6a3835d734392fccff3949f7c82a63b9?size=870" height="20px"></br>
- ✅ Fragment Craft : Lucas Delanier<img src ="https://codefirst.iut.uca.fr/git/avatars/6a3835d734392fccff3949f7c82a63b9?size=870" height="20px"></br>
- ✅ Fragment Forge : Lucas Delanier<img src ="https://codefirst.iut.uca.fr/git/avatars/6a3835d734392fccff3949f7c82a63b9?size=870" height="20px"></br>
- ✅ Fragment Boss : Lucas Delanier<img src ="https://codefirst.iut.uca.fr/git/avatars/6a3835d734392fccff3949f7c82a63b9?size=870" height="20px"></br>
- ✅ Fragment Collect : Lucas Delanier<img src ="https://codefirst.iut.uca.fr/git/avatars/6a3835d734392fccff3949f7c82a63b9?size=870" height="20px"></br>
- ✅ Gestion de la rotation de l'écran Home fragment : Lucas Delanier<img src ="https://codefirst.iut.uca.fr/git/avatars/6a3835d734392fccff3949f7c82a63b9?size=870" height="20px"></br>
- ✅ Gestion du capteur Accélérometre : Lucas Delanier<img src ="https://codefirst.iut.uca.fr/git/avatars/6a3835d734392fccff3949f7c82a63b9?size=870" height="20px"></br>
- ✅ RecyclerView, Adapter, viewholder : Lucas Delanier<img src ="https://codefirst.iut.uca.fr/git/avatars/6a3835d734392fccff3949f7c82a63b9?size=870" height="20px"></br>
- ✅ ViewModel : Lucas Delanier<img src ="https://codefirst.iut.uca.fr/git/avatars/6a3835d734392fccff3949f7c82a63b9?size=870" height="20px"></br>
- ✅ LiveData : Lucas Delanier<img src ="https://codefirst.iut.uca.fr/git/avatars/6a3835d734392fccff3949f7c82a63b9?size=870" height="20px"></br>
- ✅ Model, Player, Item, Tool, Boss, ItemManager, Generator : Lucas Delanier<img src ="https://codefirst.iut.uca.fr/git/avatars/6a3835d734392fccff3949f7c82a63b9?size=870" height="20px"></br>
- ✅ Requete API, retrofit : Lucas Delanier<img src ="https://codefirst.iut.uca.fr/git/avatars/6a3835d734392fccff3949f7c82a63b9?size=870" height="20px"></br>
- 👷 Persistence profonde : Lucas Delanier, Theo Renaud<img src ="https://codefirst.iut.uca.fr/git/avatars/6a3835d734392fccff3949f7c82a63b9?size=870" height="20px"><img src ="https://codefirst.iut.uca.fr/git/avatars/af9299d66a9a0bf7be17f8dc156f67b9?size=870" height="20px"></br>
## :dizzy: Getting Started ## :dizzy: Getting Started
Une fois le dépot cloné, vous pouvez lancer le code sur votre téléphone Android grace a l'outil Android studio ou grace a un émulateur android. Une fois le dépot cloné, vous pouvez lancer le code sur votre téléphone Android grace a l'outil Android studio ou grace a un émulateur android.
## :gift: OverView ## :gift: OverView
<p align="center"> <p align="center">

@ -33,11 +33,6 @@ android {
kotlinOptions { kotlinOptions {
jvmTarget = '1.8' jvmTarget = '1.8'
} }
packagingOptions {
exclude 'META-INF/atomicfu.kotlin_module'
}
} }
apply plugin: 'kotlin-kapt' apply plugin: 'kotlin-kapt'
dependencies { dependencies {
@ -49,8 +44,6 @@ dependencies {
implementation 'com.google.ar.sceneform:filament-android:1.17.1' implementation 'com.google.ar.sceneform:filament-android:1.17.1'
implementation 'androidx.navigation:navigation-fragment-ktx:2.5.3' implementation 'androidx.navigation:navigation-fragment-ktx:2.5.3'
implementation 'androidx.navigation:navigation-ui-ktx:2.5.3' implementation 'androidx.navigation:navigation-ui-ktx:2.5.3'
implementation 'androidx.fragment:fragment-ktx:1.5.6'
testImplementation 'junit:junit:4.13.2' testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5' androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
@ -58,12 +51,7 @@ dependencies {
implementation "androidx.room:room-runtime:2.5.1" implementation "androidx.room:room-runtime:2.5.1"
kapt "androidx.room:room-compiler:2.5.1" kapt "androidx.room:room-compiler:2.5.1"
implementation "androidx.room:room-ktx:2.5.1" implementation "androidx.room:room-ktx:2.5.1"
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
//Retrofit
implementation "com.squareup.retrofit2:retrofit:2.9.0"
implementation "com.squareup.retrofit2:converter-gson:2.9.0"
//Coroutine
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4"
} }

@ -16,7 +16,6 @@ import android.view.animation.ScaleAnimation
import android.widget.ImageView import android.widget.ImageView
import android.widget.ProgressBar import android.widget.ProgressBar
import android.widget.TextView import android.widget.TextView
import androidx.fragment.app.activityViewModels
import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
@ -25,7 +24,6 @@ import com.example.shakecraft.model.Generator
import com.example.shakecraft.model.Item import com.example.shakecraft.model.Item
import com.example.shakecraft.model.Player import com.example.shakecraft.model.Player
import com.example.shakecraft.view.adapter.AdapterBossLoot import com.example.shakecraft.view.adapter.AdapterBossLoot
import com.example.shakecraft.viewmodel.MainViewModel
import kotlin.math.pow import kotlin.math.pow
import kotlin.math.sqrt import kotlin.math.sqrt
@ -39,7 +37,7 @@ class BossFragment() : Fragment() {
private lateinit var image: ImageView private lateinit var image: ImageView
private lateinit var buttonCollect: TextView private lateinit var buttonCollect: TextView
private lateinit var recyclerView: RecyclerView private lateinit var recyclerView: RecyclerView
val viewModel : MainViewModel by activityViewModels<MainViewModel>() private lateinit var boss: Boss
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@ -49,22 +47,21 @@ class BossFragment() : Fragment() {
savedInstanceState: Bundle? savedInstanceState: Bundle?
): View? { ): View? {
val currentPlayer = (activity as MainActivity).currentPlayer
val view = inflater.inflate(R.layout.fragment_boss, container, false) val view = inflater.inflate(R.layout.fragment_boss, container, false)
// Initialize views // Initialize views
initializeViews(view) initializeViews(view)
// Set up boss // Set up boss
if(!viewModel.isBossInitialized) boss = Generator.generateBoss()
viewModel.currentBoss = Generator.generateBoss() setUpBoss(boss)
setUpBoss(viewModel.currentBoss)
// Set up RecyclerView for boss loot // Set up RecyclerView for boss loot
setUpRecyclerView(view) setUpRecyclerView(view)
// Set up accelerometer listener // Set up accelerometer listener
viewModel.currentPlayer.value?.let { setUpAccelerometerListener(view, it) } setUpAccelerometerListener(view, currentPlayer)
// Set up activity orientation // Set up activity orientation
setUpActivityOrientation() setUpActivityOrientation()
@ -105,7 +102,7 @@ class BossFragment() : Fragment() {
recyclerView = view.findViewById(R.id.recyclerviewBossLoot) recyclerView = view.findViewById(R.id.recyclerviewBossLoot)
with(recyclerView) { with(recyclerView) {
layoutManager = LinearLayoutManager(view.context) layoutManager = LinearLayoutManager(view.context)
adapter = AdapterBossLoot(viewModel.currentBoss.possibleLoot) adapter = AdapterBossLoot(boss.possibleLoot)
} }
} }
private fun setUpActivityOrientation(){ private fun setUpActivityOrientation(){
@ -120,7 +117,7 @@ class BossFragment() : Fragment() {
toastView.visibility = View.VISIBLE toastView.visibility = View.VISIBLE
lootImage.setImageResource(item.type.image) lootImage.setImageResource(item.type.image)
lootName.text = item.type.name lootName.text = item.type.name
xpReward.text = viewModel.currentBoss.xpReward.toString() xpReward.text = boss.xpReward.toString()
toastView.postDelayed({ toastView.postDelayed({
toastView.visibility = View.GONE toastView.visibility = View.GONE
}, 3000) }, 3000)
@ -134,35 +131,35 @@ class BossFragment() : Fragment() {
} }
override fun onSensorChanged(event: SensorEvent?) { override fun onSensorChanged(event: SensorEvent?) {
val acceleration = sqrt(event!!.values[0].pow(2) + event.values[1].pow(2) + event.values[2].pow(2)) val acceleration = sqrt(event!!.values[0].pow(2) + event.values[1].pow(2) + event.values[2].pow(2))
if (viewModel.currentBoss.life <= 0) { if (boss.life <= 0) {
//Vibration to signal the death of the boss //Vibration to signal the death of the boss
val vibrator = context?.getSystemService(Context.VIBRATOR_SERVICE) as Vibrator val vibrator = context?.getSystemService(Context.VIBRATOR_SERVICE) as Vibrator
vibrator.vibrate(100) vibrator.vibrate(100)
// Generate a loot item and XP reward // Generate a loot item and XP reward
val item = Generator.generateLootBoss(viewModel.currentBoss.possibleLoot) val item = Generator.generateLootBoss(boss.possibleLoot)
currentPlayer.addItem(item) currentPlayer.addItem(item)
currentPlayer.gainXp(viewModel.currentBoss.xpReward) currentPlayer.gainXp(boss.xpReward)
// Show loot toast view for 3 seconds // Show loot toast view for 3 seconds
displayToast(view,item) displayToast(view,item)
// Spawn new boss and reset progress bar // Spawn new boss and reset progress bar
viewModel.currentBoss = Generator.generateBoss() boss = Generator.generateBoss()
setUpBoss(viewModel.currentBoss) setUpBoss(boss)
//Update displayed information //Update displayed information
setUpRecyclerView(view) setUpRecyclerView(view)
} else { } else {
if(acceleration > 20){ if(acceleration > 20){
viewModel.currentBoss.takeDamage(((acceleration / 80)+ currentPlayer.attack()/100).toDouble()) boss.takeDamage(((acceleration / 80)+ currentPlayer.attack()/100).toDouble())
} }
else{ else{
viewModel.currentBoss.takeDamage(currentPlayer.attack().toDouble()/100) boss.takeDamage(currentPlayer.attack().toDouble()/100)
} }
progressBar.progress = viewModel.currentBoss.life.toInt() progressBar.progress = boss.life.toInt()
} }
} }

@ -16,14 +16,12 @@ import android.view.ViewGroup
import android.widget.ImageView import android.widget.ImageView
import android.widget.ProgressBar import android.widget.ProgressBar
import android.widget.TextView import android.widget.TextView
import androidx.fragment.app.activityViewModels
import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.findNavController
import com.example.shakecraft.model.Generator import com.example.shakecraft.model.Generator
import com.example.shakecraft.model.Item import com.example.shakecraft.model.Item
import com.example.shakecraft.model.Player import com.example.shakecraft.model.Player
import com.example.shakecraft.viewmodel.MainViewModel
import kotlin.math.pow import kotlin.math.pow
@ -36,7 +34,6 @@ class CollectFragment() : Fragment() {
private lateinit var accelerometerEventListener: SensorEventListener private lateinit var accelerometerEventListener: SensorEventListener
private lateinit var progressBar: ProgressBar private lateinit var progressBar: ProgressBar
private lateinit var buttonBack: TextView private lateinit var buttonBack: TextView
val viewModel : MainViewModel by activityViewModels<MainViewModel>()
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@ -47,13 +44,14 @@ class CollectFragment() : Fragment() {
savedInstanceState: Bundle? savedInstanceState: Bundle?
): View? { ): View? {
val currentPlayer = (activity as MainActivity).currentPlayer
val view = inflater.inflate(R.layout.fragment_collect, container, false) val view = inflater.inflate(R.layout.fragment_collect, container, false)
// Initialize views // Initialize views
initializeViews(view) initializeViews(view)
// Set up accelerometer listener // Set up accelerometer listener
viewModel.currentPlayer.value?.let { setUpAccelerometerListener(view, it) } setUpAccelerometerListener(view,currentPlayer)
// Set up activity orientation // Set up activity orientation
setUpActivityOrientation() setUpActivityOrientation()
@ -103,7 +101,7 @@ class CollectFragment() : Fragment() {
// Generate a resource item and XP reward // Generate a resource item and XP reward
val item = Generator.generateLootCollection() val item = Generator.generateLootCollection()
viewModel.addItem(item) currentPlayer.addItem(item)
currentPlayer.gainXp(item.type.xpReward) currentPlayer.gainXp(item.type.xpReward)
//reset to 0 the progress bar //reset to 0 the progress bar

@ -8,8 +8,6 @@ import android.view.ViewGroup
import android.widget.Button import android.widget.Button
import android.widget.ImageView import android.widget.ImageView
import android.widget.TextView import android.widget.TextView
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.Observer
import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
@ -17,7 +15,7 @@ import com.example.shakecraft.model.Player
import com.example.shakecraft.model.Recipe import com.example.shakecraft.model.Recipe
import com.example.shakecraft.model.RecipeManager import com.example.shakecraft.model.RecipeManager
import com.example.shakecraft.view.adapter.AdapterMaterials import com.example.shakecraft.view.adapter.AdapterMaterials
import com.example.shakecraft.viewmodel.MainViewModel
class CraftFragment : Fragment() { class CraftFragment : Fragment() {
@ -27,10 +25,7 @@ class CraftFragment : Fragment() {
private lateinit var image: ImageView private lateinit var image: ImageView
private lateinit var name: TextView private lateinit var name: TextView
private lateinit var buttonForge: Button private lateinit var buttonForge: Button
private lateinit var buttonForgeMax: Button
private lateinit var numberCraftable: TextView private lateinit var numberCraftable: TextView
private lateinit var craftValue : TextView
private val viewModel : MainViewModel by activityViewModels()
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
@ -43,15 +38,12 @@ class CraftFragment : Fragment() {
): View? { ): View? {
val currentPlayer = (activity as MainActivity).currentPlayer
val view = inflater.inflate(R.layout.fragment_craft, container, false) val view = inflater.inflate(R.layout.fragment_craft, container, false)
recipe = arguments?.getParcelable("recipe")!! recipe = arguments?.getParcelable("recipe")!!
initializeViews(view, currentPlayer)
viewModel.currentPlayer.observe(this.viewLifecycleOwner, Observer {player -> setUpRecyclerView(view,currentPlayer)
initializeViews(view, player)
setUpRecyclerView(view, player)
})
return view return view
} }
@ -73,9 +65,7 @@ class CraftFragment : Fragment() {
private fun initializeViews(view: View, currentPlayer: Player) { private fun initializeViews(view: View, currentPlayer: Player) {
buttonBack = view.findViewById(R.id.backbutton) buttonBack = view.findViewById(R.id.backbutton)
buttonForge = view.findViewById(R.id.buttonForge) buttonForge = view.findViewById(R.id.buttonForge)
buttonForgeMax = view.findViewById(R.id.buttonForgeMax)
numberCraftable = view.findViewById(R.id.craftableNumber) numberCraftable = view.findViewById(R.id.craftableNumber)
craftValue = view.findViewById(R.id.craftValue)
buttonBack.setOnClickListener{ buttonBack.setOnClickListener{
findNavController().navigate(R.id.action_craftFragment_to_forgeFragment) findNavController().navigate(R.id.action_craftFragment_to_forgeFragment)
@ -85,15 +75,12 @@ class CraftFragment : Fragment() {
image.setImageResource(recipe.item.type.image) image.setImageResource(recipe.item.type.image)
name.text = recipe.item.type.name name.text = recipe.item.type.name
buttonForge.isEnabled = RecipeManager.isCraftable(recipe,currentPlayer) buttonForge.isEnabled = RecipeManager.isCraftable(recipe,currentPlayer)
buttonForgeMax.isEnabled = RecipeManager.isCraftable(recipe,currentPlayer)
numberCraftable.text = RecipeManager.HowManyCraftable(recipe,currentPlayer).toString() numberCraftable.text = RecipeManager.HowManyCraftable(recipe,currentPlayer).toString()
craftValue.text = recipe.item.stack.toString()
buttonForge.setOnClickListener{ buttonForge.setOnClickListener{
viewModel.craft(recipe) currentPlayer.craft(recipe)
} initializeViews(view, currentPlayer)
buttonForgeMax.setOnClickListener{ setUpRecyclerView(view, currentPlayer)
viewModel.craft(recipe, RecipeManager.HowManyCraftable(recipe, currentPlayer))
} }

@ -15,7 +15,6 @@ import com.example.shakecraft.model.RecipeManager
import com.example.shakecraft.view.adapter.AdapterRecipe import com.example.shakecraft.view.adapter.AdapterRecipe
class ForgeFragment : Fragment(), AdapterRecipe.OnItemClickListener { class ForgeFragment : Fragment(), AdapterRecipe.OnItemClickListener {
private lateinit var buttonBack: TextView private lateinit var buttonBack: TextView
private lateinit var recyclerViewObjects: RecyclerView private lateinit var recyclerViewObjects: RecyclerView

@ -11,12 +11,9 @@ import android.widget.ImageView
import android.widget.ProgressBar import android.widget.ProgressBar
import android.widget.TextView import android.widget.TextView
import androidx.constraintlayout.widget.ConstraintLayout import androidx.constraintlayout.widget.ConstraintLayout
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.Observer
import androidx.navigation.NavOptions import androidx.navigation.NavOptions
import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.findNavController
import com.example.shakecraft.model.Player import com.example.shakecraft.model.Player
import com.example.shakecraft.viewmodel.MainViewModel
class HomeFragment : Fragment() { class HomeFragment : Fragment() {
@ -32,7 +29,6 @@ class HomeFragment : Fragment() {
private lateinit var playermage : ImageView private lateinit var playermage : ImageView
private lateinit var equipeditem: ImageView private lateinit var equipeditem: ImageView
private lateinit var eventFishing: ImageView private lateinit var eventFishing: ImageView
val viewModel : MainViewModel by activityViewModels<MainViewModel>()
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@ -43,15 +39,12 @@ class HomeFragment : Fragment() {
inflater: LayoutInflater, container: ViewGroup?, inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle? savedInstanceState: Bundle?
): View? { ): View? {
val currentPlayer = (activity as MainActivity).currentPlayer
val isRaining = (activity as MainActivity).isRaining val isRaining = (activity as MainActivity).isRaining
val view = inflater.inflate(R.layout.fragment_home,container,false) val view = inflater.inflate(R.layout.fragment_home,container,false)
// Initialize views // Initialize views
initializeViews(view, currentPlayer, isRaining)
viewModel.currentPlayer.observe(viewLifecycleOwner, Observer {
initializeViews(view, it, isRaining)
})
return view return view
} }
@ -89,10 +82,9 @@ class HomeFragment : Fragment() {
progressbar.progress = currentPlayer.xp progressbar.progress = currentPlayer.xp
progressbar.max = currentPlayer.level*100 progressbar.max = currentPlayer.level*100
playermage.setImageResource(currentPlayer.image) playermage.setImageResource(currentPlayer.image)
if(currentPlayer.equipedItem?.type?.image != null) { if(currentPlayer.equipedItem?.type?.image != null) equipeditem.setImageResource(
equipeditem.setImageResource(currentPlayer.equipedItem!!.type.image) currentPlayer.equipedItem!!.type.image)
} if(isRaining == true){
if(isRaining){
eventFishing.visibility = View.VISIBLE eventFishing.visibility = View.VISIBLE
} }

@ -5,29 +5,34 @@ import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.Toast import android.widget.Toast
import androidx.fragment.app.activityViewModels
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.example.shakecraft.model.Player
import com.example.shakecraft.model.Tool import com.example.shakecraft.model.Tool
import com.example.shakecraft.view.adapter.AdapterInventory import com.example.shakecraft.view.adapter.AdapterInventory
import com.example.shakecraft.viewmodel.MainViewModel
class InventoryFragment() : Fragment( ), AdapterInventory.OnItemLongClickListener { class InventoryFragment() : Fragment( ), AdapterInventory.OnItemLongClickListener {
private lateinit var currentPlayer: Player
private lateinit var recyclerView: RecyclerView private lateinit var recyclerView: RecyclerView
val viewModel : MainViewModel by activityViewModels<MainViewModel>()
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
} }
override fun onItemLongClick(position: Int) { override fun onItemLongClick(position: Int) {
if (viewModel.currentPlayer.value!!.items[position] is Tool) { if(currentPlayer.items[position] is Tool) {
val text = if (viewModel.equipeItem(viewModel.currentPlayer.value!!.items[position]) ) " was well equipped" else " has been well unequipped" if (currentPlayer.equipeItem(currentPlayer.items[position]) == true)
Toast.makeText(
context,
currentPlayer.items[position].type.name + " was well equipped",
Toast.LENGTH_SHORT
).show()
else
Toast.makeText( Toast.makeText(
context, context,
viewModel.currentPlayer.value!!.items[position].type.name + text, currentPlayer.items[position].type.name + " has been well unequipped",
Toast.LENGTH_SHORT Toast.LENGTH_SHORT
).show() ).show()
setUpRecyclerView(view?.parent as ViewGroup, this) setUpRecyclerView(view?.parent as ViewGroup, this)
@ -38,6 +43,7 @@ class InventoryFragment() : Fragment( ), AdapterInventory.OnItemLongClickListene
inflater: LayoutInflater, container: ViewGroup?, inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle? savedInstanceState: Bundle?
): View? { ): View? {
currentPlayer = (activity as MainActivity).currentPlayer
val view = inflater.inflate(R.layout.fragment_inventory, container, false) val view = inflater.inflate(R.layout.fragment_inventory, container, false)
// Initialize views // Initialize views
@ -49,14 +55,9 @@ class InventoryFragment() : Fragment( ), AdapterInventory.OnItemLongClickListene
recyclerView = view.findViewById(R.id.recyclerviewInventory) recyclerView = view.findViewById(R.id.recyclerviewInventory)
with(recyclerView) { with(recyclerView) {
layoutManager = LinearLayoutManager(view.context) layoutManager = LinearLayoutManager(view.context)
adapter = viewModel.currentPlayer.value?.let { adapter = AdapterInventory(currentPlayer.items, listener , currentPlayer)
AdapterInventory(viewModel.currentPlayer.value!!.items, listener ,
it
)
} }
} }
}
} }

@ -4,7 +4,6 @@ import android.os.Build
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle import android.os.Bundle
import android.view.View import android.view.View
import androidx.activity.viewModels
import androidx.annotation.RequiresApi import androidx.annotation.RequiresApi
import androidx.core.view.WindowCompat import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsCompat import androidx.core.view.WindowInsetsCompat
@ -12,18 +11,22 @@ import androidx.core.view.WindowInsetsControllerCompat
import androidx.navigation.findNavController import androidx.navigation.findNavController
import androidx.navigation.ui.NavigationUI import androidx.navigation.ui.NavigationUI
import androidx.navigation.ui.setupWithNavController import androidx.navigation.ui.setupWithNavController
import com.example.shakecraft.data.Stub
import com.example.shakecraft.services.OpenWeatherMapService import com.example.shakecraft.services.OpenWeatherMapService
import com.example.shakecraft.viewmodel.MainViewModel
import com.google.android.material.bottomnavigation.BottomNavigationView import com.google.android.material.bottomnavigation.BottomNavigationView
import kotlinx.coroutines.* import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import retrofit2.Retrofit import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory import retrofit2.converter.gson.GsonConverterFactory
class MainActivity: AppCompatActivity() { class MainActivity: AppCompatActivity() {
var currentPlayer = Stub().load()
var isRaining = false var isRaining = false
private val model: MainViewModel by viewModels()
@RequiresApi(Build.VERSION_CODES.R) @RequiresApi(Build.VERSION_CODES.R)
private fun hideSystemUI() { private fun hideSystemUI() {
@ -44,6 +47,7 @@ class MainActivity: AppCompatActivity() {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
hideSystemUI() hideSystemUI()
setContentView(R.layout.activity_main) setContentView(R.layout.activity_main)
val apiKey = "85a2724ad38b3994c2b7ebe1d239bbff" val apiKey = "85a2724ad38b3994c2b7ebe1d239bbff"
val cityName = "Clermont-Ferrand" val cityName = "Clermont-Ferrand"
@ -54,8 +58,10 @@ class MainActivity: AppCompatActivity() {
val openWeatherMapService = retrofit.create(OpenWeatherMapService::class.java) val openWeatherMapService = retrofit.create(OpenWeatherMapService::class.java)
CoroutineScope(Dispatchers.IO).launch { GlobalScope.launch(Dispatchers.Main) {
val weatherResponse = openWeatherMapService.getCurrentWeather(cityName, apiKey) val weatherResponse = withContext(Dispatchers.IO) {
openWeatherMapService.getCurrentWeather(cityName, apiKey)
}
isRaining = isRaining =
weatherResponse.weather.any { it.main.contains("rain", ignoreCase = true) } weatherResponse.weather.any { it.main.contains("rain", ignoreCase = true) }
@ -96,5 +102,4 @@ class MainActivity: AppCompatActivity() {
} }

@ -1,16 +1,22 @@
package com.example.shakecraft.data package com.example.shakecraft.data
import com.example.shakecraft.model.* import com.example.shakecraft.model.ItemManager.Companion.ITEMS
import com.example.shakecraft.model.Item
import com.example.shakecraft.model.Player
import com.example.shakecraft.model.Tool
class Stub { class Stub {
fun load() : Player{ fun load() : Player{
val currentPlayer = Player("Winker",0) val currentPlayer = Player("Winker",0)
val items : MutableList<Item> = mutableListOf()
items.add(Item(type = ITEMS.BEECH_LOG.itemtype, stack = 30))
items.add(Item(type = ITEMS.BRONZE_INGOT.itemtype, stack = 30))
items.add(Tool(type = ITEMS.BRONZE_SWORD.itemtype, stack = 1, damage = 4))
items.add(Tool(type = ITEMS.DIAMOND_AXE.itemtype, stack = 1, damage = 8))
currentPlayer.addItem(Item(type = ITEMS.BEECH_LOG.itemtype, stack = 30)) currentPlayer.items = items
currentPlayer.addItem(Item(type = ITEMS.BRONZE_INGOT.itemtype, stack = 30))
currentPlayer.addItem(Tool(type = ITEMS.DIAMOND_AXE.itemtype, stack = 1, damage = 8))
return currentPlayer return currentPlayer
} }

@ -1,15 +0,0 @@
package com.example.shakecraft.data.dao
import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import com.example.shakecraft.model.Item
@Dao
interface ItemDao {
@Query("SELECT * FROM item")
suspend fun getAllItems(): List<Item>
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertItem(item: Item)
}

@ -1,16 +0,0 @@
package com.example.shakecraft.data.dao
import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import com.example.shakecraft.model.Player
@Dao
interface PlayerDao {
@Query("SELECT * FROM player")
suspend fun getAllPlayers(): List<Player>
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertPlayer(player: Player)
}

@ -1,5 +1,6 @@
package com.example.shakecraft.model package com.example.shakecraft.model
import com.example.shakecraft.R import com.example.shakecraft.R
import com.example.shakecraft.model.ItemManager.Companion.ITEMS
import kotlin.random.Random import kotlin.random.Random
class Generator { class Generator {

@ -2,15 +2,11 @@ package com.example.shakecraft.model
import android.os.Parcel import android.os.Parcel
import android.os.Parcelable import android.os.Parcelable
import androidx.room.Entity
import androidx.room.PrimaryKey
@Entity(tableName = "items")
open class Item( open class Item(
val type: ItemType, val type: ItemType,
var stack: Int = 1, var stack: Int = 1,
) : Parcelable { ) : Parcelable {
@PrimaryKey(autoGenerate = true) val id: String = type.name
override fun describeContents(): Int { override fun describeContents(): Int {

@ -1,7 +1,8 @@
package com.example.shakecraft.model package com.example.shakecraft.model
import com.example.shakecraft.R import com.example.shakecraft.R
class ItemManager {
companion object {
enum class ITEMS(val itemtype: ItemType){ enum class ITEMS(val itemtype: ItemType){
// Craftable items and resources // Craftable items and resources
@ -29,3 +30,5 @@ enum class ITEMS(val itemtype: ItemType){
} }
}
}

@ -4,15 +4,10 @@ import com.example.shakecraft.R
class Player(var pseudo: String, var xp: Int = 0) { class Player(var pseudo: String, var xp: Int = 0) {
var level: Int = 1 var level: Int = 1
private set
val image: Int = R.drawable.player_image val image: Int = R.drawable.player_image
var items: MutableList<Item> = mutableListOf() var items: MutableList<Item> = mutableListOf()
private set
var rank: String = "Beginner" var rank: String = "Beginner"
private set
var equipedItem : Tool? = null var equipedItem : Tool? = null
private set
fun changeRank(){ fun changeRank(){
@ -33,6 +28,7 @@ class Player(var pseudo: String, var xp: Int = 0) {
val findItem = items.find { it.type.name == item.type.name } val findItem = items.find { it.type.name == item.type.name }
if(findItem!= null){ if(findItem!= null){
println("findItem n: "+findItem.stack+" item nb:"+item.stack)
findItem.stack += item.stack findItem.stack += item.stack
} }
else{ else{
@ -70,11 +66,10 @@ class Player(var pseudo: String, var xp: Int = 0) {
return false return false
} }
fun craft(recipe: Recipe, count: Int = 1) : Boolean{ fun craft(recipe: Recipe) : Boolean{
println("test") println("test")
for (i in 1..count) {
for (ingredient in recipe.ingredients) { for (ingredient in recipe.ingredients) {
val searchedItem = items.find { it.type == ingredient.type } val searchedItem = items.find { it.type.name == ingredient.type.name }
if(searchedItem != null) { if(searchedItem != null) {
searchedItem.stack -= ingredient.stack searchedItem.stack -= ingredient.stack
if (searchedItem.stack == 0){ if (searchedItem.stack == 0){
@ -84,7 +79,6 @@ class Player(var pseudo: String, var xp: Int = 0) {
} }
println("item:"+recipe.item.stack) println("item:"+recipe.item.stack)
addItem(recipe.item) addItem(recipe.item)
}
return true return true
} }
@ -98,5 +92,4 @@ class Player(var pseudo: String, var xp: Int = 0) {
return true return true
} }
} }

@ -1,4 +1,5 @@
package com.example.shakecraft.model package com.example.shakecraft.model
import com.example.shakecraft.model.ItemManager.Companion.ITEMS
class RecipeManager { class RecipeManager {
@ -74,14 +75,16 @@ class RecipeManager {
fun HowManyCraftable(recipe: Recipe, player: Player): Int{ fun HowManyCraftable(recipe: Recipe, player: Player): Int{
val divisedList = mutableListOf<Int>() val divisedList = mutableListOf<Int>()
return if (!isCraftable(recipe,player)) 0 if(isCraftable(recipe,player)==false)
return 0
else{ else{
for(element in recipe.ingredients){ for(element in recipe.ingredients){
println("cc")
val itemSearch = player.items.find { it.type.name == element.type.name } val itemSearch = player.items.find { it.type.name == element.type.name }
if(itemSearch!= null) if(itemSearch!= null)
divisedList.add(itemSearch.stack / element.stack) divisedList.add(itemSearch.stack / element.stack)
} }
divisedList.min() return divisedList.min()
} }
} }

@ -0,0 +1,3 @@
package com.example.shakecraft.view.viewholder
class ViewHolderInventory(inflate: Any?) {
}

@ -1,39 +0,0 @@
package com.example.shakecraft.viewmodel
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.example.shakecraft.data.Stub
import com.example.shakecraft.model.Boss
import com.example.shakecraft.model.Item
import com.example.shakecraft.model.Recipe
class MainViewModel : ViewModel() {
var currentPlayer = MutableLiveData(Stub().load())
lateinit var currentBoss : Boss
val isBossInitialized get() = this::currentBoss.isInitialized
fun craft(recipe : Recipe, count : Int = 1){
currentPlayer.value?.craft(recipe, count)
this.currentPlayer.value = currentPlayer.value
}
fun addItem(item: Item) {
currentPlayer.value?.addItem(item)
this.currentPlayer.value = currentPlayer.value
}
fun gainXp(xpReward: Int) {
currentPlayer.value?.gainXp(xpReward)
this.currentPlayer.value = currentPlayer.value
}
fun equipeItem(item: Item): Boolean {
currentPlayer.value?.equipeItem(item)
this.currentPlayer.value = currentPlayer.value
return true
}
}

@ -24,24 +24,24 @@
android:id="@+id/backbutton" android:id="@+id/backbutton"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="start|center_vertical" android:layout_gravity="left|center_vertical"
android:focusable="true" android:focusable="true"
android:text="@string/ancient_forge" android:drawableStart="@drawable/back"
android:drawableTint="@color/blue"
android:text="Ancient Forge"
android:textColor="@color/blue" android:textColor="@color/blue"
android:textSize="16sp" android:textSize="16sp"
android:textStyle="bold" android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent" />
app:drawableStartCompat="@drawable/back"
app:drawableTint="@color/blue" />
<TextView <TextView
android:id="@+id/textView2" android:id="@+id/textView2"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center" android:layout_gravity="center"
android:text="@string/recipe" android:text="Recipe"
android:textColor="@color/white" android:textColor="@color/white"
android:textSize="16sp" android:textSize="16sp"
android:textStyle="bold" android:textStyle="bold"
@ -63,7 +63,6 @@
app:layout_constraintTop_toBottomOf="@+id/frameLayout"> app:layout_constraintTop_toBottomOf="@+id/frameLayout">
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -72,33 +71,15 @@
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"> app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView <ImageView
android:id="@+id/item_image" android:id="@+id/item_image"
android:layout_width="50dp" android:layout_width="50dp"
android:layout_height="50dp" android:layout_height="50dp"
android:background="@drawable/item_recipe_background" android:background="@drawable/item_recipe_background"
android:contentDescription="@string/image_of_item" android:contentDescription="image of item"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/wooden_stick" /> app:srcCompat="@drawable/wooden_stick" />
<TextView
android:id="@+id/craftValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
tools:text="1"
android:paddingRight="2dp"
android:textColor="@color/white" />
</androidx.constraintlayout.widget.ConstraintLayout>
<TextView <TextView
android:id="@+id/item_name" android:id="@+id/item_name"
@ -149,34 +130,19 @@
</LinearLayout> </LinearLayout>
<Button
android:id="@+id/buttonForgeMax"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="10dp"
android:layout_marginBottom="5dp"
android:backgroundTint="@color/button_background_color"
android:text="FORGE MAX"
android:textColor="@color/white"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/buttonForge"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.473"
app:layout_constraintStart_toStartOf="parent" />
<Button <Button
android:id="@+id/buttonForge" android:id="@+id/buttonForge"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginHorizontal="10dp" android:layout_marginHorizontal="10dp"
android:layout_marginBottom="10dp" android:layout_marginBottom="10dp"
android:backgroundTint="@color/button_background_color"
android:text="Forge" android:text="Forge"
android:textColor="@color/white"
android:textStyle="bold" android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" /> app:layout_constraintStart_toStartOf="parent"
android:backgroundTint="@color/button_background_color"
android:textColor="@color/white"/>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
@ -184,7 +150,7 @@
android:layout_marginBottom="10dp" android:layout_marginBottom="10dp"
android:gravity="center" android:gravity="center"
android:orientation="horizontal" android:orientation="horizontal"
app:layout_constraintBottom_toTopOf="@+id/buttonForgeMax" app:layout_constraintBottom_toTopOf="@+id/buttonForge"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
android:background="@drawable/craftable_background" android:background="@drawable/craftable_background"

@ -6,7 +6,4 @@
<string name="hello_blank_fragment">Hello blank fragment</string> <string name="hello_blank_fragment">Hello blank fragment</string>
<string name="landscape">landscape</string> <string name="landscape">landscape</string>
<string name="wikiImage">Wiki image</string> <string name="wikiImage">Wiki image</string>
<string name="ancient_forge">Ancient Forge</string>
<string name="recipe">Recipe</string>
<string name="image_of_item">Image</string>
</resources> </resources>
Loading…
Cancel
Save