Skip to content

Instantly share code, notes, and snippets.

@ariefannur
Created February 13, 2018 08:49
Show Gist options
  • Save ariefannur/5349aa2ad961f4578ab7c923de00516e to your computer and use it in GitHub Desktop.
Save ariefannur/5349aa2ad961f4578ab7c923de00516e to your computer and use it in GitHub Desktop.
Rock Paper Scissor Logic
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)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment