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
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import com.example.shakecraft.model.Player
import android.content.Context
@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
import androidx.room.Query
import com.example.shakecraft.model.Boss
import com.example.shakecraft.model.Player
import kotlinx.coroutines.flow.Flow
import java.util.List

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

@ -1,4 +1,4 @@
package com.example.shakecraft
package com.example.shakecraft.fragment
import android.content.Context
@ -18,6 +18,8 @@ import android.widget.ProgressBar
import android.widget.TextView
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.Item
@ -101,7 +103,7 @@ class CollectFragment() : Fragment() {
// Generate a resource item and XP reward
val item = Generator.generateLootCollection()
currentPlayer.addItem(item)
currentPlayer.inventory.addItem(item)
currentPlayer.gainXp(item.type.xpReward)
//reset to 0 the progress bar

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

@ -1,4 +1,4 @@
package com.example.shakecraft
package com.example.shakecraft.fragment
import android.os.Bundle
import androidx.fragment.app.Fragment
@ -10,6 +10,7 @@ import androidx.core.os.bundleOf
import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.example.shakecraft.R
import com.example.shakecraft.model.Recipe
import com.example.shakecraft.model.RecipeManager
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 androidx.fragment.app.Fragment
@ -11,6 +11,8 @@ import android.widget.TextView
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.navigation.NavOptions
import androidx.navigation.fragment.findNavController
import com.example.shakecraft.MainActivity
import com.example.shakecraft.R
import com.example.shakecraft.model.Player
@ -52,15 +54,21 @@ class HomeFragment : Fragment() {
playermage = view.findViewById(R.id.playerImage)
buttonCollect = view.findViewById(R.id.buttonCollect)
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.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.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
level.text = currentPlayer.level.toString()

@ -1,4 +1,4 @@
package com.example.shakecraft
package com.example.shakecraft.fragment
import android.os.Bundle
import androidx.fragment.app.Fragment
@ -7,6 +7,8 @@ import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
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.view.adapter.AdapterInventory
@ -35,7 +37,7 @@ class InventoryFragment() : Fragment( ) {
recyclerView = view.findViewById(R.id.recyclerviewInventory)
with(recyclerView) {
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.net.Uri
@ -8,6 +8,7 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import com.example.shakecraft.R
class PlusFragment : Fragment() {
private lateinit var buttonWiki : LinearLayout

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

@ -1,9 +1,6 @@
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){
}

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

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

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

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

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

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

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

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

Loading…
Cancel
Save