Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import android.content.SharedPreferences
- import android.graphics.Color
- import android.os.Bundle
- import android.widget.Toast
- import androidx.activity.enableEdgeToEdge
- import androidx.appcompat.app.AppCompatActivity
- import androidx.core.view.ViewCompat
- import androidx.core.view.WindowInsetsCompat
- import kotlin.Int
- import com.zeider.clicker.databinding.ActivityMainBinding
- class MainActivity : AppCompatActivity() {
- private val binding: ActivityMainBinding by lazy {
- ActivityMainBinding.inflate(layoutInflater)
- }
- private var points: Int = 0
- private var boost: Int = 1
- private lateinit var sharedPreferences: SharedPreferences
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- enableEdgeToEdge()
- setContentView(binding.root)
- sharedPreferences = getPreferences(MODE_PRIVATE)
- open()
- ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
- val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
- v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
- insets
- }
- binding.clickButton.setOnClickListener {
- clicko()
- }
- binding.buyBoostButton.setOnClickListener {
- buy()
- }
- binding.clearButton.setOnClickListener {
- clear()
- }
- }
- private fun open() {
- points = sharedPreferences.getInt("value", points)
- boost = sharedPreferences.getInt("valu", boost)
- binding.buyBoostButton.setBackgroundColor(Color.parseColor(
- sharedPreferences.getString("boostColor", "#FFE96B")
- ))
- binding.buyBoostButton.isEnabled = sharedPreferences.getBoolean("boostClickable", true)
- when (points) {
- in 0..9 -> {
- binding.pointsTv.text = points.toString()
- binding.clickButton.text = "\uD83D\uDE42"
- sharedPreferences.edit().putInt("value", points).apply()
- }
- in 10..49 -> {
- binding.pointsTv.text = points.toString()
- binding.pointsTv.setTextColor(Color.parseColor("#00ff0c"))
- binding.clickButton.text = "\uD83E\uDD72"
- sharedPreferences.edit().putInt("value", points).apply()
- }
- in 50..99 -> {
- binding.pointsTv.text = points.toString()
- binding.pointsTv.setTextColor(Color.parseColor("#00bdff"))
- binding.clickButton.text = "\uD83E\uDD79"
- sharedPreferences.edit().putInt("value", points).apply()
- }
- in 100..499 -> {
- binding.pointsTv.text = points.toString()
- binding.pointsTv.setTextColor(Color.parseColor("#c500ff"))
- binding.clickButton.text = "\uD83D\uDE2D"
- sharedPreferences.edit().putInt("value", points).apply()
- }
- else -> {
- binding.pointsTv.text = points.toString()
- binding.pointsTv.setTextColor(Color.parseColor("#ff000f"))
- binding.clickButton.text = "\uD83D\uDC80"
- sharedPreferences.edit().putInt("value", points).apply()
- }
- }
- }
- private fun clear() {
- points = 0
- boost = 1
- binding.pointsTv.setTextColor(Color.parseColor("#4D4D4D"))
- binding.clickButton.text = "\uD83D\uDE42"
- binding.pointsTv.text = points.toString()
- binding.buyBoostButton.isEnabled = true
- binding.buyBoostButton.setBackgroundColor(Color.parseColor("#FFE96B"))
- sharedPreferences.edit().putString("boostColor", "#FFE96B").apply()
- sharedPreferences.edit().putInt("value", points).apply()
- sharedPreferences.edit().putInt("valu", boost).apply()
- sharedPreferences.edit().putBoolean("boostClickable", true).apply()
- }
- private fun clicko() {
- when (points) {
- in 0..9 -> {
- points += boost
- binding.pointsTv.text = points.toString()
- binding.clickButton.text = "\uD83D\uDE42"
- sharedPreferences.edit().putInt("value", points).apply()
- }
- in 10..49 -> {
- points += boost
- binding.pointsTv.text = points.toString()
- binding.pointsTv.setTextColor(Color.parseColor("#00ff0c"))
- binding.clickButton.text = "\uD83E\uDD72"
- sharedPreferences.edit().putInt("value", points).apply()
- }
- in 50..99 -> {
- points += boost
- binding.pointsTv.text = points.toString()
- binding.pointsTv.setTextColor(Color.parseColor("#00bdff"))
- binding.clickButton.text = "\uD83E\uDD79"
- sharedPreferences.edit().putInt("value", points).apply()
- }
- in 100..499 -> {
- points += boost
- binding.pointsTv.text = points.toString()
- binding.pointsTv.setTextColor(Color.parseColor("#c500ff"))
- binding.clickButton.text = "\uD83D\uDE2D"
- sharedPreferences.edit().putInt("value", points).apply()
- }
- else -> {
- points += boost
- binding.pointsTv.text = points.toString()
- binding.pointsTv.setTextColor(Color.parseColor("#ff000f"))
- binding.clickButton.text = "\uD83D\uDC80"
- sharedPreferences.edit().putInt("value", points).apply()
- }
- }
- }
- private fun buy() {
- if (points <= 10000) {
- Toast.makeText(this,
- "Недостаточно денег!",
- Toast.LENGTH_SHORT)
- .show()
- } else {
- boost = 2
- binding.buyBoostButton.setBackgroundColor(Color.parseColor("#BDB76B"))
- binding.buyBoostButton.isEnabled = false
- Toast.makeText(this,
- "2х куплен!",
- Toast.LENGTH_SHORT)
- .show()
- sharedPreferences.edit().putInt("valu", boost).apply()
- sharedPreferences.edit().putString("boostColor", "#BDB76B").apply()
- sharedPreferences.edit().putBoolean("boostClickable", false).apply()
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement