Guest User

Untitled

a guest
Feb 24th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. override fun onClick(v: View) {
  2. if(curState == state.finish)
  3. return
  4.  
  5. when(v.id){
  6. R.id.btn_rock->{
  7. img_mc.setImageResource(R.drawable.ic_rock)
  8. cekAnswer(type.rock)
  9. }
  10. R.id.btn_paper->{
  11. img_mc.setImageResource(R.drawable.ic_paper)
  12. cekAnswer(type.paper)
  13. }
  14. R.id.btn_scissor->{
  15. img_mc.setImageResource(R.drawable.ic_scissor)
  16. cekAnswer(type.scissor)
  17. }
  18. }
  19. ViewCompat.animate(img_mc).translationY(-600f).duration = 100
  20.  
  21. }
  22.  
  23.  
  24. fun cekAnswer(tp: type){
  25. var info:String = ""
  26. if(curType == type.rock){
  27. if(tp == type.rock){
  28. info = "=" //equal
  29. }else if(tp == type.paper){
  30. info = ":)" //win
  31. score+=10
  32. }else{
  33. info = ":(" //lose
  34. }
  35. }else if(curType == type.paper){
  36. if(tp == type.rock){
  37. info = ":)" // lose
  38. }else if(tp == type.paper){
  39. info = "=" //equal
  40. }else{
  41. info = ":(" //win
  42. score+=10
  43. }
  44. }else{
  45. if(tp == type.rock){
  46. info = ":(" // win
  47. score+=10
  48. }else if(tp == type.paper){
  49. info = ":)" // lose
  50. }else{
  51. info = "=" // equal
  52. }
  53. }
  54.  
  55. tv_score.text = "Score : $score"
  56. tv_info.text = "$info"
  57.  
  58.  
  59. tv_info.postDelayed({
  60. tv_info.text = ""
  61. ViewCompat.animate(img_enemy).translationY(-400f).duration = 100
  62. ViewCompat.animate(img_mc).translationY(600f).duration = 100
  63. tv_info.postDelayed({
  64. randomEnemy()
  65. }, 500)
  66.  
  67. }, 500)
  68. }
Add Comment
Please, Sign In to add comment