0

だから私はチョンプのゲームに取り組んでいます。左下隅に「クッキー」と「毒クッキー」のグリッドがある場所。プレイヤーがクッキーを選択すると、そのクッキーの右上にあるすべてのクッキーが食べられます。

現在、私のプログラムは、選択した Cookie の上と左側にあるすべての Cookie を選択します。以下は、マウス クリックから行と列に渡され、各「Cookie」のタイプを変更する updateBoard メソッドです。私の質問は、クッキーを左側ではなく右側に選択する方法ですか?

static void updateBoard(int Row, int Column){
    if(gb1.arrayName1[Row][Column].getType() == 1){
        gb1.arrayName1[Row][Column].setType(currentPlayer);

        if(currentPlayer == Player1){   
            for(int i = 0; i <=  Row; i++){                    
                for(int j = 0; j <= Column; j++){    
                    if(gb1.arrayName1[i][j].getType() != Player2){
                       gb1.arrayName1[i][j].setType(Player1);  
                    }
                }
            }            
            turn.setText("Player2's turn");
            currentPlayer = Player2;
        }else if (currentPlayer == Player2){
            for(int i= 0; i <= Row; i++){                    
                for(int j = 0; j <= Column; j++){              
                    if(gb1.arrayName1[i][j].getType() != Player1){
                       gb1.arrayName1[i][j].setType(Player2);  
                    }                  
                } 
             } 
    turn.setText("Player1's turn");
    currentPlayer=Player1;
        }         
}else if(gb1.arrayName1[Row][Column].getType() == 4){
        turn.setText("Poison cookie eaten, Game Over!");
    }
}
4

1 に答える 1

0

これで 2D グリッドができました。ここで行っていることは、交差するデータの左上の象限を通過します。(Row,Column)

for(int i= 0; i <= Row; i++){                    
    for(int j = 0; j <= Column; j++){

左下の象限は

for(int i = Row; i < gb1.arrayName1.length; i++){                    
    for(int j = 0; j <= Column; j++){

右下の象限は

for(int i = Row; i < gb1.arrayName1.length; i++){                    
    for(int j = Column; j < gb1.arrayName1[Row].length; j++){

そして、右上の象限は

for(int i = 0; i <= Row; i++){                    
    for(int j = Column; j < gb1.arrayName1[Row].length; j++){
于 2015-10-22T22:38:51.663 に答える