Ancient forge is now available with his recipes 🔨🔧

SQLite
Lucas Delanier 2 years ago
parent 7c4b6cb148
commit 4c379f05ce

@ -7,11 +7,4 @@
<component name="ProjectType">
<option name="id" value="Android" />
</component>
<component name="VisualizationToolProject">
<option name="state">
<ProjectState>
<option name="scale" value="0.2" />
</ProjectState>
</option>
</component>
</project>

@ -33,7 +33,7 @@ class CollectFragment() : Fragment() {
private lateinit var accelerometer: Sensor
private lateinit var accelerometerEventListener: SensorEventListener
private lateinit var progressBar: ProgressBar
private lateinit var buttonCollect: TextView
private lateinit var buttonBack: TextView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@ -61,8 +61,8 @@ class CollectFragment() : Fragment() {
}
private fun initializeViews(view: View) {
progressBar = view.findViewById(R.id.progressBar)
buttonCollect = view.findViewById<TextView>(R.id.backbutton)
buttonCollect.setOnClickListener{
buttonBack = view.findViewById<TextView>(R.id.backbutton)
buttonBack.setOnClickListener{
findNavController().navigate(R.id.action_collectFragment_to_homeFragment)
}
}

@ -0,0 +1,66 @@
package com.example.shakecraft
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.example.shakecraft.model.RecipeManager
import com.example.shakecraft.view.adapter.AdapterRecipe
class ForgeFragment : Fragment() {
private lateinit var buttonBack: TextView
private lateinit var recyclerViewObjects: RecyclerView
private lateinit var recyclerViewTools: RecyclerView
private lateinit var recyclerViewBlacksmithing: RecyclerView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
}
private fun initializeViews(view: View) {
buttonBack = view.findViewById<TextView>(R.id.backbutton)
buttonBack.setOnClickListener{
findNavController().navigate(R.id.action_forgeFragment_to_homeFragment)
}
}
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val view = inflater.inflate(R.layout.fragment_forge, container, false)
// Initialize views
initializeViews(view)
setUpRecyclerView(view)
return view
}
private fun setUpRecyclerView(view: View) {
recyclerViewObjects = view.findViewById(R.id.RecyclerviewObjects)
with(recyclerViewObjects) {
layoutManager = LinearLayoutManager(view.context)
adapter = AdapterRecipe(RecipeManager.recipeListObjects)
}
recyclerViewTools = view.findViewById(R.id.RecyclerviewTools)
with(recyclerViewTools) {
layoutManager = LinearLayoutManager(view.context)
adapter = AdapterRecipe(RecipeManager.recipeListTools)
}
recyclerViewBlacksmithing = view.findViewById(R.id.RecyclerviewBlacksmithing)
with(recyclerViewBlacksmithing) {
layoutManager = LinearLayoutManager(view.context)
adapter = AdapterRecipe(RecipeManager.recipeListBlacksmithing)
}
}
}

