package com.example.drievka

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.DisplayMetrics
import kotlinx.android.synthetic.main.hra1.*
import java.util.*
import kotlin.concurrent.schedule
import kotlin.math.roundToInt

class GameActivity1 : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.hra1)


        imageButtonBack.setOnClickListener {
            val intent = Intent(this, MainActivity::class.java)
            startActivity(intent)
        }

        val display = windowManager.defaultDisplay
        val metricsB = DisplayMetrics()
        display.getMetrics(metricsB)

        var width = metricsB.widthPixels
        var height = metricsB.heightPixels

        imageButtonOK.layoutParams.width = width / 15
        imageButtonOK.layoutParams.height = width / 15

        imageButtonRepeat.layoutParams.width = width / 15
        imageButtonRepeat.layoutParams.height = width / 15

        imageButtonBack.layoutParams.width = width / 15
        imageButtonBack.layoutParams.height = width / 15

        task.layoutParams.width = width / 15 *12
        task.layoutParams.height = (height * 0.15).roundToInt()


        imageView2.layoutParams.width = (width * 0.9).roundToInt()
        imageView2.layoutParams.height = (height * 0.75).roundToInt()

        imageButtonRepeat.setOnClickListener {
            imageView2.clearPlayground()
        }

        Timer("timer1").schedule(1000,1000){
            var update = false
            if(task.square != imageView2.square){
                task.square = imageView2.square
            }
            if(task.usedSticks != imageView2.sticksCounter){
                task.usedSticks = imageView2.sticksCounter
                update = true
            }
            if(task.createdShapes != imageView2.shapesCounter){
                task.createdShapes = imageView2.shapesCounter
                update = true
            }
            if(update){
                task.invalidate()
            }
        }.run()


    }



    override fun onPause() {
        super.onPause()
        imageView2.activityPaused()
        //Log.d("STICK", " pause w=" + otec.width + " h=" + otec.height)
    }


}