Compare commits

...

9 Commits

@ -18,25 +18,25 @@
[![Technical Debt](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=ShakeAndCraft&metric=sqale_index&token=bb717076471bf71ba25b805c0b6ad18e4ae5c047)](https://codefirst.iut.uca.fr/sonar/dashboard?id=ShakeAndCraft) [![Technical Debt](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=ShakeAndCraft&metric=sqale_index&token=bb717076471bf71ba25b805c0b6ad18e4ae5c047)](https://codefirst.iut.uca.fr/sonar/dashboard?id=ShakeAndCraft)
[![Duplicated Lines (%)](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=ShakeAndCraft&metric=duplicated_lines_density&token=bb717076471bf71ba25b805c0b6ad18e4ae5c047)](https://codefirst.iut.uca.fr/sonar/dashboard?id=ShakeAndCraft) [![Duplicated Lines (%)](https://codefirst.iut.uca.fr/sonar/api/project_badges/measure?project=ShakeAndCraft&metric=duplicated_lines_density&token=bb717076471bf71ba25b805c0b6ad18e4ae5c047)](https://codefirst.iut.uca.fr/sonar/dashboard?id=ShakeAndCraft)
**ShakeAndCraft** est un jeu mobile de type RPG dans lequel vous etes invités a secouer votre téléphone pour récuperer des ressources ainsi que combattre des boss surpuissants. Vous y découvrirais également un systeme de craft et d'évenement relié a la météo en temps réel. **ShakeAndCraft** est un jeu mobile de type RPG dans lequel vous êtes invités a secouer votre téléphone pour récupérer des ressources ainsi que combattre des boss surpuissants. Vous y découvrirEZ également un système de crafts et d'événements reliés a la météo en temps réel.
## :floppy_disk: FEATURES ## :floppy_disk: FEATURES
Sur la page principale, vous pouvez voir les informations de votre personnages ( pseudo, level, xp, rank) ainsi que des boutons de navigtions vers les pages de jeu. Sur la page principale, vous pouvez voir les informations de votre personnages ( pseudo, level, xp, rank) ainsi que des boutons de navigation vers les pages de jeu.
La page "Inventory" vous permet de voir tous les items que vous possédez dans une liste dans laquelle vous pouvez rechercher par le nom un item en particulié. La page "Inventory" vous permet de voir tous les items que vous possédez dans une liste dans laquelle vous pouvez rechercher par le nom un item en particulié.
La page "Ancient Forge" affiche les crafts disponibles dans le jeu avec un effet grisé pour les crafts qui ne peuvent pas etre fabriqués. La page "Ancient Forge" affiche les crafts disponibles dans le jeu avec un effet grisé pour les crafts qui ne peuvent pas etre fabriqués.
La page "Pleasent Forest" est une page de jeu dans laquelle le joueur doit secouer son téléphone pour charger une barre dechargement. Une fois celle ci compete, un item est choisi selon sa rareté affiché sur l'écran et est ajouté a l'inventaire du joueur. La page "Pleasent Forest" est une page de jeu dans laquelle le joueur doit secouer son téléphone pour charger une barre de chargement. Une fois celle ci complète, un item est choisi selon sa rareté affiché sur l'écran et est ajouté a l'inventaire du joueur.
La page "Dungeon" est une page de jeu dans laquelle le joueur doit secouer son téléphone pour faire déscendre la vie d'un Boss beaucoup plus compliqué que la recolte de ressources. Une fois le boss tué, un item est ajouté a l'inventaire du joueur selon la rareté affiché a l'écran. La page "Dungeon" est une page de jeu dans laquelle le joueur doit secouer son téléphone pour faire descendre la vie d'un Boss beaucoup plus compliqué que la recolte de ressources. Une fois le boss tué, un item est ajouté a l'inventaire du joueur selon la rareté affiché a l'écran.
![](https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/rainbow.png) ![](https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/rainbow.png)
## :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 ou sur un émulateur Android grace a l'outil Android studio.
@ -48,7 +48,7 @@ Une fois le dépot cloné, vous pouvez lancer le code sur votre téléphone Andr
## :wrench: SUPPORT ## :wrench: SUPPORT
En cas de problème lors de l'utilisation de l'application, vous pouvez nous contacer aux adresses suivantes : En cas de problème lors de l'utilisation de l'application, vous pouvez nous contacter aux adresses suivantes :
Lucas Delanier : **lucas.delanier@etu.uca.fr** </br> Lucas Delanier : **lucas.delanier@etu.uca.fr** </br>

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="VcsDirectoryMappings"> <component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/../" vcs="Git" /> <mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component> </component>
</project> </project>

@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AutoImportSettings">
<option name="autoReloadType" value="NONE" />
</component>
<component name="ChangeListManager">
<list default="true" id="c1d3a00b-b752-49c3-9cf2-bbd65379556a" name="Changes" comment="" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/../.." />
</component>
<component name="ProjectId" id="2N679bs9cUF2LZx6uhUfUbDiBup" />
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"RunOnceActivity.OpenProjectViewOnStart": "true",
"RunOnceActivity.ShowReadmeOnStart": "true",
"RunOnceActivity.cidr.known.project.marker": "true",
"cidr.known.project.marker": "true",
"last_opened_file_path": "D:/ShakeAndCraft/ShakeAndCraft/ShakeAndCraft"
}
}]]></component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="c1d3a00b-b752-49c3-9cf2-bbd65379556a" name="Changes" comment="" />
<created>1678972527401</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1678972527401</updated>
</task>
<servers />
</component>
</project>

