Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- override fun onClick(v: View) {
- if(curState == state.finish)
- return
- when(v.id){
- R.id.btn_rock->{
- img_mc.setImageResource(R.drawable.ic_rock)
- cekAnswer(type.rock)
- }
- R.id.btn_paper->{
- img_mc.setImageResource(R.drawable.ic_paper)
- cekAnswer(type.paper)
- }
- R.id.btn_scissor->{
- img_mc.setImageResource(R.drawable.ic_scissor)
- cekAnswer(type.scissor)
- }
- }
- ViewCompat.animate(img_mc).translationY(-600f).duration = 100
- }
- fun cekAnswer(tp: type){
- var info:String = ""
- if(curType == type.rock){
- if(tp == type.rock){
- info = "=" //equal
- }else if(tp == type.paper){
- info = ":)" //win
- score+=10
- }else{
- info = ":(" //lose
- }
- }else if(curType == type.paper){
- if(tp == type.rock){
- info = ":)" // lose
- }else if(tp == type.paper){
- info = "=" //equal
- }else{
- info = ":(" //win
- score+=10
- }
- }else{
- if(tp == type.rock){
- info = ":(" // win
- score+=10
- }else if(tp == type.paper){
- info = ":)" // lose
- }else{
- info = "=" // equal
- }
- }
- tv_score.text = "Score : $score"
- tv_info.text = "$info"
- tv_info.postDelayed({
- tv_info.text = ""
- ViewCompat.animate(img_enemy).translationY(-400f).duration = 100
- ViewCompat.animate(img_mc).translationY(600f).duration = 100
- tv_info.postDelayed({
- randomEnemy()
- }, 500)
- }, 500)
- }
Add Comment
Please, Sign In to add comment