Compare commits

..

18 Commits

Author SHA1 Message Date
Lucas DELANIER c2dd429e9c Mise à jour de 'README.md'
continuous-integration/drone/push Build is passing Details
2 years ago
Lucas DELANIER df73330ce4 Mise à jour de 'README.md'
continuous-integration/drone/push Build is passing Details
2 years ago
Lucas DELANIER 945f0eeda5 Mise à jour de 'README.md'
continuous-integration/drone/push Build is passing Details
2 years ago
Lucas DELANIER 1e46767d2b Mise à jour de 'README.md'
continuous-integration/drone/push Build is passing Details
2 years ago
Lucas DELANIER b47c4f4c88 Mise à jour de 'README.md'
continuous-integration/drone/push Build is passing Details
2 years ago
Lucas Delanier af20aa2832 correct bugs
continuous-integration/drone/push Build is passing Details
2 years ago
Lucas Delanier 1dab25c89e livedata and observer on needed fragments
continuous-integration/drone/push Build is passing Details
2 years ago
Lucas Delanier 20df5325ab livedata and observer on needed fragments
2 years ago
Lucas Delanier 245ff1bffd working livedata on craft
continuous-integration/drone/push Build is passing Details
2 years ago
Lucas Delanier 043dd9ca4f fix problem string
2 years ago
Lucas DELANIER 37b8b0f95d Transférer les fichiers vers 'Documentations'
continuous-integration/drone/push Build is passing Details
2 years ago
Lucas DELANIER ee76fcb954 Transférer les fichiers vers 'Documentations'
continuous-integration/drone/push Build is passing Details
2 years ago
Lucas Delanier a851991274 little arrangements to make the code more kotlin spirit ⚗️
continuous-integration/drone/push Build is passing Details
2 years ago
Lucas Delanier 218e85d571 add max craft button 🎉
continuous-integration/drone/push Build is passing Details
2 years ago
Lucas Delanier 640950bc50 save the currentboss in tthe viewmodel 🎉
continuous-integration/drone/push Build is passing Details
2 years ago
Lucas Delanier 35fd67cbcf viewModel to save state
continuous-integration/drone/push Build is passing Details
2 years ago
Lucas Delanier bf752264ef Merge branch 'OpenWeatherApi'
continuous-integration/drone/push Build is passing Details
2 years ago
Lucas Delanier b04739859f merge api
continuous-integration/drone/push Build is passing Details
2 years ago

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 88 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

@ -34,12 +34,29 @@ 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)
## :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
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
<p align="center">

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

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

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

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

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

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

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

@ -1,22 +1,16 @@
package com.example.shakecraft.data
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
import com.example.shakecraft.model.*
class Stub {
fun load() : Player{
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.items = items
currentPlayer.addItem(Item(type = ITEMS.BEECH_LOG.itemtype, stack = 30))
currentPlayer.addItem(Item(type = ITEMS.BRONZE_INGOT.itemtype, stack = 30))
currentPlayer.addItem(Tool(type = ITEMS.DIAMOND_AXE.itemtype, stack = 1, damage = 8))
return currentPlayer
}

@ -0,0 +1,15 @@
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)
}

@ -0,0 +1,16 @@
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,6 +1,5 @@
package com.example.shakecraft.model
import com.example.shakecraft.R
import com.example.shakecraft.model.ItemManager.Companion.ITEMS
import kotlin.random.Random
class Generator {

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

@ -1,9 +1,8 @@
package com.example.shakecraft.model
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
BEECH_LOG(ItemType(name = "Beech Log", image = R.drawable.log2, rarity = 1, xpReward = 10)),
@ -29,6 +28,4 @@ class ItemManager {
TREASURE_KEY(ItemType(name = "Treasure Key", image = R.drawable.treasure_key, rarity = 2, xpReward = 20)),
}
}
}

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

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

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

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

@ -6,4 +6,7 @@
<string name="hello_blank_fragment">Hello blank fragment</string>
<string name="landscape">landscape</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>
Loading…
Cancel
Save