@ -35,8 +35,10 @@ android {
} }
} }
dependencies { apply plugin: 'kotlin-kapt'
dependencies {
implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.5.1"
implementation 'androidx.core:core-ktx:1.7.0' implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.1' implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0' implementation 'com.google.android.material:material:1.5.0'
@ -48,4 +50,7 @@ dependencies {
androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation 'androidx.vectordrawable:vectordrawable:1.1.0' implementation 'androidx.vectordrawable:vectordrawable:1.1.0'
kapt 'androidx.room:room-compiler:2.5.1'
implementation 'androidx.room:room-ktx:2.5.1'
implementation 'androidx.room:room-runtime:2.5.1'
} }

@ -0,0 +1,8 @@
package com.example.shakecraft
import android.app.Application
import com.example.shakecraft.data.DataBase
class PlayerApplication: Application(){
val database: DataBase by lazy { DataBase.getInstance(this) }
}

@ -0,0 +1,60 @@
package com.example.shakecraft
import androidx.lifecycle.LiveData
import androidx.lifecycle.asLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.viewModelScope
import com.example.shakecraft.data.PlayerDao
import com.example.shakecraft.model.Player
import kotlinx.coroutines.launch
class PlayerViewModel(private val playerDao: PlayerDao): ViewModel() {
val player:LiveData<Player> = playerDao.getPlayer()
.asLiveData()
fun updatePlayer(
Id: Int,
pseudo: String,
level: Int,
xp: Int,
image: Int,
rank: String,
){
val updatePlayer= getUpdatePlayerEntry(Id, pseudo, level, xp, image, rank)
updatePlayer(updatePlayer)
}
private fun updatePlayer(player: Player) {
viewModelScope.launch{
playerDao.update(player)
}
}
private fun getUpdatePlayerEntry(
Id: Int,
pseudo: String,
level: Int,
xp: Int,
image: Int,
rank: String,
): Player {
return Player(
id= Id,
pseudo= pseudo,
level= level,
xp= xp,
image= image,
rank= rank,
)
}
}
class PlayerViewModelFactory(private val playerDao: PlayerDao): ViewModelProvider.Factory{
fun <T : ViewModel?> create(modelClass: Class<T>): T {
if (modelClass.isAssignableFrom(PlayerViewModel::class.java)){
@Suppress("UNCHECKED_CAST")
return PlayerViewModel(playerDao) as T
}
throw IllegalArgumentException("Unknown ViewModel class")
}
}

@ -0,0 +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: 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
}
}
}
}

@ -0,0 +1,21 @@
package com.example.shakecraft.data
import androidx.room.*
import com.example.shakecraft.model.Player
import kotlinx.coroutines.flow.Flow
@Dao
interface PlayerDao {
@Query("SELECT * FROM Player")
fun getPlayer(): Flow<Player>
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insert(player: Player)
@Update
suspend fun update(player: Player)
@Delete
suspend fun delete(player: Player)
}

