début de BDD
continuous-integration/drone/push Build is passing Details

persistance
Théo RENAUD 2 years ago
parent 0b20d7745c
commit e60ed56936

@ -1,8 +1,28 @@
package com.example.shakecraft.data package com.example.shakecraft.data
import androidx.room.Database import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import com.example.shakecraft.model.Player import com.example.shakecraft.model.Player
import android.content.Context
@Database(entities = [Player::class],version = 1) @Database(entities = [Player::class],version = 1)
abstract class DataBase { abstract class DataBase: RoomDatabase() {
abstract fun playerDao(): PlayerDao
companion object{
private var INSTANCE : DataBase? = null
fun getInstance(context: Context): DataBase{
return INSTANCE ?: synchronized(this){
val instance = Room.databaseBuilder(
context.applicationContext,
DataBase::class.java,
"player_database"
)
.fallbackToDestructiveMigration()
.build()
INSTANCE = instance
instance
}
}
}
} }

@ -1,7 +1,6 @@
package com.example.shakecraft.data package com.example.shakecraft.data
import androidx.room.Query import androidx.room.Query
import com.example.shakecraft.model.Boss
import com.example.shakecraft.model.Player import com.example.shakecraft.model.Player
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
import java.util.List import java.util.List

@ -1,4 +1,4 @@
package com.example.shakecraft package com.example.shakecraft.fragment
import android.content.Context import android.content.Context
import android.content.pm.ActivityInfo import android.content.pm.ActivityInfo
import android.hardware.Sensor import android.hardware.Sensor
@ -19,6 +19,8 @@ import android.widget.TextView
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
import com.example.shakecraft.MainActivity
import com.example.shakecraft.R
import com.example.shakecraft.model.Boss import com.example.shakecraft.model.Boss
import com.example.shakecraft.model.Generator import com.example.shakecraft.model.Generator
import com.example.shakecraft.model.Item import com.example.shakecraft.model.Item
@ -139,7 +141,7 @@ class BossFragment() : Fragment() {
// Generate a loot item and XP reward // Generate a loot item and XP reward
val item = Generator.generateLootBoss(boss.possibleLoot) val item = Generator.generateLootBoss(boss.possibleLoot)
currentPlayer.addItem(item) currentPlayer.inventory.addItem(item)
currentPlayer.gainXp(boss.xpReward) currentPlayer.gainXp(boss.xpReward)
// Show loot toast view for 3 seconds // Show loot toast view for 3 seconds

@ -1,4 +1,4 @@
package com.example.shakecraft package com.example.shakecraft.fragment
import android.content.Context import android.content.Context
@ -18,6 +18,8 @@ import android.widget.ProgressBar
import android.widget.TextView import android.widget.TextView
import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.findNavController
import com.example.shakecraft.MainActivity
import com.example.shakecraft.R
import com.example.shakecraft.model.Generator import com.example.shakecraft.model.Generator
import com.example.shakecraft.model.Item import com.example.shakecraft.model.Item
@ -101,7 +103,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()
currentPlayer.addItem(item) currentPlayer.inventory.addItem(item)
currentPlayer.gainXp(item.type.xpReward) currentPlayer.gainXp(item.type.xpReward)
//reset to 0 the progress bar //reset to 0 the progress bar

@ -1,4 +1,4 @@
package com.example.shakecraft package com.example.shakecraft.fragment
import android.os.Bundle import android.os.Bundle
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
@ -11,6 +11,8 @@ import android.widget.TextView
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
import com.example.shakecraft.MainActivity
import com.example.shakecraft.R
import com.example.shakecraft.model.Player 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
@ -74,11 +76,11 @@ class CraftFragment : Fragment() {
name = view.findViewById(R.id.item_name) name = view.findViewById(R.id.item_name)
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.inventory)
numberCraftable.text = RecipeManager.HowManyCraftable(recipe,currentPlayer).toString() numberCraftable.text = RecipeManager.HowManyCraftable(recipe,currentPlayer.inventory).toString()
buttonForge.setOnClickListener{ buttonForge.setOnClickListener{
currentPlayer.craft(recipe) currentPlayer.inventory.craft(recipe)
initializeViews(view, currentPlayer) initializeViews(view, currentPlayer)
setUpRecyclerView(view, currentPlayer) setUpRecyclerView(view, currentPlayer)
} }

@ -1,4 +1,4 @@
package com.example.shakecraft package com.example.shakecraft.fragment
import android.os.Bundle import android.os.Bundle
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
@ -10,6 +10,7 @@ import androidx.core.os.bundleOf
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
import com.example.shakecraft.R
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.AdapterRecipe import com.example.shakecraft.view.adapter.AdapterRecipe

@ -1,4 +1,4 @@
package com.example.shakecraft package com.example.shakecraft.fragment
import android.os.Bundle import android.os.Bundle
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
@ -11,6 +11,8 @@ import android.widget.TextView
import androidx.constraintlayout.widget.ConstraintLayout import androidx.constraintlayout.widget.ConstraintLayout
import androidx.navigation.NavOptions import androidx.navigation.NavOptions
import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.findNavController
import com.example.shakecraft.MainActivity
import com.example.shakecraft.R
import com.example.shakecraft.model.Player import com.example.shakecraft.model.Player
@ -52,15 +54,21 @@ class HomeFragment : Fragment() {
playermage = view.findViewById(R.id.playerImage) playermage = view.findViewById(R.id.playerImage)
buttonCollect = view.findViewById(R.id.buttonCollect) buttonCollect = view.findViewById(R.id.buttonCollect)
buttonCollect.setOnClickListener{ buttonCollect.setOnClickListener{
findNavController().navigate(R.id.action_homeFragment_to_collectFragment, null, NavOptions.Builder().setPopUpTo(R.id.homeFragment, false).build()) findNavController().navigate(
R.id.action_homeFragment_to_collectFragment, null, NavOptions.Builder().setPopUpTo(
R.id.homeFragment, false).build())
} }
buttonBoss = view.findViewById(R.id.buttonBoss) buttonBoss = view.findViewById(R.id.buttonBoss)
buttonBoss.setOnClickListener{ buttonBoss.setOnClickListener{
findNavController().navigate(R.id.action_homeFragment_to_bossFragment, null, NavOptions.Builder().setPopUpTo(R.id.homeFragment, false).build()) findNavController().navigate(
R.id.action_homeFragment_to_bossFragment, null, NavOptions.Builder().setPopUpTo(
R.id.homeFragment, false).build())
} }
buttonForge = view.findViewById(R.id.buttonForge) buttonForge = view.findViewById(R.id.buttonForge)
buttonForge.setOnClickListener{ buttonForge.setOnClickListener{
findNavController().navigate(R.id.action_homeFragment_to_forgeFragment, null, NavOptions.Builder().setPopUpTo(R.id.homeFragment, false).build()) findNavController().navigate(
R.id.action_homeFragment_to_forgeFragment, null, NavOptions.Builder().setPopUpTo(
R.id.homeFragment, false).build())
} }
pseudo.text = currentPlayer.pseudo pseudo.text = currentPlayer.pseudo
level.text = currentPlayer.level.toString() level.text = currentPlayer.level.toString()

@ -1,4 +1,4 @@
package com.example.shakecraft package com.example.shakecraft.fragment
import android.os.Bundle import android.os.Bundle
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
@ -7,6 +7,8 @@ import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.example.shakecraft.MainActivity
import com.example.shakecraft.R
import com.example.shakecraft.model.Player import com.example.shakecraft.model.Player
import com.example.shakecraft.view.adapter.AdapterInventory import com.example.shakecraft.view.adapter.AdapterInventory
@ -35,7 +37,7 @@ class InventoryFragment() : Fragment( ) {
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 = AdapterInventory(currentPlayer.items) adapter = AdapterInventory(currentPlayer.inventory.items)
} }
} }

