我有2个玩家的应用程序游戏。我想将游戏设置为在设备播放时与设备一起播放,我先走了,单击后设备未单击。然后另一位玩家选择了一个随机按钮,我想当我玩游戏时,他们在我玩之后不要等待点击然后设备点击
fun action(optionNumber: Int, btnselected: Button) {
if (playingplayer == PLAYINGPLAYER.FIRST_PLAYER) {
btnselected.setBackgroundResource(R.drawable.button_game_green)
buttonClickes1Player.add(optionNumber)
btnselected.isEnabled = false
playingplayer = PLAYINGPLAYER.SECOND_PLAYER
} else if (playingplayer == PLAYINGPLAYER.SECOND_PLAYER) {
var noSelectedButton: ArrayList<Int> = ArrayList()
for (buttonNumber in 1..10){
if (!(buttonClickes1Player.contains(buttonNumber))){
noSelectedButton.add(buttonNumber)
}
}
try {
var randomNumber = (Math.random() * noSelectedButton.size).toInt()
var buttonNumber = noSelectedButton[randomNumber]
when(buttonNumber){
1 -> btnselected = btn1
2 -> btnselected = btn2
3 -> btnselected = btn3
4 -> btnselected = btn4
5 -> btnselected = btn5
6 -> btnselected = btn6
7 -> btnselected = btn7
8 -> btnselected = btn8
9 -> btnselected = btn9
10 -> btnselected = btn10
}
btnselected.setBackgroundResource(R.drawable.button_game_red)
buttonClickes1Player.add(optionNumber)
btnselected.isEnabled = false
playingplayer = PLAYINGPLAYER.FIRST_PLAYER
}catch (e: Exception){
e.printStackTrace()
}
}
imagebtnState()
}