@ -8,10 +8,12 @@ import com.example.shakecraft.model.Player
class Stub { class Stub {
fun load() : Player{ fun load() : Player{
val currentPlayer = Player("Winker",0) val currentPlayer = Player()
val items : MutableList<Item> = mutableListOf() val items : MutableList<Item> = mutableListOf()
items.add(Item(type = ITEMS.BEECH_LOG.itemtype, stack = 30)) items.add(Item(type = ITEMS.BEECH_LOG.itemtype, stack = 30))
items.add(Item(type = ITEMS.BRONZE_INGOT.itemtype, stack = 30)) items.add(Item(type = ITEMS.BRONZE_INGOT.itemtype, stack = 30))
items.add(Item(type = ITEMS.TREASURE.itemtype, stack = 2))
items.add(Item(type = ITEMS.TREASURE_KEY.itemtype, stack = 1))
currentPlayer.items = items currentPlayer.items = items
return currentPlayer return currentPlayer

@ -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,7 +1,10 @@
package com.example.shakecraft.model package com.example.shakecraft.model
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey
class Boss ( data class Boss (
var name: String, var name: String,
var life: Int, var life: Int,
var maxlife: Int, var maxlife: Int,

@ -80,5 +80,22 @@ class Generator {
// Si aucun élément n'a été choisi, retourner le dernier élément de la liste // Si aucun élément n'a été choisi, retourner le dernier élément de la liste
return possibleBoss.last().first return possibleBoss.last().first
} }
fun generateTreasure(): Item{
val possibleTreasure: List<Pair<Item,Double>> = listOf(
Pair(Item(type = ITEMS.MONSTER_BONES.itemtype), 0.9),
)
val rand = Random.nextDouble()
var cumulativeProb = 0.0
for (element in possibleTreasure) {
cumulativeProb += element.second
if (rand < cumulativeProb) {
return element.first
}
}
// Si aucun élément n'a été choisi, retourner le dernier élément de la liste
return possibleTreasure.last().first
}
} }
} }

@ -2,8 +2,14 @@ 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.ForeignKey
@Entity(tableName = "Item", foreignKeys = [ForeignKey(
entity = ItemType::class, parentColumns = arrayOf("name"),
childColumns = arrayOf("itemtype"),
onUpdate = ForeignKey.CASCADE,
onDelete = ForeignKey.CASCADE)])
class Item( class Item(
val type: ItemType, val type: ItemType,
var stack: Int = 1, var stack: Int = 1,

@ -21,13 +21,14 @@ class ItemManager {
IRON_ORE(ItemType(name = "Iron Ore", image = R.drawable.iron_ore, rarity = 2, xpReward = 25)), IRON_ORE(ItemType(name = "Iron Ore", image = R.drawable.iron_ore, rarity = 2, xpReward = 25)),
IRON_INGOT(ItemType(name = "Iron Ingot", image = R.drawable.iron_ingot, rarity = 1, xpReward = 0)), IRON_INGOT(ItemType(name = "Iron Ingot", image = R.drawable.iron_ingot, rarity = 1, xpReward = 0)),
OPEN_TREASURE(ItemType(name = "Open Treasure", image = R.drawable.open_treasure, rarity = 3, xpReward = 50)),
// Lootable items // Lootable items
MONSTER_BONES(ItemType(name = "Monster Bones", image = R.drawable.monster_bones, rarity = 1, xpReward = 10)), MONSTER_BONES(ItemType(name = "Monster Bones", image = R.drawable.monster_bones, rarity = 1, xpReward = 10)),
MONSTER_EYE(ItemType(name = "Monster Eye", image = R.drawable.monster_eyes, rarity = 2, xpReward = 20)), MONSTER_EYE(ItemType(name = "Monster Eye", image = R.drawable.monster_eyes, rarity = 2, xpReward = 20)),
TREASURE_KEY(ItemType(name = "Treasure Key", image = R.drawable.treasure_key, rarity = 2, xpReward = 20)), TREASURE_KEY(ItemType(name = "Treasure Key", image = R.drawable.treasure_key, rarity = 2, xpReward = 20)),
TREASURE(ItemType(name = "Treasure", image = R.drawable.treasure, rarity = 3, xpReward = 20)),
} }
} }

@ -1,6 +1,6 @@
package com.example.shakecraft.model package com.example.shakecraft.model
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){
} }

