0

我开始在安卓(日本传统游戏)上制作一款名为 GO 的游戏。推荐人:GO

而且我想在每个玩家轮到一个条件时,所以当玩家轮到时,条件去查看石头的位置,如果放置的石头位置可以获得自由,然后运行条件,否则不是。这是编码:

public void checkCondition(int position, View v){

    final ImageButton[] arrPlayer1 = { //Board
            g1  ,g2,  g3,  g4,  g5,  g6,  g7,  g8,  g9, 
            g10, g11, g12, g13, g14, g15, g16, g17, g18, 
            g19, g20, g21, g22, g23, g24, g25, g26, g27, 
            g28, g29, g30, g31, g32, g33, g34, g35, g36, 
            g37, g38, g39, g40, g41, g42, g43, g44, g45, 
            g46, g47, g48, g49, g50, g51, g52, g53, g54, 
            g55, g56, g57, g58, g59, g60, g61, g62, g63, 
            g64, g65, g66, g67, g68, g69, g70, g71, g72, 
            g73, g74, g75, g76, g77, g78, g79, g80, g81};

    int posT = position - 9; //Top Position
    int posD = position + 9;  //Down Position
    int posL = position - 1; //Left Position
    int posR = position + 1; //Right Position

    ImageView BlackStone = (ImageView) findViewById(R.drawable.BlackStone);

    if(v == arrPlayer1[position] && arrPlayer1[posT] != null){
        if(arrPlayer1[posT] == BlackStone){
            if(v == arrPlayer1[position] && arrPlayer1[posD] != null){
                if(arrPlayer1[posD] == BlackStone){
                    if(v == arrPlayer1[position] && arrPlayer1[posR] != null){
                        if(arrPlayer1[posR] == BlackStone){
                            if(v == arrPlayer1[position] && arrPlayer1[posL] != null){
                                if(arrPlayer1[posL] == BlackStone){
                                    ChangeTurn(v);
                                }else{
                                    CheckLiberty(position, v);
                                }
                            }
                        }else{
                            CheckLiberty(position, v);
                        }
                    }
                }else{
                    CheckLiberty(position, v);
                }
            }
        }else{
            CheckLiberty(position, v);
        }
    }

} 

我的逻辑是,我在这个编码中创建了一个动态条件,所以无论玩家走到哪里,它都会看到石头的状况,例如:如果玩家在 G20 放置石头,那么逻辑将在 G11、G19、G21、G29 中看到或等相互连接的石头。

int posT = position - 9; //Top Position
int posD = position + 9;  //Down Position
int posL = position - 1; //Left Position
int posR = position + 1; //Right Position

但它仍然是错误的,并且 logcat 在方法(CheckCondition)处给了我错误数组越界异常。所以我该怎么做 ?任何帮助表示赞赏

4

1 回答 1

2

第一个变化:

ImageView BlackStone = (ImageView) findViewById(R.drawable.BlackStone);

ImageView BlackStone = (ImageView) findViewById(R.id.IdOfImageview);

您需要找到任何组件的视图,而Id不是background您正在使用的组件findViewById

于 2013-11-12T04:13:05.050 回答