@ -1,4 +1,4 @@
package com.example.shakecraft package com.example.shakecraft.fragment
import android.content.Intent import android.content.Intent
import android.net.Uri import android.net.Uri
@ -8,6 +8,7 @@ import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.LinearLayout import android.widget.LinearLayout
import com.example.shakecraft.R
class PlusFragment : Fragment() { class PlusFragment : Fragment() {
private lateinit var buttonWiki : LinearLayout private lateinit var buttonWiki : LinearLayout

@ -1,6 +1,6 @@
package com.example.shakecraft.model package com.example.shakecraft.model
class Inventory { class Inventory() {
var items: MutableList<Item> = mutableListOf() var items: MutableList<Item> = mutableListOf()
fun addItem(item: Item) { fun addItem(item: Item) {
@ -14,8 +14,8 @@ class Inventory {
} }
fun hasItem(item: Item) : Boolean{ fun hasItem(item: Item) : Boolean{
for (inventoryitem in items){ for (inventoryItem in items){
if(inventoryitem.type.name == item.type.name && inventoryitem.stack >= item.stack){ if(inventoryItem.type.name == item.type.name && inventoryItem.stack >= item.stack){
return true return true
} }
} }

@ -1,9 +1,6 @@
package com.example.shakecraft.model package com.example.shakecraft.model
import androidx.room.Entity
import androidx.room.ForeignKey
class ItemType (val name : String,val image : Int,val rarity : Int, val xpReward : Int){ class ItemType (val name : String,val image : Int,val rarity : Int, val xpReward : Int){
} }

@ -2,10 +2,8 @@ package com.example.shakecraft.model
import androidx.room.ColumnInfo import androidx.room.ColumnInfo
import androidx.room.Entity import androidx.room.Entity
import androidx.room.ForeignKey
import androidx.room.PrimaryKey import androidx.room.PrimaryKey
import com.example.shakecraft.R import com.example.shakecraft.R
import com.example.shakecraft.model.Generator.Companion.generateTreasure
@Entity(tableName="Player") @Entity(tableName="Player")
class Player() { class Player() {
@ -21,6 +19,7 @@ class Player() {
val image: Int = R.drawable.player_image val image: Int = R.drawable.player_image
@ColumnInfo(index = true) @ColumnInfo(index = true)
var rank: String = "Beginner" var rank: String = "Beginner"
val inventory: Inventory= Inventory()
fun changeRank(){ fun changeRank(){

@ -6,7 +6,7 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@drawable/backgroundboss" android:background="@drawable/backgroundboss"
android:scaleType="center" android:scaleType="center"
tools:context=".BossFragment"> tools:context=".fragment.BossFragment">
<FrameLayout <FrameLayout
android:id="@+id/frameLayout" android:id="@+id/frameLayout"

@ -6,7 +6,7 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@drawable/backgroundforest2" android:background="@drawable/backgroundforest2"
android:scaleType="center" android:scaleType="center"
tools:context=".CollectFragment"> tools:context=".fragment.CollectFragment">
<FrameLayout <FrameLayout
android:id="@+id/frameLayout" android:id="@+id/frameLayout"

@ -6,7 +6,7 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@color/black_800" android:background="@color/black_800"
android:scaleType="center" android:scaleType="center"
tools:context=".CollectFragment"> tools:context=".fragment.CollectFragment">
<FrameLayout <FrameLayout
android:id="@+id/frameLayout" android:id="@+id/frameLayout"

@ -6,7 +6,7 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@color/black_800" android:background="@color/black_800"
android:scaleType="center" android:scaleType="center"
tools:context=".CollectFragment"> tools:context=".fragment.CollectFragment">
<FrameLayout <FrameLayout
android:id="@+id/frameLayout" android:id="@+id/frameLayout"

@ -5,7 +5,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@color/black_800" android:background="@color/black_800"
tools:context=".InventoryFragment"> tools:context=".fragment.InventoryFragment">
<TextView <TextView
android:id="@+id/textView2" android:id="@+id/textView2"

@ -5,7 +5,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@color/black_800" android:background="@color/black_800"
tools:context=".PlusFragment"> tools:context=".fragment.PlusFragment">
<TextView <TextView
android:id="@+id/textView2" android:id="@+id/textView2"

@ -8,7 +8,7 @@
<fragment <fragment
android:id="@+id/bossFragment" android:id="@+id/bossFragment"
android:name="com.example.shakecraft.BossFragment" android:name="com.example.shakecraft.fragment.BossFragment"
android:label="fragment_boss" android:label="fragment_boss"
tools:layout="@layout/fragment_boss" > tools:layout="@layout/fragment_boss" >
<action <action
@ -20,7 +20,7 @@
</fragment> </fragment>
<fragment <fragment
android:id="@+id/collectFragment" android:id="@+id/collectFragment"
android:name="com.example.shakecraft.CollectFragment" android:name="com.example.shakecraft.fragment.CollectFragment"
android:label="fragment_collect" android:label="fragment_collect"
tools:layout="@layout/fragment_collect" > tools:layout="@layout/fragment_collect" >
<action <action
@ -33,17 +33,17 @@
<fragment <fragment
android:id="@+id/plusFragment" android:id="@+id/plusFragment"
android:name="com.example.shakecraft.PlusFragment" android:name="com.example.shakecraft.fragment.PlusFragment"
android:label="fragment_plus" android:label="fragment_plus"
tools:layout="@layout/fragment_plus" /> tools:layout="@layout/fragment_plus" />
<fragment <fragment
android:id="@+id/inventoryFragment" android:id="@+id/inventoryFragment"
android:name="com.example.shakecraft.InventoryFragment" android:name="com.example.shakecraft.fragment.InventoryFragment"
android:label="fragment_inventory" android:label="fragment_inventory"
tools:layout="@layout/fragment_inventory" /> tools:layout="@layout/fragment_inventory" />
<fragment <fragment
android:id="@+id/homeFragment" android:id="@+id/homeFragment"
android:name="com.example.shakecraft.HomeFragment" android:name="com.example.shakecraft.fragment.HomeFragment"
android:label="HomeFragment" > android:label="HomeFragment" >
<action <action
android:id="@+id/action_homeFragment_to_collectFragment" android:id="@+id/action_homeFragment_to_collectFragment"
@ -59,7 +59,7 @@
</fragment> </fragment>
<fragment <fragment
android:id="@+id/forgeFragment" android:id="@+id/forgeFragment"
android:name="com.example.shakecraft.ForgeFragment" android:name="com.example.shakecraft.fragment.ForgeFragment"
android:label="ForgeFragment" > android:label="ForgeFragment" >
<action <action
android:id="@+id/action_forgeFragment_to_homeFragment" android:id="@+id/action_forgeFragment_to_homeFragment"
@ -73,7 +73,7 @@
</fragment> </fragment>
<fragment <fragment
android:id="@+id/craftFragment" android:id="@+id/craftFragment"
android:name="com.example.shakecraft.CraftFragment" android:name="com.example.shakecraft.fragment.CraftFragment"
android:label="CraftFragment" > android:label="CraftFragment" >
<action <action
android:id="@+id/action_craftFragment_to_forgeFragment" android:id="@+id/action_craftFragment_to_forgeFragment"

Loading…
Cancel
Save