@ -1,12 +1,26 @@
package com.example.shakecraft.model package com.example.shakecraft.model
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey
import com.example.shakecraft.R import com.example.shakecraft.R
class Player(val pseudo: String, var xp: Int = 0) { @Entity(tableName="Player")
var level: Int = 1 class Player() {
@PrimaryKey(autoGenerate = true)
val id : Int = 0
@ColumnInfo(name = "name")
val pseudo: String = "Unknow"
@ColumnInfo(name = "level")
var level: Int = 0
@ColumnInfo(name = "xp")
var xp: Int = 0
@ColumnInfo(name = "image")
val image: Int = R.drawable.player_image val image: Int = R.drawable.player_image
var items: MutableList<Item> = mutableListOf() @ColumnInfo(name = "rank")
var rank: String = "Beginner" var rank: String = "Beginner"
//@ColumnInfo(name = "items") Je ne sais pas comment faire pour stocker la liste dans la BDD
var items: MutableList<Item> = mutableListOf()
fun changeRank(){ fun changeRank(){
@ -23,15 +37,6 @@ class Player(val pseudo: String, var xp: Int = 0) {
else -> {"Divine"} else -> {"Divine"}
} }
} }
fun addItem(item: Item) {
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{items.add(Item(type = item.type, stack = item.stack))}
}
fun gainXp(xp: Int) { fun gainXp(xp: Int) {
this.xp += xp this.xp += xp
@ -42,16 +47,26 @@ class Player(val pseudo: String, var xp: Int = 0) {
} }
} }
fun addItem(item: Item) {
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{items.add(Item(type = item.type, stack = item.stack))}
}
fun hasItem(item: Item) : Boolean{ fun hasItem(item: Item) : Boolean{
for (playeritem in items){ for (playerItem in items){
if(playeritem.type.name == item.type.name && playeritem.stack >= item.stack){ if(playerItem.type.name == item.type.name && playerItem.stack >= item.stack){
return true return true
} }
} }
return false return false
} }
fun craft(recipe: Recipe) : Boolean{ fun craft(recipe: Recipe) : Boolean{
println("test") println("test")
for (ingredient in recipe.ingredients) { for (ingredient in recipe.ingredients) {
@ -61,11 +76,15 @@ class Player(val pseudo: String, var xp: Int = 0) {
if (searchedItem.stack == 0){ if (searchedItem.stack == 0){
items.remove(searchedItem) items.remove(searchedItem)
} }
println(ingredient.type.name)
if (recipe.item.type.name == "Open Treasure"){
addItem(Generator.generateTreasure())
return true
}
} }
} }
println("item:"+recipe.item.stack) println("item:"+recipe.item.stack)
addItem(recipe.item) addItem(recipe.item)
return true return true
} }
} }

@ -21,7 +21,11 @@ class RecipeManager {
Item(type = ITEMS.WOODEN_STICK.itemtype, stack = 2), Item(type = ITEMS.WOODEN_STICK.itemtype, stack = 2),
Item(type = ITEMS.WOODEN_PLANK.itemtype, stack = 2) Item(type = ITEMS.WOODEN_PLANK.itemtype, stack = 2)
), "Objects"), ), "Objects"),
Recipe(
Item(type = ITEMS.OPEN_TREASURE.itemtype, stack = 1),listOf(
Item(type = ITEMS.TREASURE.itemtype, stack = 1),
Item(type = ITEMS.TREASURE_KEY.itemtype, stack = 1)
), "Objects"),
) )
val recipeListTools : List<Recipe> = listOf( val recipeListTools : List<Recipe> = listOf(
@ -60,10 +64,6 @@ class RecipeManager {
) )
fun isCraftable(recipe: Recipe, player :Player): Boolean{ fun isCraftable(recipe: Recipe, player :Player): Boolean{
for (ingredient in recipe.ingredients) { for (ingredient in recipe.ingredients) {
if (!player.hasItem(ingredient)) { if (!player.hasItem(ingredient)) {
@ -75,7 +75,7 @@ class RecipeManager {
fun HowManyCraftable(recipe: Recipe, player : Player): Int{ fun HowManyCraftable(recipe: Recipe, player : Player): Int{
val divisedList = mutableListOf<Int>() val divisedList = mutableListOf<Int>()
if(isCraftable(recipe,player)==false) if(!isCraftable(recipe,player))
return 0 return 0
else{ else{
for(element in recipe.ingredients){ for(element in recipe.ingredients){

@ -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