java模拟Android Studio中的人工智能点击
我在安卓工作室做了一个tic-tac-toe游戏。我还制作了一个玩家可以玩的AI,但是AI不需要“点击”,因为它可以将特定行和列的值设置为其值(X或0)。有没有办法模拟人工智能的点击
<LinearLayout
安卓:layout_width="match_parent"
安卓:layout_height="0dp"
安卓:layout_weight="1">
<Button
安卓:id="@+id/button_00"
安卓:layout_width="0dp"
安卓:layout_height="match_parent"
安卓:layout_weight="1"
安卓:textSize="60sp"/>
<Button
安卓:id="@+id/button_01"
安卓:layout_width="0dp"
安卓:layout_height="match_parent"
安卓:layout_weight="1"
安卓:textSize="60sp"/>
<Button
安卓:id="@+id/button_02"
安卓:layout_width="0dp"
安卓:layout_height="match_parent"
安卓:layout_weight="1"
安卓:textSize="60sp"/>
</LinearLayout>
<LinearLayout
安卓:layout_width="match_parent"
安卓:layout_height="0dp"
安卓:layout_weight="1">
<Button
安卓:id="@+id/button_10"
安卓:layout_width="0dp"
安卓:layout_height="match_parent"
安卓:layout_weight="1"
安卓:textSize="60sp"/>
<Button
安卓:id="@+id/button_11"
安卓:layout_width="0dp"
安卓:layout_height="match_parent"
安卓:layout_weight="1"
安卓:textSize="60sp"/>
<Button
安卓:id="@+id/button_12"
安卓:layout_width="0dp"
安卓:layout_height="match_parent"
安卓:layout_weight="1"
安卓:textSize="60sp"/>
</LinearLayout>
<LinearLayout
安卓:layout_width="match_parent"
安卓:layout_height="0dp"
安卓:layout_weight="1">
<Button
安卓:id="@+id/button_20"
安卓:layout_width="0dp"
安卓:layout_height="match_parent"
安卓:layout_weight="1"
安卓:textSize="60sp"/>
<Button
安卓:id="@+id/button_21"
安卓:layout_width="0dp"
安卓:layout_height="match_parent"
安卓:layout_weight="1"
安卓:textSize="60sp"/>
<Button
安卓:id="@+id/button_22"
安卓:layout_width="0dp"
安卓:layout_height="match_parent"
安卓:layout_weight="1"
安卓:textSize="60sp"/>
</LinearLayout>
我的布局非常简单,在我的玩家对玩家模式下,点击看起来就像:
if(!((Button) v).getText().toString().equals("")){return;}
if(player1turn){ ((Button) v).setText("X");
}else{ ((Button) v).setText("O"); }
# 1 楼答案
你可以打电话给^{}