0

So I am working on a game of Chomp. Where you have a grid of "cookies" and a "poison cookie" in the bottom left corner. When a player selects a cookie, all the cookies up and to the right of that cookie are eaten.

Right now, my program selects all the cookies up and to the left of the cookie selected. Below is the updateBoard method that gets passed in the row and column from the mouse click and changes the type of each "cookie". My question is how to select the cookies to the right instead of the left?

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!");
    }
}
Greg Taylor
  • 21
  • 1
  • 7

1 Answers1

0

So you have a 2D grid. What you are doing here goes through the top left quadrant of the data intersected by (Row,Column)

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

The bottom left quadrant would be

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

The bottom right quadrant would be

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

And the top right quadrant would be

for(int i = 0; i <= Row; i++){                    
    for(int j = Column; j < gb1.arrayName1[Row].length; j++){
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245