Skip to content

Commit

Permalink
1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
fym35 committed Mar 21, 2022
1 parent a95ad79 commit 09dd767
Show file tree
Hide file tree
Showing 14 changed files with 675 additions and 71 deletions.
43 changes: 26 additions & 17 deletions Cookie Clicker +/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.cookieclicker">
package="com.example.cookieclicker">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.CookieClicker">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".UpgradesActivity">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.CookieClicker">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".UpgradesActivity">

</activity>
</application>
</activity>
<activity android:name=".GadgetsActivity">

</activity>
<activity android:name=".BakeryActivity">

</activity>
<activity android:name=".SettingsActivity">

</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.example.cookieclicker

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.widget.Button
import android.widget.ImageButton
import android.widget.TextView
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity

class BakeryActivity : AppCompatActivity(){
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.bakery_activity)
setBakeryExitButton()
}

fun setBakeryExitButton(){
var exitButton = findViewById<ImageButton>(R.id.BakeryExitButton)
exitButton.setOnClickListener {
setResult(Activity.RESULT_OK)
finish()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,21 @@ class CookieData : Serializable {
var autoClickerPrice = 500
var workersPrice = 2000
var bakeriesPrice = 5000
var BombGadgetActive = false
var KeyGadgetActive = false
private var NewBakery = false
private val BakeryBonusCoef = 6

fun getKeyPrice(): Long {
var upgValue = 90000
return upgValue.toLong()
}

fun getBombPrice(): Long {
var upgValue = 70000
return upgValue.toLong()
}


override fun toString(): String {
var buffer = "{ cookiesCounter: $cookiesCounter, "
Expand All @@ -47,7 +59,6 @@ class CookieData : Serializable {

fun calculateClickValue() {
clickValue *= 2

}
fun updateAutoClicker() {
cookiesCounter -= autoClickerPrice
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package com.example.cookieclicker

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.widget.Button
import android.widget.ImageButton
import android.widget.TextView
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity

class GadgetsActivity : AppCompatActivity(){
var cookieData = CookieData()
lateinit var bombCostTextView: TextView
lateinit var clickerKeyCostTextView: TextView

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.gadgets_activity)
setGadgetsExitButton()
setBuyBombButton()
refreshTextViews()
setBuyButtonClickerKey()
bombCostTextView = findViewById(R.id.bombprice)
clickerKeyCostTextView = findViewById(R.id.clickerkeyprice)
}

fun refreshTextViews(){
if(cookieData.BombGadgetActive)
{
bombCostTextView.text = "Already purchased"
}
if(cookieData.KeyGadgetActive)
{
clickerKeyCostTextView.text = "Already purchased"
}
}
fun setGadgetsExitButton(){
var exitButton = findViewById<ImageButton>(R.id.GadgetsExitButton)
exitButton.setOnClickListener {
setResult(Activity.RESULT_OK)
finish()
}
}

fun setBuyBombButton(){
var button = findViewById<Button>(R.id.BombButton)
button.setOnClickListener {
if(cookieData.BombGadgetActive == false){
if(cookieData.cookiesCounter >= 70000) {
cookieData.BombGadgetActive = true
cookieData.cookiesCounter -= 70000
refreshTextViews()
}else{
Toast.makeText(applicationContext, "You cannot buy this gadget", Toast.LENGTH_LONG).show()
}
}else{
Toast.makeText(applicationContext, "You already own this gadget", Toast.LENGTH_LONG).show()
}
}
}

fun setBuyButtonClickerKey(){
var button = findViewById<Button>(R.id.KeyGadgetBuy)
button.setOnClickListener {
if(cookieData.KeyGadgetActive == false) {
if (cookieData.cookiesCounter >= 90000) {
cookieData.BombGadgetActive = true
cookieData.cookiesCounter -= 90000
refreshTextViews()
}else{
Toast.makeText(applicationContext, "You cannot buy this gadget", Toast.LENGTH_LONG).show()
}
}else{
Toast.makeText(applicationContext, "You already own this gadget", Toast.LENGTH_LONG).show()
}
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.os.Handler
import android.widget.Button
import android.widget.ImageButton
import android.widget.RelativeLayout
import android.widget.TextView
import android.view.View
import android.widget.*
import androidx.appcompat.app.AppCompatActivity
import androidx.constraintlayout.widget.ConstraintLayout

Expand All @@ -17,15 +15,55 @@ class MainActivity : AppCompatActivity() {
val upgradeRequestCode = 10
val handler = Handler()
lateinit var timer: Runnable
var enableGadgets = true
val secondInMillis = 1000L
var gTimeout = 0
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
setupClickButton()
setupUpgradeButton()
setupGadgetsButton()
setupBakeries()
initTimer()
setupBombGadget()
setupKeyGadget()
setupSettingsButton()
}

fun setupKeyGadget() {
val button = findViewById<Button>(R.id.BombGadget)
button.setOnClickListener {
if(cookieData.KeyGadgetActive && enableGadgets){
var kgrnd = (0..5).random()
cookieData.cookiesPerSecond += kgrnd
var kgrnd2 = (0..10).random()
cookieData.clickUpgradeLevel += kgrnd2
Toast.makeText(applicationContext, "Upgraded by ${kgrnd}\n autoclick and ${kgrnd2}\n click upgrade", Toast.LENGTH_LONG).show()
}else if(cookieData.KeyGadgetActive && enableGadgets == false){
Toast.makeText(applicationContext, "This gadget is on timeout!", Toast.LENGTH_LONG).show()
}else{

}
}
}

fun setupBombGadget() {
val button = findViewById<Button>(R.id.BombGadget)
button.setOnClickListener {
if(cookieData.BombGadgetActive && enableGadgets){
var rnd = (80..6000).random()
cookieData.cookiesCounter += rnd
enableGadgets = false
}else if(cookieData.BombGadgetActive){
Toast.makeText(applicationContext, "This gadget is on timeout!", Toast.LENGTH_LONG).show()
}else{

}
}
}


fun setupClickButton() {
val button = findViewById<ImageButton>(R.id.cookieButton)
button.setOnClickListener {
Expand All @@ -43,6 +81,23 @@ class MainActivity : AppCompatActivity() {
}
}

fun setupGadgetsButton() {
val button = findViewById<Button>(R.id.upgradeButton3)
button.setOnClickListener {
val intent = Intent(this, GadgetsActivity::class.java)
startActivity(intent)
}
}

fun setupBakeries(){
val button = findViewById<Button>(R.id.upgradeButton4)
button.setOnClickListener {
val intent = Intent(this, BakeryActivity::class.java)
startActivity(intent)
}
}


override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == upgradeRequestCode && resultCode == Activity.RESULT_OK) {
Expand All @@ -51,11 +106,39 @@ class MainActivity : AppCompatActivity() {
var button = findViewById<ImageButton>(R.id.cookieButton)
var background = findViewById<ConstraintLayout>(R.id.background)
cookieData.startBakeryBonus(handler , button, background)
refreshGadgets()
}
}



fun setupSettingsButton(){
var button = findViewById<Button>(R.id.settingsButton)
button.setOnClickListener{
val intent = Intent(this, SettingsActivity::class.java)
startActivity(intent)
}
}

fun initTimer() {
timer = Runnable {
gTimeout += 1
if(gTimeout > 80)
{
enableGadgets = true
gTimeout = 0
}
if(cookieData.cookiesCounter > 8000)
{
var rnds = (0..52).random()
if(rnds == 30 || rnds == 31 || rnds == 32 || rnds == 33 || rnds == 34 || rnds == 35 || rnds == 36 || rnds == 37 || rnds == 38 || rnds == 39 || rnds == 40)
{
refreshCookieView()
var button = findViewById<ImageButton>(R.id.cookieButton)
var background = findViewById<ConstraintLayout>(R.id.background)
cookieData.startBakeryBonus(handler , button, background)
}
}
cookieData.cookiesCounter += cookieData.cookiesPerSecond
refreshCookieView()
handler.postDelayed(timer, secondInMillis)
Expand All @@ -64,9 +147,32 @@ class MainActivity : AppCompatActivity() {
}


fun refreshCookieView() {
val cookiesTextView: TextView = findViewById(R.id.cookieTextArea)
cookiesTextView.text = "🍪Cookies : ${cookieData.cookiesCounter}"
fun refreshCookieView() {
val cookiesTextView: TextView = findViewById(R.id.cookieTextArea)
cookiesTextView.text = "🍪Cookies : ${cookieData.cookiesCounter}"
}

fun refreshGadgets() {
if(cookieData.BombGadgetActive)
{
val button = findViewById<Button>(R.id.BombGadget)
button.visibility = View.VISIBLE
}else{
val button = findViewById<Button>(R.id.BombGadget)
button.visibility = View.INVISIBLE
}
if(cookieData.KeyGadgetActive)
{
val button = findViewById<Button>(R.id.keyGadget)
button.visibility = View.VISIBLE
}else{
val button = findViewById<Button>(R.id.keyGadget)
button.visibility = View.INVISIBLE
}


}

}


Loading

0 comments on commit 09dd767

Please sign in to comment.