@ -22,6 +22,7 @@ class HomeFragment : Fragment() {
private lateinit var xp : TextView
private lateinit var buttonCollect : ConstraintLayout
private lateinit var buttonBoss : ConstraintLayout
private lateinit var buttonForge : ConstraintLayout
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@ -54,6 +55,10 @@ class HomeFragment : Fragment() {
buttonBoss.setOnClickListener{
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())
}
pseudo.text = currentPlayer.pseudo
level.text = currentPlayer.level.toString()
rank.text = currentPlayer.rank

@ -7,18 +7,15 @@ import androidx.annotation.RequiresApi
import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.WindowInsetsControllerCompat
import androidx.navigation.findNavController
import androidx.navigation.ui.setupWithNavController
import com.example.shakecraft.data.Stub
import com.example.shakecraft.model.Player
import com.google.android.material.bottomnavigation.BottomNavigationView
class MainActivity : AppCompatActivity() {
var currentPlayer = Stub().currentPlayer
var currentPlayer = Player("Winker",0)
@RequiresApi(Build.VERSION_CODES.R)
private fun hideSystemUI() {

@ -3,10 +3,10 @@ package com.example.shakecraft.model
data class Item(
var name: String,
var rarity: Int,
var stack: Int,
var rarity: Int = 1,
var stack: Int = 1,
var image: Int,
var xpReward: Int,
var xpReward: Int = 0,
)

@ -63,6 +63,29 @@ class Player(val pseudo: String, var xp: Int = 0) {
items.remove(item)
}
fun hasItem(item: Item) : Boolean{
for (playeritem in items){
if(playeritem.name == item.name && playeritem.stack >= item.stack){
return true
}
}
return false
}
fun craft(recipe: Recipe) : Boolean{
for (ingredient in recipe.ingredients) {
val searchedItem = items.find { it.name == recipe.item.name }
if(searchedItem != null) {
searchedItem.stack -= recipe.item.stack
if (searchedItem.stack == 0){
items.remove(searchedItem)
}
return true
}
else
return false
}
return false
}
}

@ -1,4 +1,4 @@
package com.example.shakecraft.model
class Recipe(val item: Item, val quantity: Int, itemsNeeded : List<Item>) {
class Recipe(val item: Item, val ingredients : List<Item>, val type: String) {
}

@ -0,0 +1,79 @@
package com.example.shakecraft.model
import com.example.shakecraft.R
class RecipeManager {
companion object {
var recipeListObjects : List<Recipe> = listOf(
Recipe(
Item("Wooden Stick", image = R.drawable.wooden_stick, stack = 1),listOf(
Item("Wooden Plank", image = R.drawable.wooden_plank, stack = 2)
), "Objects"),
Recipe(
Item("Wooden Plank", image = R.drawable.wooden_plank, stack = 4),listOf(
Item("Beech Log", image = R.drawable.log2, stack = 2)
), "Objects"),
Recipe(
Item("Wooden Ball", image = R.drawable.wooden_ball, stack = 1),listOf(
Item("Wooden Stick", image = R.drawable.wooden_stick, stack = 2),
Item("Wooden Plank", image = R.drawable.wooden_plank, stack = 2)
), "Objects"),
)
var recipeListTools : List<Recipe> = listOf(
Recipe(
Item("Bronze Sword", image = R.drawable.bronze_sword, stack = 1),listOf(
Item("Wooden Stick", image = R.drawable.wooden_stick, stack = 5),
Item("Bronze Ingot", image = R.drawable.bronze_ore, stack = 10)
), "Tools"),
Recipe(
Item("Wizard Staff", image = R.drawable.wizard_staff, stack = 1),listOf(
Item("Wooden Stick", image = R.drawable.wooden_stick, stack = 10),
Item("Monster Eye", image = R.drawable.monster_eyes, stack = 20),
), "Tools"),
Recipe(
Item("Diamond Axe", image = R.drawable.diamond_axe, stack = 1),listOf(
Item("Wooden Stick", image = R.drawable.wooden_stick, stack = 5),
Item("Diamond", image = R.drawable.diamond, stack = 10),
), "Tools"),
)
var recipeListBlacksmithing : List<Recipe> = listOf(
Recipe(
Item("Bronze Ingot", image = R.drawable.bronze_ingot, stack = 1),listOf(
Item("Bronze Ore", image = R.drawable.bronze_ore, stack = 5)
), "Blacksmithing"),
Recipe(
Item("Iron Ingot", image = R.drawable.iron_ingot, stack = 1),listOf(
Item("Iron Ore", image = R.drawable.iron_ore, stack = 5)
), "Blacksmithing"),
)
fun isCraftable(recipe: Recipe, player: Player): Boolean{
for (ingredient in recipe.ingredients) {
if (!player.hasItem(ingredient)) {
return false
}
}
return true
}
}
}

@ -0,0 +1,50 @@
package com.example.shakecraft.view.adapter
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.example.shakecraft.R
import com.example.shakecraft.model.Recipe
class AdapterRecipe(private val recipelist: List<Recipe>) : RecyclerView.Adapter<AdapterRecipe.ViewHolder>() {
class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
val textView: TextView
var imageView: ImageView
init {
// Define click listener for the ViewHolder's View
textView = view.findViewById(R.id.item_name)
imageView = view.findViewById(R.id.item_image)
}
fun bind(recipe: Recipe) {
textView.text = recipe.item.name
imageView.setImageResource(recipe.item.image)
}
}
override fun getItemCount() = recipelist.size
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val view = LayoutInflater.from(parent.context)
.inflate(R.layout.list_item, parent, false)
return ViewHolder(view)
}
override fun onBindViewHolder(viewHolder: ViewHolder, position: Int) {
val recipe : Recipe = recipelist[position]
viewHolder.bind(recipe)
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/grey_500"/>
<corners
android:topLeftRadius="5dp"
android:topRightRadius="5dp"
android:bottomLeftRadius="5dp"
android:bottomRightRadius="5dp"/>
</shape>

@ -0,0 +1,4 @@
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/black_800"/>
<item android:drawable="@drawable/roundedreciplistcard"/>
</layer-list>

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/grey"/>
<corners
android:topLeftRadius="19dp"
android:topRightRadius="19dp"
android:bottomLeftRadius="19dp"
android:bottomRightRadius="19dp"/>
</shape>

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

@ -0,0 +1,155 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black_800"
android:scaleType="center"
tools:context=".CollectFragment">
<FrameLayout
android:id="@+id/frameLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingTop="50dp"
android:paddingBottom="20dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginBottom="20dp">
<TextView
android:id="@+id/backbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center_vertical"
android:focusable="true"
android:drawableStart="@drawable/back"
android:drawableTint="@color/blue"
android:text="Home"
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" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Ancient Forge"
android:textColor="@color/white"
android:textSize="16sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</FrameLayout>
<ScrollView
android:id="@+id/RecipeScroll"
android:layout_width="match_parent"
android:layout_height="635dp"
android:paddingHorizontal="10dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/frameLayout">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:background="@drawable/recipelistcard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginVertical="10dp"
android:paddingBottom="10dp">
<TextView
android:paddingTop="20dp"
android:paddingLeft="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="17dp"
android:textColor="@color/grey_400"
android:textStyle="bold"
android:text="Objects"/>
<androidx.recyclerview.widget.RecyclerView
android:overScrollMode="never"
android:id="@+id/RecyclerviewObjects"
android:layout_marginHorizontal="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:listitem="@layout/list_recipe"
tools:itemCount="3"/>
</LinearLayout>
<LinearLayout
android:background="@drawable/recipelistcard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginVertical="10dp"
android:paddingBottom="10dp">
<TextView
android:paddingTop="20dp"
android:paddingLeft="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="17dp"
android:textColor="@color/grey_400"
android:textStyle="bold"
android:text="Tools"/>
<androidx.recyclerview.widget.RecyclerView
android:overScrollMode="never"
android:id="@+id/RecyclerviewTools"
android:layout_marginHorizontal="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:listitem="@layout/list_recipe"
tools:itemCount="3"/>
</LinearLayout>
<LinearLayout
android:background="@drawable/recipelistcard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginVertical="10dp"
android:paddingBottom="10dp">
<TextView
android:paddingTop="20dp"
android:paddingLeft="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="17dp"
android:textColor="@color/grey_400"
android:textStyle="bold"
android:text="Blacksmithing"/>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/RecyclerviewBlacksmithing"
android:overScrollMode="never"
android:layout_marginHorizontal="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:listitem="@layout/list_recipe"
tools:itemCount="3"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>

@ -143,7 +143,7 @@
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/constraintLayout2"
android:id="@+id/buttonForge"
android:layout_width="match_parent"
android:layout_marginHorizontal="15dp"
android:layout_height="60dp"
@ -210,7 +210,7 @@
android:background="@drawable/rounded_border_button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/constraintLayout2">
app:layout_constraintTop_toBottomOf="@+id/buttonForge">
<LinearLayout

@ -0,0 +1,65 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<androidx.constraintlayout.widget.ConstraintLayout
android:focusable="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginVertical="8dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:contentDescription="image of item"
android:background="@drawable/item_recipe_background"
android:id="@+id/item_image"
android:layout_width="50dp"
android:layout_height="50dp"
app:srcCompat="@drawable/wooden_stick" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="@+id/item_name"
android:layout_marginLeft="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:textStyle="bold"
tools:text="Wooden Stick"/>
<View
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_above="@+id/bottomNav"
android:background="@color/grey_delimiter"></View>
</LinearLayout>

@ -53,5 +53,19 @@
android:id="@+id/action_homeFragment_to_bossFragment"
app:destination="@id/bossFragment"
app:enterAnim="@android:anim/fade_in" />
<action
android:id="@+id/action_homeFragment_to_forgeFragment"
app:destination="@id/forgeFragment" />
</fragment>
<fragment
android:id="@+id/forgeFragment"
android:name="com.example.shakecraft.ForgeFragment"
android:label="ForgeFragment" >
<action
android:id="@+id/action_forgeFragment_to_homeFragment"
app:destination="@id/homeFragment"
app:enterAnim="@android:anim/fade_in"
app:popUpTo="@id/homeFragment"
app:popUpToInclusive="true" />
</fragment>
</navigation>

@ -15,4 +15,6 @@
<color name="grey_300">#ADACB2</color>
<color name="red">#FF3D3D</color>
<color name="yellow">#FADB68</color>
<color name="grey_400">#999A9F</color>
<color name="grey_500">#3A393F</color>
</resources>
Loading…
Cancel
Save